Advertisement
Guest User

Untitled

a guest
Apr 12th, 2025
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. ; set VIA address
  2. PORTB = $6000
  3. PORTA = $6001
  4. DDRB = $6002
  5. DDRA = $6003
  6. T1CL = $6004
  7. T1CH = $6005
  8. ACR = $600B
  9. IFR = $600D
  10. IER = $600E
  11.  
  12. ; define variables
  13. MODE = $0300
  14. HOLD = $0301
  15. COUNT = $0302
  16.  
  17. E = %01000000
  18. RW = %00100000
  19. RS = %00010000
  20.  
  21. .org $8000
  22.  
  23. reset:
  24. sei ;disable interrupts
  25.  
  26. ldx #$FF
  27. txs ;inlisize stack pointer
  28.  
  29. lda #$FF
  30. sta DDRB ; set all port b pins to output
  31. sta DDRA ; set all port a pins to output
  32.  
  33. lda #%01000000
  34. sta ACR ; enable timer 1 continuous mode
  35.  
  36. lda #%11000000
  37. sta IER ; enable timer 1 interrupts
  38.  
  39. stz HOLD ; set hold to 0
  40. stz MODE ; set mode to 0
  41.  
  42. lda #$01
  43. sta COUNT ; set count to 1
  44. sta PORTA ; set port a to output 1
  45.  
  46. jsr lcd_init
  47. lda #%00101000 ; Set 4-bit mode; 2-line display; 5x8 font
  48. jsr lcd_instruction
  49. lda #%00001110 ; Display on; cursor on; blink off
  50. jsr lcd_instruction
  51. lda #%00000110 ; Increment and shift cursor; don't shift display
  52. jsr lcd_instruction
  53. lda #$00000001 ; Clear display
  54. jsr lcd_instruction
  55.  
  56. cli ; enable interrupts
  57.  
  58. lda #$FF
  59. sta T1CL ; load timer 1 counter low with 255
  60. sta T1CH ; load timer 1 counter high with 255, and start the count
  61.  
  62. loop:
  63. ; do nothing loop
  64. jmp loop
  65.  
  66. lcd_wait:
  67. pha
  68. lda #%11110000 ; LCD data is input
  69. sta DDRB
  70. lcdbusy:
  71. lda #RW
  72. sta PORTB
  73. lda #(RW | E)
  74. sta PORTB
  75. lda PORTB ; Read high nibble
  76. pha ; and put on stack since it has the busy flag
  77. lda #RW
  78. sta PORTB
  79. lda #(RW | E)
  80. sta PORTB
  81. lda PORTB ; Read low nibble
  82. pla ; Get high nibble off stack
  83. and #%00001000
  84. bne lcdbusy
  85.  
  86. lda #RW
  87. sta PORTB
  88. lda #%11111111 ; LCD data is output
  89. sta DDRB
  90. pla
  91. rts
  92.  
  93. lcd_init:
  94. lda #%00000010 ; Set 4-bit mode
  95. sta PORTB
  96. ora #E
  97. sta PORTB
  98. and #%00001111
  99. sta PORTB
  100. rts
  101.  
  102. lcd_instruction:
  103. jsr lcd_wait
  104. pha
  105. lsr
  106. lsr
  107. lsr
  108. lsr ; Send high 4 bits
  109. sta PORTB
  110. ora #E ; Set E bit to send instruction
  111. sta PORTB
  112. eor #E ; Clear E bit
  113. sta PORTB
  114. pla
  115. and #%00001111 ; Send low 4 bits
  116. sta PORTB
  117. ora #E ; Set E bit to send instruction
  118. sta PORTB
  119. eor #E ; Clear E bit
  120. sta PORTB
  121. rts
  122.  
  123.  
  124.  
  125. nmi:
  126. rti
  127. irq:
  128. pha
  129. bit HOLD
  130. bne slow ; jump to slow if HOLD is not zero
  131.  
  132. lda COUNT ; load count into a register
  133.  
  134. bit MODE
  135. bmi invert ; jump to invert if MODE bit 7 is a 1
  136.  
  137. inc ; increment the counter
  138. jmp finish
  139.  
  140. invert:
  141. dec ; decrement the counter
  142.  
  143. finish:
  144. beq switch ; if the counter is now 0, jump to switch
  145. sta PORTA ; output the counter to port A LEDs
  146. sta COUNT ; save new counter value
  147. jmp exit_irq_hold
  148.  
  149. switch:
  150. sta COUNT ; save counter without outputting
  151. lda #%10000000
  152. eor MODE ; flip bit 7 of MODE
  153. sta MODE ; save new MODE value
  154.  
  155. exit_irq_hold:
  156. lda #$02
  157. sta HOLD ; save a 2 into HOLD
  158. jmp exit_irq
  159.  
  160. slow:
  161. dec HOLD ; decrement HOLD
  162.  
  163. exit_irq:
  164. bit T1CL ; read timer 1 counter low to clear interrupt
  165. pla
  166. rti ; return from interrupt
  167.  
  168. .org $FFFA
  169. .word nmi
  170. .word reset
  171. .word irq
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement