Advertisement
jimlkosmo

VGA Signaling Correct

Feb 24th, 2016
3,144
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.  
  14. RESET:
  15. sbi ddrb,4 ; HORIZONTAL SYNC PULSE  pin set as output
  16. sbi ddrb,3 ;red pin set as output
  17. sbi ddrb,2 ;green  pin set as output
  18. sbi ddrb,0 ;blue  pin set as output
  19. sbi ddrb,1 ; VERTICAL SYNC PULSE  pin set as output
  20. ldi r16,(1<<PORTB4); H_SYNC PIN HIGH
  21. out PORTB,r16
  22. ;sbi PINB,1
  23. ;in r16,PORTB; V_SYNC PIN LOW
  24. ;sbr r16,(0<<PORTB1)
  25. ;out PORTB,r16
  26.  
  27. ;stack_pointer
  28. ldi r16,ramend
  29. out spl,r16
  30.  
  31. ;setup interrupts
  32. clr r16
  33. ldi r16,(1<<COM1B0); Toggle in OC1B when Comp Match on OCR1B
  34. out TCCR1A,r16
  35. ldi r16,(1<<FOC1B)
  36. out TCCR1C,r16
  37. ldi r16,(1<<CS10 | 1<<WGM12) ;CTC on OCR1A Comp Match and set CLKin
  38. out TCCR1B,r16
  39. ldi r16,(1<<OCIE1A | 1<<OCIE1B) ;TC1 Output Comp Match Interrupt Enabled on A and B channel
  40. out timsk,r16
  41. ldi r16,high(635); Load Max for TC1
  42. out ocr1ah,r16
  43. ldi r16,low(635)
  44. out ocr1al,r16
  45. ldi r16,0
  46. out tcnt1h,r16; clear tc1
  47. out tcnt1l,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 r29
  62. clr r16
  63. sei; interrupts globally enabled
  64. main:
  65.  
  66. cp r28,r19 ;[1]
  67. cpc r29,r20 ;[1]
  68. brlo no_vid ;[1/2] Are we in vertical visible area?
  69. in r26,tcnt1l;
  70. in r27,tcnt1h
  71. cp r26,r21 ;[1]
  72. cpc r27,r22 ;[1]
  73. brlo no_vid ;[1/2] Are we in horizontal visible area?
  74. ;in r24,PORTB; white space
  75. ;sbr r24,(1<<PORTB0)|(1<<PORTB2)|(1<<PORTB3)
  76. ;out PORTB,r24
  77. sbi PORTB,0
  78. sbi PORTB,2
  79. sbi PORTB,3
  80. rjmp main
  81.  
  82. no_vid:
  83. ;in r24,PORTB; black space
  84. ;sbr r24,(0<<PORTB0)|(0<<PORTB2)|(0<<PORTB3)
  85. ;out PORTB,r24
  86. cbi PORTB,0
  87. cbi PORTB,2
  88. cbi PORTB,3
  89. rjmp main
  90.  
  91.  
  92. TIM1_COMPA:
  93. ldi r16,low(12); Load first toggle value for H_SYNC (13 clock pulses) [1]
  94. ldi r17,high(12);
  95. out ocr1bh,r17;[2]
  96. out ocr1bl,r16
  97. in r16,sreg ; SAVE STATUS REGISTER [1]
  98. push r16;[2]
  99. adiw r29:r28,1 ;[2] V_SYNC counter++
  100. ldi r17,0 ;[1]
  101. cp r18,r28 ;[1]
  102. cpc r17,r29 ;[1]
  103. breq vsync_toggle ;[1/2] If we got 10 or 12 lines
  104. ldi r16,low(525) ;[1]
  105. ldi r17,high(525) ;[1]
  106. cp r16,r28 ;[1]
  107. cpc r17,r29 ;[1]
  108. breq cls_vsync ;[1/2] If we got 525 lines
  109. cont:
  110. pop r16 ;[2] RESTORE sreg
  111. out sreg,r16 ;1
  112. reti ;[4] return operation to software
  113.  
  114. TIM1_COMPB:
  115. in r16,sreg ; SAVE STATUS REGISTER [1]
  116. push r16;[2]
  117. ldi r16,low(87); Load second toggle value for H_SYNC (13+76 clock pulses)
  118. out ocr1bl,r16
  119. pop r16 ;[2] RESTORE sreg
  120. out sreg,r16 ;1
  121. reti ;[4] return operation to software
  122.  
  123. vsync_toggle:
  124. in r16,PORTB; white space
  125. ldi r17,(1<<PORTB1)
  126. eor r16,r17
  127. out PORTB,r16
  128. ;sbi PINB,1;toggle v_sync
  129. ldi r18,12 ;set r18 with 12
  130. rjmp cont
  131.  
  132. cls_vsync:
  133. ldi r18,10 ;set r18 with 10
  134. ldi r28,0; reset v_sync counter
  135. ldi r29,0
  136. rjmp cont
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement