Advertisement
jimlkosmo

Untitled

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