use PA fpr keypad

This commit is contained in:
matthias@rpi 2023-11-13 19:14:18 +01:00
parent d5631307b0
commit 3b41b47ccd
2 changed files with 62 additions and 35 deletions

View File

@ -44,24 +44,25 @@ SPI_IO = IO2
;******************************************************************************** ;********************************************************************************
; Interrupts ; Interrupts
;******************************************************************************** ;********************************************************************************
.zeropage
IRQ_VAR: .res 1
.code .code
nmi: nmi:
lda #'%' lda #'%'
jsr lcd_char jsr lcd_char
rti rti
irq: irq:
IRQ_VAR = 0
; read IRFs, while bit 7 ist set handle interrupts ; read IRFs, while bit 7 ist set handle interrupts
@irq_io1: ; @irq_io1:
lda SPI_IO+IO::IFR ; lda SPI_IO+IO::IFR
sta IRQ_VAR
bbr7 IRQ_VAR,@irq_io2
bbs2 IRQ_VAR,@irq_spi_p ; check SR
@irq_io2:
; lda IO2+IO::IFR
; sta IRQ_VAR ; sta IRQ_VAR
; bbr7 IRQ_VAR,@irq_return ; bbr7 IRQ_VAR,@irq_io2
; bbs4 IRQ_VAR,@irq_keypad ; check CB1 @irq_io2:
lda IO2+IO::IFR
sta IRQ_VAR
bbr7 IRQ_VAR,@irq_return
bbs1 IRQ_VAR,@irq_keypad ; check CB1
bbs2 IRQ_VAR,@irq_spi_p ; check SR
; this should never be reached ; this should never be reached
jsr lcd_clear jsr lcd_clear
Print str_irq_unknown Print str_irq_unknown
@ -76,9 +77,9 @@ IRQ_VAR = 0
@irq_spi_p: @irq_spi_p:
jsr spi_p_read jsr spi_p_read
bra @irq_return bra @irq_return
@irq_dht: ; @irq_dht:
lda IO1 + IO::T1CL ;T1L2 ; clear interrupt flag ; lda IO1 + IO::T1CL ;T1L2 ; clear interrupt flag
bra @irq_return ; bra @irq_return
@irq_return: @irq_return:
rti rti
@ -88,15 +89,16 @@ IRQ_VAR = 0
reset: reset:
jsr lcd_init jsr lcd_init
; jsr kp_init
jsr spi_p_init
lda #$ff lda #$ff
sta IO1 + IO::DDRA sta IO1 + IO::DDRA
DEBUG_LED_OFF 0 DEBUG_LED_OFF 0
DEBUG_LED_OFF 1 DEBUG_LED_OFF 1
jsr kp_init
jsr spi_p_init
; ; INIT DHT ; ; INIT DHT
; lda #%11000010 ; enable interrupt for Timer 1 and CA1 on IO2 ; lda #%11000010 ; enable interrupt for Timer 1 and CA1 on IO2
; sta IER2 ; sta IER2
@ -128,7 +130,26 @@ reset:
jeq print_1 jeq print_1
cmp #'D' cmp #'D'
jeq print_2 jeq print_2
cmp #'0'
bne @l1
DEBUG_LED_OFF 0
jmp home
@l1:
cmp #'#'
bne @l2
DEBUG_LED_ON 0
jmp home
@l2:
cmp #'8'
bne @l3
DEBUG_LED_OFF 1
jmp home
@l3:
cmp #'9'
bne @l4
DEBUG_LED_ON 1
jmp home
@l4:
cmp #'*' ; print home menu again if not visible (message 1 and 2 jmp to home) cmp #'*' ; print home menu again if not visible (message 1 and 2 jmp to home)
jeq return_home jeq return_home
@ -147,7 +168,11 @@ print_2:
jmp home jmp home
.rodata .rodata
message_1: .asciiz " Powered by ......6502...... **** www.quintern.xyz" message_1:
.byte " Powered by "
.byte "......6502......"
.byte " **** "
.asciiz "www.quintern.xyz"
message_2: message_2:
.byte " Hello " .byte " Hello "
.byte " there " .byte " there "

