Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; set VIA address
- PORTB = $6000
- PORTA = $6001
- DDRB = $6002
- DDRA = $6003
- T1CL = $6004
- T1CH = $6005
- ACR = $600B
- IFR = $600D
- IER = $600E
- ; define variables
- MODE = $0300
- HOLD = $0301
- COUNT = $0302
- E = %01000000
- RW = %00100000
- RS = %00010000
- .org $8000
- reset:
- sei ;disable interrupts
- ldx #$FF
- txs ;inlisize stack pointer
- lda #$FF
- sta DDRB ; set all port b pins to output
- sta DDRA ; set all port a pins to output
- lda #%01000000
- sta ACR ; enable timer 1 continuous mode
- lda #%11000000
- sta IER ; enable timer 1 interrupts
- stz HOLD ; set hold to 0
- stz MODE ; set mode to 0
- lda #$01
- sta COUNT ; set count to 1
- sta PORTA ; set port a to output 1
- jsr lcd_init
- lda #%00101000 ; Set 4-bit mode; 2-line display; 5x8 font
- jsr lcd_instruction
- lda #%00001110 ; Display on; cursor on; blink off
- jsr lcd_instruction
- lda #%00000110 ; Increment and shift cursor; don't shift display
- jsr lcd_instruction
- lda #$00000001 ; Clear display
- jsr lcd_instruction
- cli ; enable interrupts
- lda #$FF
- sta T1CL ; load timer 1 counter low with 255
- sta T1CH ; load timer 1 counter high with 255, and start the count
- loop:
- ; do nothing loop
- jmp loop
- lcd_wait:
- pha
- lda #%11110000 ; LCD data is input
- sta DDRB
- lcdbusy:
- lda #RW
- sta PORTB
- lda #(RW | E)
- sta PORTB
- lda PORTB ; Read high nibble
- pha ; and put on stack since it has the busy flag
- lda #RW
- sta PORTB
- lda #(RW | E)
- sta PORTB
- lda PORTB ; Read low nibble
- pla ; Get high nibble off stack
- and #%00001000
- bne lcdbusy
- lda #RW
- sta PORTB
- lda #%11111111 ; LCD data is output
- sta DDRB
- pla
- rts
- lcd_init:
- lda #%00000010 ; Set 4-bit mode
- sta PORTB
- ora #E
- sta PORTB
- and #%00001111
- sta PORTB
- rts
- lcd_instruction:
- jsr lcd_wait
- pha
- lsr
- lsr
- lsr
- lsr ; Send high 4 bits
- sta PORTB
- ora #E ; Set E bit to send instruction
- sta PORTB
- eor #E ; Clear E bit
- sta PORTB
- pla
- and #%00001111 ; Send low 4 bits
- sta PORTB
- ora #E ; Set E bit to send instruction
- sta PORTB
- eor #E ; Clear E bit
- sta PORTB
- rts
- nmi:
- rti
- irq:
- pha
- bit HOLD
- bne slow ; jump to slow if HOLD is not zero
- lda COUNT ; load count into a register
- bit MODE
- bmi invert ; jump to invert if MODE bit 7 is a 1
- inc ; increment the counter
- jmp finish
- invert:
- dec ; decrement the counter
- finish:
- beq switch ; if the counter is now 0, jump to switch
- sta PORTA ; output the counter to port A LEDs
- sta COUNT ; save new counter value
- jmp exit_irq_hold
- switch:
- sta COUNT ; save counter without outputting
- lda #%10000000
- eor MODE ; flip bit 7 of MODE
- sta MODE ; save new MODE value
- exit_irq_hold:
- lda #$02
- sta HOLD ; save a 2 into HOLD
- jmp exit_irq
- slow:
- dec HOLD ; decrement HOLD
- exit_irq:
- bit T1CL ; read timer 1 counter low to clear interrupt
- pla
- rti ; return from interrupt
- .org $FFFA
- .word nmi
- .word reset
- .word irq
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement