This commit is contained in:
matthias@rpi 2023-10-30 22:17:19 +01:00
parent 5ec8858180
commit 55d0926fe4

148
main.s65
View File

@ -1,6 +1,26 @@
.segment "CODE" .segment "CODE"
.include "system/system.h65" .include "system/system.h65"
.macro DEBUG_LED_OFF nr
lda IO1 + IO_RA
.if nr = 0
and #%11111110
.else
and #%11111101
.endif
sta IO1 + IO_RA
.endmacro
.macro DEBUG_LED_ON nr
lda IO1 + IO_RA
.if nr = 0
ora #%00000001
.else
ora #%00000010
.endif
sta IO1 + IO_RA
.endmacro
;******************************************************************************** ;********************************************************************************
; Modules ; Modules
;******************************************************************************** ;********************************************************************************
@ -9,13 +29,17 @@
LCD_IO = IO1 LCD_IO = IO1
.include "lcd.s65" .include "lcd.s65"
; Keypad Reading ; Keypad Reading
KP_IO = IO1 KP_IO = IO2
.include "keypad.s65" .include "keypad.s65"
; SPI
SPI_IO = IO1
.include "system/spi.s65"
; Printer ; Printer
.include "printer.s65" .include "printer.s65"
; Digital Humidity and Temerature Sensor ; Digital Humidity and Temerature Sensor
; .include "dht.s65" ; .include "dht.s65"
;******************************************************************************** ;********************************************************************************
; Interrupts ; Interrupts
;******************************************************************************** ;********************************************************************************
@ -24,51 +48,52 @@ nmi:
jsr _lcd_char jsr _lcd_char
rti rti
irq: irq:
; lda IFR2 todo: verify that the line below does the same thing ; read IRFs, while bit 7 ist set handle interrupts
; Print str_irq
@irq_io1:
; todo use a reserved address instead of 0
lda IO1+IO_IFR
sta 0
bbr7 0,@irq_io2
bbs2 0,@irq_spi_p ; check SR
@irq_io2:
lda IO2+IO_IFR lda IO2+IO_IFR
sta 0 sta 0
; todo: decide wether to read keypad or dht bbr7 0,@irq_return
ora #%10100000 bbs4 0,@irq_keypad ; check CB1
; jsr lcd_char ;TODO: Remove ; this should never be reached
jsr kp_read Print str_irq_unknown
rti ; force reset interrupt flags
; bbs1 0,irq_keypad lda #$ff
lda #'-' sta IO1 + IO_IFR
jsr _lcd_char sta IO2 + IO_IFR
; bbs4 0,irq_dht bra @irq_return
; bbs6 0,irq_dht @irq_keypad:
rti jsr kp_read_on_irq
irq_keypad: bra irq
jsr kp_read @irq_spi_p:
rti jsr spi_p_read
irq_dht: bra irq
@irq_dht:
lda IO1 + IO_T1CL ;T1L2 ; clear interrupt flag lda IO1 + IO_T1CL ;T1L2 ; clear interrupt flag
; jsr dht_irq bra irq
@irq_return:
rti rti
;******************************************************************************** ;********************************************************************************
; Reset sequence ; Reset sequence
;******************************************************************************** ;********************************************************************************
reset: reset:
lda #%11111111 jsr spi_p_init
sta IO1 + IO_DDRA
.macro SET_DEBUG_LED_OFF
lda #%00000000
sta IO1 + IO_RANH
.endmacro
.macro SET_DEBUG_LED_ON
lda #%11111111
sta IO1 + IO_RANH
.endmacro
; SET_DEBUG_LED_OFF
jsr lcd_init jsr lcd_init
; .repeat 1000
; nop
; .endrepeat
; SET_DEBUG_LED_ON
jsr kp_init jsr kp_init
; SET_DEBUG_LED_OFF
lda #$ff
sta IO1 + IO_DDRA
DEBUG_LED_ON 0
DEBUG_LED_ON 1
; ; 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
@ -86,21 +111,27 @@ reset:
.proc return_home .proc return_home
Print message_menu Print message_menu
; @return_home:
; lda menu,x
; beq @return_home_done
; sta TO_PRINT,x
; jsr _lcd_char
; inx
; bra @return_home
; @return_home_done:
; jsr lcd_print_clear
.endproc .endproc
.proc home .proc home
; SET_DEBUG_LED_ON .macro wait
jsr kb_read wait:
stz 1
stz 2
.repeat 2
nop
.endrepeat
inc 1
bne wait
inc 2
bne wait
.endmacro
; jsr rb_keypad_read
lda KB_LAST
beq home beq home
stz KB_LAST
; beq home
cmp #'A' cmp #'A'
jeq printer jeq printer
cmp #'B' cmp #'B'
@ -109,20 +140,19 @@ reset:
jeq print_1 jeq print_1
cmp #'D' cmp #'D'
jeq print_2 jeq print_2
cmp '4'
bra debug
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)
beq return_home jeq return_home
; .repeat 500
; nop
; .endrepeat
; SET_DEBUG_LED_OFF
; .repeat 500
; nop
; .endrepeat
jmp home jmp home
debug:
DEBUG_LED_OFF 0
jmp home
.endproc .endproc
print_1: print_1:
@ -135,12 +165,20 @@ print_2:
.segment "RODATA" .segment "RODATA"
message_1: .asciiz " Powered by ......6502...... **** www.quintern.xyz" message_1: .asciiz " Powered by ......6502...... **** www.quintern.xyz"
message_2: .asciiz " Danke fuer eure Aufmerksamkeit ;) " message_2:
.byte " Hallo "
.byte " Clara "
.byte " <3 "
.asciiz "================"
message_menu: message_menu:
.byte "<A> Printer " .byte "<A> Printer "
.byte "<B> Temperatur " .byte "<B> Temperatur "
.byte "<C> Text 1 " .byte "<C> Text 1 "
.asciiz "<D> Text 2 " .asciiz "<D> Text 2 "
str_irq:
.asciiz "IRQ detected! "
str_irq_unknown:
.asciiz "Unknown IRQ src!"
.segment "CODE" .segment "CODE"
;******************************************************************************** ;********************************************************************************