View File

@ -4,7 +4,7 @@
; @device 4x4 Matrix Keypad ; @device 4x4 Matrix Keypad
; @details ; @details
; The LCD must be connected to a W65C22N Interface Chip: ; The LCD must be connected to a W65C22N Interface Chip:
; - IO.RB0-7 -> ; - IO.RA0-7 ->
; @requires KP_IO: Base Address of IO Chip ; @requires KP_IO: Base Address of IO Chip
; @depends IO-W65C22N ; @depends IO-W65C22N
;******************************************************************************** ;********************************************************************************
@ -30,22 +30,23 @@ RBUF_MEM_END = RBUF_MEM_START + KP_BUF_SIZE - 1
.proc kp_init .proc kp_init
; todo remove later and test ; todo remove later and test
lda #$ff lda #$ff
sta KP_IO+IO::DDRB sta KP_IO+IO::DDRA
stz KP_IO+IO::RB stz KP_IO+IO::RA
; INIT KEYPAD ; INIT KEYPAD
; todo: use masks ; todo: use masks
lda #%00001111; KP_IO+IO::RB 0-3 output lda #%11110000; KP_IO+IO::RA 0-3 output
sta KP_IO+IO::DDRB sta KP_IO+IO::DDRA
stz KP_IO+IO::RB ; KP_IO+IO::RB 4-7 1 so keypad press can be detected ; output 0, key press will pull input pin low
stz KP_IO+IO::RA
stz KP_IO+IO::ACR stz KP_IO+IO::ACR
; lda #%00010000 ; set CB1 to interrupt on pos. edge ; lda #%00010000 ; set CA1 to interrupt on pos. edge
; todo: use masks ; todo: use masks
lda #IO::PCR::CB1_IP_AE lda #IO::PCR::CA1_IP_AE
sta KP_IO+IO::PCR sta KP_IO+IO::PCR
jsr rb_keypad_init ; init keybuffer jsr rb_keypad_init ; init keybuffer
lda #(IO::IRQ::IRQ | IO::IRQ::CB1) ; enable interrupt for CB1 on KP_IO lda #(IO::IRQ::IRQ | IO::IRQ::CA1) ; enable interrupt for CA1 on KP_IO
sta KP_IO+IO::IER sta KP_IO+IO::IER
rts rts
.endproc .endproc
@ -60,23 +61,24 @@ RBUF_MEM_END = RBUF_MEM_START + KP_BUF_SIZE - 1
.proc kp_read_on_irq .proc kp_read_on_irq
; test each "row" and check which column is 1 ; test each "row" and check which column is 1
; todo dont check every column if the value has been found ; todo dont check every column if the value has been found
lda #%00001110 lda #%11100000
ldx #$00 ldx #$00
jsr @kp_read_column jsr @kp_read_column
lda #%00001101 lda #%11010000
ldx #$08 ldx #$08
jsr @kp_read_column jsr @kp_read_column
lda #%00001011 lda #%10110000
ldx #$04 ldx #$04
jsr @kp_read_column jsr @kp_read_column
lda #%00000111 lda #%01110000
ldx #$0c ldx #$0c
jsr @kp_read_column jsr @kp_read_column
stz KP_IO+IO::RB ; todo why all zero? stz KP_IO+IO::RA
lda KP_IO+IO::RA ; todo: verify that this is necessary so that rows 1-3 dont refire immediately after they are armed again because of stz
rts rts
@kp_read_column: @kp_read_column:
sta KP_IO+IO::RB sta KP_IO+IO::RA
lda KP_IO+IO::RB lda KP_IO+IO::RA
sta _KP_COLUMN ; store result in zeropage so that bbr can be used sta _KP_COLUMN ; store result in zeropage so that bbr can be used
bbr4 _KP_COLUMN,@kp_write bbr4 _KP_COLUMN,@kp_write
inx inx