diff --git a/main.s65 b/main.s65 index 78edfdc..643a21b 100644 --- a/main.s65 +++ b/main.s65 @@ -1,6 +1,26 @@ .segment "CODE" .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 ;******************************************************************************** @@ -9,13 +29,17 @@ LCD_IO = IO1 .include "lcd.s65" ; Keypad Reading -KP_IO = IO1 +KP_IO = IO2 .include "keypad.s65" +; SPI +SPI_IO = IO1 + .include "system/spi.s65" ; Printer .include "printer.s65" ; Digital Humidity and Temerature Sensor ; .include "dht.s65" + ;******************************************************************************** ; Interrupts ;******************************************************************************** @@ -24,51 +48,52 @@ nmi: jsr _lcd_char rti 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 sta 0 - ; todo: decide wether to read keypad or dht - ora #%10100000 - ; jsr lcd_char ;TODO: Remove - jsr kp_read - rti - ; bbs1 0,irq_keypad - lda #'-' - jsr _lcd_char - ; bbs4 0,irq_dht - ; bbs6 0,irq_dht - rti -irq_keypad: - jsr kp_read - rti -irq_dht: + bbr7 0,@irq_return + bbs4 0,@irq_keypad ; check CB1 + ; this should never be reached + Print str_irq_unknown + ; force reset interrupt flags + lda #$ff + sta IO1 + IO_IFR + sta IO2 + IO_IFR + bra @irq_return +@irq_keypad: + jsr kp_read_on_irq + bra irq +@irq_spi_p: + jsr spi_p_read + bra irq +@irq_dht: lda IO1 + IO_T1CL ;T1L2 ; clear interrupt flag - ; jsr dht_irq + bra irq +@irq_return: rti ;******************************************************************************** ; Reset sequence ;******************************************************************************** reset: - lda #%11111111 - 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 spi_p_init + jsr lcd_init - ; .repeat 1000 - ; nop - ; .endrepeat - ; SET_DEBUG_LED_ON jsr kp_init - ; SET_DEBUG_LED_OFF + + lda #$ff + sta IO1 + IO_DDRA + DEBUG_LED_ON 0 + DEBUG_LED_ON 1 ; ; INIT DHT ; lda #%11000010 ; enable interrupt for Timer 1 and CA1 on IO2 @@ -86,21 +111,27 @@ reset: .proc return_home 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 .proc home - ; SET_DEBUG_LED_ON - jsr kb_read +.macro wait +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 + stz KB_LAST + ; beq home cmp #'A' jeq printer cmp #'B' @@ -109,20 +140,19 @@ reset: jeq print_1 cmp #'D' jeq print_2 + cmp '4' + bra debug cmp #'*' ; print home menu again if not visible (message 1 and 2 jmp to home) - beq return_home - - ; .repeat 500 - ; nop - ; .endrepeat - ; SET_DEBUG_LED_OFF - ; .repeat 500 - ; nop - ; .endrepeat + jeq return_home jmp home +debug: + DEBUG_LED_OFF 0 + jmp home + + .endproc print_1: @@ -135,12 +165,20 @@ print_2: .segment "RODATA" 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: .byte " Printer " .byte " Temperatur " .byte " Text 1 " .asciiz " Text 2 " +str_irq: + .asciiz "IRQ detected! " +str_irq_unknown: + .asciiz "Unknown IRQ src!" .segment "CODE" ;********************************************************************************