.include "system/system.s65" .code .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 "system/lcd.s65" ; Keypad Reading KP_IO = IO2 .include "system/keypad.s65" ; SPI SPI_IO = IO2 .include "system/spi.s65" ; Printer .include "programs/printer.s65" .include "programs/print_slow.s65" ; Digital Humidity and Temerature Sensor ; .include "dht.s65" ;******************************************************************************** ; Interrupts ;******************************************************************************** .code nmi: lda #'%' jsr lcd_char rti irq: IRQ_VAR = 0 ; read IRFs, while bit 7 ist set handle interrupts @irq_io1: 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 ; bbr7 IRQ_VAR,@irq_return ; bbs4 IRQ_VAR,@irq_keypad ; check CB1 ; this should never be reached jsr lcd_clear 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 jsr rb_keypad_read beq home ; beq home cmp #'A' jeq printer cmp #'B' jeq SPI_CODE_START ; jeq dht_request cmp #'C' jeq print_1 cmp #'D' jeq print_2 cmp #'*' ; print home menu again if not visible (message 1 and 2 jmp to home) jeq return_home jmp home .endproc print_1: jsr lcd_clear PrintSlow message_1,10 jmp home print_2: jsr lcd_clear PrintSlow message_2,10 jmp home .rodata message_1: .asciiz " Powered by ......6502...... **** www.quintern.xyz" message_2: .byte " Hello " .byte " there " .byte " <3 " .asciiz "================" message_menu: .byte " Printer " ; .byte " Temperatur " .byte " Run from SPI" .byte " Text 1 " .asciiz " Text 2 " str_irq: .asciiz "IRQ detected! " str_irq_unknown: .asciiz "Unknown IRQ src!" ;******************************************************************************** ; reset vector ;******************************************************************************** .segment "RESET_VECTOR" .word nmi .word reset .word irq