-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspislave.s
91 lines (77 loc) · 1.39 KB
/
spislave.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
.include "defs.inc"
.include "via.inc"
DESTINATION = $200
.zeropage
startclk: .res 1
accumulator: .res 1
.code
.macro CHECK_CE
lda PORTA
and #SPI_CE
.endmacro
.proc spitest
lda #>load_program
ldy #<load_program
jsr lcd_puts
lda #0
sta accumulator
lda 0
sta r0
lda #>DESTINATION
sta r0+1
ldy #<DESTINATION
; CE must start high
init:
CHECK_CE
beq init
; wait for master to lower CE
wait_ce:
CHECK_CE
bne wait_ce
jsr led_on
next_byte:
ldx #8
; wait for CLK to go high
wait_clk_hi:
CHECK_CE
bne spi_done
lda PORTA
and #SPI_CLK
beq wait_clk_hi
lda PORTA
clc
and #SPI_MOSI
beq add_bit
sec
add_bit:
rol accumulator
; wait for CLK to go low
wait_clk_lo:
CHECK_CE
bne spi_done
lda PORTA
and #SPI_CLK
bne wait_clk_lo
dex
bne wait_clk_hi
lda accumulator
sta (r0),y
iny
bne next_byte
inc r0+1
jmp next_byte
.endproc
.proc spi_done
jsr led_off
cpy #0
bne execute
lda #>DESTINATION
cmp r0+1
bne execute
jmp spitest
execute:
jmp DESTINATION
.endproc
.rodata
load_program:
.asciiz "load program"