Compare commits
8 Commits
498d61186a
...
ae17478c14
Author | SHA1 | Date | |
---|---|---|---|
|
ae17478c14 | ||
|
e0ba885132 | ||
|
454812a647 | ||
|
60f42f2d90 | ||
|
cb203bf62d | ||
|
db80bd9aa3 | ||
|
0b1dcf4998 | ||
|
e0f58c262a |
@ -1,8 +1,12 @@
|
|||||||
MEMORY {
|
MEMORY {
|
||||||
ROM: start = $8000, size = $8000, type = ro, file = %O, fill = yes;
|
RAM_ZP: start = $0000, size = $100, type = rw, file = "", fill = yes;
|
||||||
RAM: start = $0000, size = $5fff, type = rw, file = "", fill = yes;
|
RAM: start = $0100, size = $5eff, type = rw, file = "", fill = yes;
|
||||||
|
VIA1: start = $6000, size = $600f, type = rw, file = "", fill = yes;
|
||||||
|
VIA2: start = $7000, size = $700f, type = rw, file = "", fill = yes;
|
||||||
|
ROM: start = $8000, size = $8000, type = ro, file = %O, fill = yes;
|
||||||
}
|
}
|
||||||
SEGMENTS {
|
SEGMENTS {
|
||||||
|
ZP: load = RAM_ZP, type = bss, start = $0;
|
||||||
RAM: load = RAM, type = bss;
|
RAM: load = RAM, type = bss;
|
||||||
CODE: load = ROM, type = ro;
|
CODE: load = ROM, type = ro;
|
||||||
RODATA: load = ROM, type = ro;
|
RODATA: load = ROM, type = ro;
|
||||||
|
67
main.s65
67
main.s65
@ -27,15 +27,16 @@
|
|||||||
; LCD
|
; LCD
|
||||||
; .include "utility.asm6502"
|
; .include "utility.asm6502"
|
||||||
LCD_IO = IO1
|
LCD_IO = IO1
|
||||||
.include "lcd.s65"
|
.include "system/lcd.s65"
|
||||||
; Keypad Reading
|
; Keypad Reading
|
||||||
KP_IO = IO2
|
KP_IO = IO2
|
||||||
.include "keypad.s65"
|
.include "system/keypad.s65"
|
||||||
; SPI
|
; SPI
|
||||||
SPI_IO = IO1
|
SPI_IO = IO2
|
||||||
.include "system/spi.s65"
|
.include "system/spi.s65"
|
||||||
; Printer
|
; Printer
|
||||||
.include "printer.s65"
|
.include "programs/printer.s65"
|
||||||
|
.include "programs/print_slow.s65"
|
||||||
; Digital Humidity and Temerature Sensor
|
; Digital Humidity and Temerature Sensor
|
||||||
; .include "dht.s65"
|
; .include "dht.s65"
|
||||||
|
|
||||||
@ -48,20 +49,20 @@ nmi:
|
|||||||
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
|
||||||
; Print str_irq
|
|
||||||
@irq_io1:
|
@irq_io1:
|
||||||
; todo use a reserved address instead of 0
|
lda SPI_IO+IO::IFR
|
||||||
lda IO1+IO::IFR
|
sta IRQ_VAR
|
||||||
sta 0
|
bbr7 IRQ_VAR,@irq_io2
|
||||||
bbr7 0,@irq_io2
|
bbs2 IRQ_VAR,@irq_spi_p ; check SR
|
||||||
bbs2 0,@irq_spi_p ; check SR
|
|
||||||
@irq_io2:
|
@irq_io2:
|
||||||
lda IO2+IO::IFR
|
; lda IO2+IO::IFR
|
||||||
sta 0
|
; sta IRQ_VAR
|
||||||
bbr7 0,@irq_return
|
; bbr7 IRQ_VAR,@irq_return
|
||||||
bbs4 0,@irq_keypad ; check CB1
|
; bbs4 IRQ_VAR,@irq_keypad ; check CB1
|
||||||
; this should never be reached
|
; this should never be reached
|
||||||
|
jsr lcd_clear
|
||||||
Print str_irq_unknown
|
Print str_irq_unknown
|
||||||
; force reset interrupt flags
|
; force reset interrupt flags
|
||||||
lda #$ff
|
lda #$ff
|
||||||
@ -86,7 +87,7 @@ irq:
|
|||||||
reset:
|
reset:
|
||||||
jsr lcd_init
|
jsr lcd_init
|
||||||
|
|
||||||
jsr kp_init
|
; jsr kp_init
|
||||||
|
|
||||||
jsr spi_p_init
|
jsr spi_p_init
|
||||||
|
|
||||||
@ -114,53 +115,34 @@ reset:
|
|||||||
.endproc
|
.endproc
|
||||||
|
|
||||||
.proc home
|
.proc home
|
||||||
.macro wait
|
jsr rb_keypad_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
|
; beq home
|
||||||
cmp #'A'
|
cmp #'A'
|
||||||
jeq printer
|
jeq printer
|
||||||
cmp #'B'
|
cmp #'B'
|
||||||
|
jeq SPI_CODE_START
|
||||||
; jeq dht_request
|
; jeq dht_request
|
||||||
cmp #'C'
|
cmp #'C'
|
||||||
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)
|
||||||
jeq return_home
|
jeq return_home
|
||||||
|
|
||||||
jmp home
|
jmp home
|
||||||
|
|
||||||
debug:
|
|
||||||
DEBUG_LED_ON 0
|
|
||||||
jmp home
|
|
||||||
|
|
||||||
|
|
||||||
.endproc
|
.endproc
|
||||||
|
|
||||||
|
|
||||||
print_1:
|
print_1:
|
||||||
Print message_1
|
jsr lcd_clear
|
||||||
|
PrintSlow message_1,10
|
||||||
jmp home
|
jmp home
|
||||||
|
|
||||||
print_2:
|
print_2:
|
||||||
Print message_2
|
jsr lcd_clear
|
||||||
|
PrintSlow message_2,10
|
||||||
jmp home
|
jmp home
|
||||||
|
|
||||||
.segment "RODATA"
|
.segment "RODATA"
|
||||||
@ -172,7 +154,8 @@ message_2:
|
|||||||
.asciiz "================"
|
.asciiz "================"
|
||||||
message_menu:
|
message_menu:
|
||||||
.byte "<A> Printer "
|
.byte "<A> Printer "
|
||||||
.byte "<B> Temperatur "
|
; .byte "<B> Temperatur "
|
||||||
|
.byte "<B> Run from SPI"
|
||||||
.byte "<C> Text 1 "
|
.byte "<C> Text 1 "
|
||||||
.asciiz "<D> Text 2 "
|
.asciiz "<D> Text 2 "
|
||||||
str_irq:
|
str_irq:
|
||||||
|
46
programs/print_slow.s65
Normal file
46
programs/print_slow.s65
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
|
||||||
|
.ifndef INCLUDE_PRINT_SLOW
|
||||||
|
INCLUDE_PRINT_SLOW = 1
|
||||||
|
|
||||||
|
.include "programs/sleep.s65"
|
||||||
|
.include "system/lcd.s65"
|
||||||
|
|
||||||
|
|
||||||
|
;********************************************************************************
|
||||||
|
; @function Print a null-terminated string
|
||||||
|
; @param ARG0-1: Address of the string to print
|
||||||
|
; @param x: time to sleep in centiseconds
|
||||||
|
;********************************************************************************
|
||||||
|
.proc print_slow
|
||||||
|
ldy #$00
|
||||||
|
@print_loop:
|
||||||
|
lda (ARG0),y
|
||||||
|
beq @print_end
|
||||||
|
phx
|
||||||
|
jsr sleep
|
||||||
|
plx
|
||||||
|
jsr lcd_char
|
||||||
|
iny
|
||||||
|
bra @print_loop
|
||||||
|
@print_end:
|
||||||
|
rts
|
||||||
|
.endproc
|
||||||
|
|
||||||
|
;********************************************************************************
|
||||||
|
; @macro Print a null-terminated string
|
||||||
|
; @param message: Address of the message
|
||||||
|
; @param time_cs: time to sleep in centiseconds
|
||||||
|
;********************************************************************************
|
||||||
|
.macro PrintSlow message,time_cs
|
||||||
|
jsr lcd_clear
|
||||||
|
lda #.LOBYTE(message)
|
||||||
|
sta ARG0
|
||||||
|
lda #.HIBYTE(message)
|
||||||
|
sta ARG1
|
||||||
|
phx
|
||||||
|
ldx #time_cs
|
||||||
|
jsr print_slow
|
||||||
|
plx
|
||||||
|
.endmacro
|
||||||
|
|
||||||
|
.endif ; guard
|
@ -13,4 +13,4 @@ printer:
|
|||||||
jeq return_home
|
jeq return_home
|
||||||
jsr lcd_char
|
jsr lcd_char
|
||||||
bra @printer_loop
|
bra @printer_loop
|
||||||
.endif
|
.endif ; guard
|
||||||
|
41
programs/sleep.s65
Normal file
41
programs/sleep.s65
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
.ifndef INCLUDE_SLEEP
|
||||||
|
INCLUDE_SLEEP = 1
|
||||||
|
;********************************************************************************
|
||||||
|
; @macro Sleep
|
||||||
|
; @param time_cs: Time to sleep in centiseconds (10^-2s = 10ms)
|
||||||
|
; @details
|
||||||
|
; Interrupts might change the actual time to finish
|
||||||
|
;********************************************************************************
|
||||||
|
.macro Sleep time_cs
|
||||||
|
phx
|
||||||
|
ldx #time_cs
|
||||||
|
jsr sleep
|
||||||
|
plx
|
||||||
|
.endmacro
|
||||||
|
|
||||||
|
;********************************************************************************
|
||||||
|
; @function sleep
|
||||||
|
; @param x: Time to sleep in centiseconds (10^-2s = 10ms)
|
||||||
|
; @details
|
||||||
|
; Interrupts might change the actual time to finish
|
||||||
|
; To be exact, time_cs is in units of 0.010244s
|
||||||
|
;********************************************************************************
|
||||||
|
.proc sleep
|
||||||
|
VAR_1 = 0
|
||||||
|
stz VAR_1
|
||||||
|
@loop:
|
||||||
|
.repeat 17
|
||||||
|
nop ; 2 - i
|
||||||
|
.endrepeat
|
||||||
|
inc VAR_1 ; 3 - zp
|
||||||
|
bne @loop ; 2/3 - r (2 if not taken, but here most of the time its 3)
|
||||||
|
; reaching this takes 256 * (X * 2(nop) + 3(inc) + 3(bne)) - 1(last bne) cycles
|
||||||
|
; with X = 17: T1 = (256×(17×2 + 3 +3) − 1) × (1/1MHz) = 0,010 239 s
|
||||||
|
dex ; 2 - i
|
||||||
|
bne @loop ; 2/3 - r
|
||||||
|
; with T1 = for running through VAR_1, one iteration takes
|
||||||
|
; T1 + (2(dex) + 3(bne)) × (1/1MHz) = 0,010 244 s
|
||||||
|
rts
|
||||||
|
; so T = N * 0,010 244 s - (1(last bne) + 4(jsr) + 6(rts)) * (1/1MHz)
|
||||||
|
.endproc
|
||||||
|
.endif ; guard
|
@ -58,7 +58,6 @@ RB_LENGTH = RBUF_MEM_END - RBUF_MEM_START - 2
|
|||||||
cpx RB_WRITE
|
cpx RB_WRITE
|
||||||
beq @rb_read_rts ; if buffer empty
|
beq @rb_read_rts ; if buffer empty
|
||||||
lda RB_START,x
|
lda RB_START,x
|
||||||
Inc_buf_ptr RB_READ
|
|
||||||
inx ; increment RB_READ pointer, not using macro bec. of unknown Pz
|
inx ; increment RB_READ pointer, not using macro bec. of unknown Pz
|
||||||
cpx #RB_LENGTH
|
cpx #RB_LENGTH
|
||||||
beq @read_wrap
|
beq @read_wrap
|
||||||
@ -89,16 +88,17 @@ RB_LENGTH = RBUF_MEM_END - RBUF_MEM_START - 2
|
|||||||
stx RB_WRITE
|
stx RB_WRITE
|
||||||
@check_buf_full: ; increment read if buffer is full
|
@check_buf_full: ; increment read if buffer is full
|
||||||
cpx RB_READ
|
cpx RB_READ
|
||||||
beq read_inc
|
beq @read_inc
|
||||||
rts
|
rts
|
||||||
@write_wrap: ; ptr == RB_LENGTH -> ptr = 0
|
@write_wrap: ; ptr == RB_LENGTH -> ptr = 0
|
||||||
stz RB_WRITE
|
stz RB_WRITE
|
||||||
|
ldx #0
|
||||||
bra @check_buf_full
|
bra @check_buf_full
|
||||||
@read_inc:
|
@read_inc:
|
||||||
ldx RB_READ
|
ldx RB_READ
|
||||||
inx
|
inx
|
||||||
cpx #RB_LENGTH
|
cpx #RB_LENGTH
|
||||||
beq read_wrap
|
beq @read_wrap
|
||||||
stx RB_READ
|
stx RB_READ
|
||||||
rts
|
rts
|
||||||
@read_wrap: ; ptr == RB_LENGTH -> ptr = 0
|
@read_wrap: ; ptr == RB_LENGTH -> ptr = 0
|
||||||
|
@ -18,7 +18,7 @@ INCLUDE_KEYPAD = 1
|
|||||||
|
|
||||||
|
|
||||||
RBUF_MEM_START = $200
|
RBUF_MEM_START = $200
|
||||||
RBUF_MEM_END = $2ff
|
RBUF_MEM_END = $208
|
||||||
.define RBUF_NAME "keypad"
|
.define RBUF_NAME "keypad"
|
||||||
.include "buffer.s65"
|
.include "buffer.s65"
|
||||||
|
|
||||||
@ -61,16 +61,15 @@ KB_VAR = $05 ; any free zp address
|
|||||||
ldx #$00
|
ldx #$00
|
||||||
jsr @kp_read_column
|
jsr @kp_read_column
|
||||||
lda #%00001101
|
lda #%00001101
|
||||||
ldx #$04
|
ldx #$08
|
||||||
jsr @kp_read_column
|
jsr @kp_read_column
|
||||||
lda #%00001011
|
lda #%00001011
|
||||||
ldx #$08
|
ldx #$04
|
||||||
jsr @kp_read_column
|
jsr @kp_read_column
|
||||||
lda #%00000111
|
lda #%00000111
|
||||||
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::RB ; todo why all zero?
|
||||||
; lda KP_IO+IO::RB ; read to definetly clear the interrupt flag
|
|
||||||
rts
|
rts
|
||||||
@kp_read_column:
|
@kp_read_column:
|
||||||
sta KP_IO+IO::RB
|
sta KP_IO+IO::RB
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
; @optparam LCD_MEM: Memory address for a runtime variable. Default = $300
|
; @optparam LCD_MEM: Memory address for a runtime variable. Default = $300
|
||||||
; @depends IO-W65C22N
|
; @depends IO-W65C22N
|
||||||
;********************************************************************************
|
;********************************************************************************
|
||||||
|
.ifndef INCLUDE_LCD
|
||||||
|
INCLUDE_LCD = 1
|
||||||
|
|
||||||
.ifndef LCD_IO
|
.ifndef LCD_IO
|
||||||
.fatal "LCD_IO is not defined: set it to the base address of the IO chip of the LCD"
|
.fatal "LCD_IO is not defined: set it to the base address of the IO chip of the LCD"
|
||||||
@ -228,3 +230,4 @@ LCD_CLEAR = %00000000
|
|||||||
jsr _lcd_cmd
|
jsr _lcd_cmd
|
||||||
rts
|
rts
|
||||||
.endproc
|
.endproc
|
||||||
|
.endif
|
||||||
|
31
system/ram.s65
Normal file
31
system/ram.s65
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
|
||||||
|
|
||||||
|
.segment "ZP"
|
||||||
|
.org 0
|
||||||
|
.byte NULL
|
||||||
|
.org $10
|
||||||
|
.byte ARG0
|
||||||
|
.byte ARG1
|
||||||
|
.byte ARG2
|
||||||
|
.byte ARG3
|
||||||
|
.byte ARG4
|
||||||
|
.byte ARG5
|
||||||
|
.byte ARG6
|
||||||
|
.byte ARG7
|
||||||
|
.byte ARG8
|
||||||
|
.byte ARG9
|
||||||
|
.byte ARG10
|
||||||
|
.byte ARG11
|
||||||
|
.byte ARG12
|
||||||
|
.byte ARG13
|
||||||
|
.byte ARG14
|
||||||
|
.byte ARG15
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.segment "RAM"
|
||||||
|
|
||||||
|
.segment "SPI"
|
||||||
|
.byte SPI_BYTES_WRITTEN
|
||||||
|
.byte SPI_PAGES_WRITTEN
|
||||||
|
.byte
|
@ -9,28 +9,34 @@
|
|||||||
|
|
||||||
.ifndef INCLUDE_SPI
|
.ifndef INCLUDE_SPI
|
||||||
INCLUDE_SPI = 1
|
INCLUDE_SPI = 1
|
||||||
.segment "CODE"
|
.segment "CODE"
|
||||||
|
|
||||||
|
SPI_CODE_START = $3000
|
||||||
|
SPI_PAGES_WRITTEN = $2fff
|
||||||
|
SPI_BYTES_WRITTEN = $2ffe
|
||||||
|
|
||||||
|
|
||||||
.struct SPI_P_Pins
|
.struct SPI_P_Pins
|
||||||
; VIA addresses
|
; VIA addresses
|
||||||
DDR_a .word ; address of the data direction register
|
DDR_a .word ; address of the data direction register
|
||||||
R_a .word ; address of the register
|
R_a .word ; address of the register
|
||||||
; pin mask
|
; pin mask
|
||||||
SCLK_p .byte ; Serial Clock
|
SCLK_p .byte ; Serial Clock
|
||||||
POCI_p .byte ; Peripheral Out / Controller In
|
POCI_p .byte ; Peripheral Out / Controller In
|
||||||
PICO_p .byte ; Peripheral In / Controller Out
|
PICO_p .byte ; Peripheral In / Controller Out
|
||||||
CSB_p .byte ; Chip Select
|
CSB_p .byte ; Chip Select
|
||||||
; settings
|
; settings
|
||||||
CPOL .byte ; Clock Polarity
|
CPOL .byte ; Clock Polarity
|
||||||
CPHA .byte ; Clock Phase
|
CPHA .byte ; Clock Phase
|
||||||
.endstruct
|
.endstruct
|
||||||
|
|
||||||
;********************************************************************************
|
;********************************************************************************
|
||||||
; @function Initialize the IO Adapter for SPI
|
; @function Initialize the IO Adapter for SPI
|
||||||
; @param ARG0-1 Address of the SPI_Pins struct
|
; @param ARG0-1 Address of the SPI_Pins struct
|
||||||
;********************************************************************************
|
;********************************************************************************
|
||||||
.proc spi_p_init
|
.proc spi_p_init
|
||||||
|
stz SPI_PAGES_WRITTEN
|
||||||
|
stz SPI_BYTES_WRITTEN
|
||||||
; todo USE MASKS
|
; todo USE MASKS
|
||||||
; set Shift register to shift in under external clock on CB1
|
; set Shift register to shift in under external clock on CB1
|
||||||
lda #IO::ACR::SR_SIN_PHIE
|
lda #IO::ACR::SR_SIN_PHIE
|
||||||
@ -39,13 +45,16 @@ INCLUDE_SPI = 1
|
|||||||
; enable SR interrupts
|
; enable SR interrupts
|
||||||
lda #(IO::IRQ::IRQ | IO::IRQ::SR)
|
lda #(IO::IRQ::IRQ | IO::IRQ::SR)
|
||||||
sta SPI_IO + IO::IER
|
sta SPI_IO + IO::IER
|
||||||
|
DEBUG_LED_ON 1
|
||||||
rts
|
rts
|
||||||
.endproc
|
.endproc
|
||||||
|
|
||||||
.proc spi_p_read
|
.proc spi_p_read
|
||||||
|
DEBUG_LED_ON 0
|
||||||
; print received byte
|
; print received byte
|
||||||
lda SPI_IO + IO::SR
|
lda SPI_IO + IO::SR
|
||||||
jsr lcd_char
|
jsr lcd_char
|
||||||
|
inc SPI_BYTES_WRITTEN
|
||||||
rts
|
rts
|
||||||
.endproc
|
.endproc
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@ INCLUDE_UTILITY = 1
|
|||||||
eor original
|
eor original
|
||||||
sta original
|
sta original
|
||||||
.endmacro
|
.endmacro
|
||||||
.endif
|
|
||||||
|
|
||||||
|
|
||||||
;_n_genlabel .set 0
|
;_n_genlabel .set 0
|
||||||
@ -31,3 +30,5 @@ INCLUDE_UTILITY = 1
|
|||||||
; .ident(.sprintf("generated_label%04X", _n_genlabel))
|
; .ident(.sprintf("generated_label%04X", _n_genlabel))
|
||||||
; _n_genlabel .set _n_genlabel + 1
|
; _n_genlabel .set _n_genlabel + 1
|
||||||
;.endmacro
|
;.endmacro
|
||||||
|
|
||||||
|
.endif
|
||||||
|
Loading…
Reference in New Issue
Block a user