Advertisement
jimlkosmo

GOLD vga test

Feb 26th, 2016
3,110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;
  2. ; vga_test.asm
  3. ;
  4. ; Created: 2/20/2016 6:44:02 PM
  5. ; Author : jimlkosmo
  6. ;
  7. .org 0
  8. rjmp RESET ;reset
  9. .org OC1Aaddr
  10. rjmp TIM1_COMPA ;isr for tc1 Compare Match A
  11. .org OC1Baddr
  12. rjmp TIM1_COMPB ;isr for tc1 Compare Match B
  13. .org OC0Aaddr
  14. rjmp TIM0_COMPA ;isr for tc0 Compare Match A
  15.  
  16. RESET:
  17. sbi ddrb,4 ; HORIZONTAL SYNC PULSE  pin set as output [2]
  18. sbi ddrb,3 ;red pin set as output
  19. sbi ddrb,2 ;green  pin set as output
  20. sbi ddrb,0 ;blue  pin set as output
  21. sbi ddrb,1 ; VERTICAL SYNC PULSE  pin set as output
  22. ldi r16,(1<<PORTB4); H_SYNC PIN HIGH
  23. out PORTB,r16; [1]
  24.  
  25. ;stack_pointer
  26. ldi r16,ramend; [1]
  27. out spl,r16; [1]
  28.  
  29. ;setup interrupts
  30. clr r16
  31. ldi r16,(1<<COM1B0); Toggle in OC1B when Comp Match on OCR1B
  32. out TCCR1A,r16
  33. ldi r16,(1<<FOC1B)
  34. out TCCR1C,r16
  35. ldi r16,(1<<CS10 | 1<<WGM12) ;CTC on OCR1A Comp Match and set CLKin
  36. out TCCR1B,r16
  37. ldi r16,(1<<OCIE1A | 1<<OCIE1B | 1<<OCIE0A) ;TC1 Output Comp Match Interrupt Enabled on A and B channel and TC0
  38. out timsk,r16
  39. ldi r16,high(635); Load Max for TC1
  40. out ocr1ah,r16
  41. ldi r16,low(635)
  42. out ocr1al,r16
  43. ldi r16,0
  44. out tcnt1h,r16; clear tc1
  45. out tcnt1l,r16
  46. ;ldi r16,10; load Compare Match interrupt value for TC0
  47. ;out OCR0A,r16
  48. ldi r16,high(12); Load first toggle value for H_SYNC (13 clock pulses)
  49. out ocr1bh,r16
  50. ldi r16,low(12)
  51. out ocr1bl,r16
  52. ldi r16,0
  53. out tcnt1h,r16; clear tc1
  54. out tcnt1l,r16
  55. ldi r18,10; Load r18 with the first value of vsync toggle
  56. ldi r19,44 ;[1] load r19 with the value of the first visible line
  57. ldi r20,0 ;[1]
  58. ldi r21,low(126); load r21,r22 with the value of the first visible pixel
  59. ldi r22,high(126)
  60. clr r28
  61. clr r16
  62. clr r29
  63. ldi r16,(1<<CS01); Start tc0 with prescaler clk/8
  64. out TCCR0B,r16
  65. ldi r16,1
  66. out GTCCR,r16
  67. sei; interrupts globally enabled
  68.  
  69.  
  70.  
  71. main:
  72. nop
  73. nop
  74. rjmp main
  75.  
  76.  
  77. TIM1_COMPA:
  78. ldi r16,low(12); Load first toggle value for H_SYNC (13 clock pulses) [1]
  79. out ocr1bl,r16;[1]
  80. ldi r16,12; load Compare Match interrupt value for TC0
  81. out OCR0A,r16;[1]
  82. in r16,sreg ; SAVE STATUS REGISTER [1]
  83. push r16;[2]
  84. ldi r16,3
  85. out TCNT0,r16
  86. ldi r16,1
  87. out GTCCR,r16
  88. adiw r29:r28,1 ;[2] V_SYNC counter++
  89. ldi r17,0 ;[1]
  90. cp r18,r28 ;[1]
  91. cpc r17,r29 ;[1]
  92. breq vsync_toggle ;[1/2] If we got 10 or 12 lines
  93. ldi r16,low(524) ;[1] [6]
  94. ldi r17,high(524) ;[1]
  95. cp r16,r28 ;[1]
  96. cpc r17,r29 ;[1]
  97. breq cls_vsync ;[1/2] If we got 525 lines
  98. cont:
  99. pop r16 ;[2] RESTORE sreg
  100. out sreg,r16 ;10
  101. reti ;[4] return operation to software
  102.  
  103. TIM1_COMPB:
  104. ;in r16,sreg ; SAVE STATUS REGISTER [1]
  105. ;push r16;[2]
  106. ldi r16,low(87); Load second toggle value for H_SYNC (13+76 clock pulses)
  107. out ocr1bl,r16
  108. ;pop r16 ;[2] RESTORE sreg
  109. ;out sreg,r16 ;1
  110. reti ;[4] return operation to software
  111.  
  112. TIM0_COMPA:
  113. in r16,sreg ; SAVE STATUS REGISTER [1]
  114. push r16;[2]
  115. ldi r16,21 ; reset TCNT0 ????????????
  116. out TCNT0,r16
  117. ldi r16,1
  118. out GTCCR,r16
  119. ldi r16,44; Are we in vertical area?
  120. ldi r17,0 ;[1]
  121. cp r28,r16 ;[1]
  122. cpc r29,r17 ;[1]
  123. brlo no_colour
  124. ldi r16,81; load Compare Match interrupt value for TC0
  125. out OCR0A,r16
  126. in r16,PORTB; [1]
  127. ldi r17,(1<<PORTB0 | 1<<PORTB2 | 1<<PORTB3);[1] we got colour
  128. eor r16,r17;[1]
  129. out PORTB,r16;[1]
  130. cont2:;[4]
  131. pop r16 ;[2] RESTORE sreg
  132. out sreg,r16 ;[1]
  133. reti;
  134.  
  135. no_colour:;[7]
  136. in r16,PORTB; [1]
  137. cbr r16,(1<<PORTB0 | 1<<PORTB2 | 1<<PORTB3);[1] clear the colour output
  138. out PORTB,r16;[1]
  139. rjmp cont2;[2]
  140.  
  141.  
  142.  
  143. vsync_toggle:;[7]
  144. ;in r16,PORTB; white space
  145. ;ldi r17,(1<<PORTB1)
  146. ;eor r16,r17
  147. ;out PORTB,r16
  148. sbi PINB,1;toggle v_sync
  149. ldi r18,12 ;set r18 with 12
  150. rjmp cont
  151.  
  152. cls_vsync:
  153. ldi r18,10 ;set r18 with 10
  154. ldi r28,0; reset v_sync counter
  155. ldi r29,0
  156. rjmp cont
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement