.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 ;******************************************************************************** ; LCD ; .include "utility.asm6502" LCD_IO = IO1 .include "lcd.s65" ; Keypad Reading 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 ;******************************************************************************** nmi: lda #'%' jsr lcd_char rti irq: ; 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 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_return @irq_spi_p: jsr spi_p_read bra @irq_return @irq_dht: lda IO1 + IO::T1CL ;T1L2 ; clear interrupt flag bra @irq_return @irq_return: rti ;******************************************************************************** ; Reset sequence ;******************************************************************************** reset: jsr lcd_init jsr kp_init jsr spi_p_init lda #$ff sta IO1 + IO::DDRA DEBUG_LED_OFF 0 DEBUG_LED_OFF 1 ; ; INIT DHT ; lda #%11000010 ; enable interrupt for Timer 1 and CA1 on IO2 ; sta IER2 ; lda #%00111111 ; set Timer 1 to interrupt when loaded ; and ACR2 ; sta ACR2 ; lda #%00000001 ; set PCR2 bit 0 CA1 pos edge interrupt ; ora PCR2 ; sta PCR2 ; stz DHT_STATUS ; enable interrupts cli .proc return_home Print message_menu .endproc .proc home .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' ; jeq dht_request cmp #'C' 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) jeq return_home jmp home debug: DEBUG_LED_ON 0 jmp home .endproc print_1: Print message_1 jmp home print_2: Print message_2 jmp home .segment "RODATA" message_1: .asciiz " Powered by ......6502...... **** www.quintern.xyz" 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" ;******************************************************************************** ; reset vector ;******************************************************************************** .segment "RESET_VECTOR" .word nmi .word reset .word irq