-
Notifications
You must be signed in to change notification settings - Fork 0
/
buttons.s
120 lines (99 loc) · 1.85 KB
/
buttons.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
PORTB = $6000
PORTA = $6001
DDRB = $6002
DDRA = $6003
E = %10000000
RW = %01000000
RS = %00100000
LED_ON = %00000001
LED_OFF = %00000000
BUTTON_ON = %00000010
BUTTON_OFF = %00000100
BUTTON_MASK = %00000110
.org $8000
reset:
ldx #$FF
txs
lda #%11111111 ; Set all pins on port B to output
sta DDRB
lda #%11100001 ; Set top 3 pins and last on port A to output
sta DDRA
lda #%00111000 ; Set 8-bit mode; 2-line display; 5x8 font
jsr lcd_instruction
lda #%00001110 ; Display on; cursor on; blink off
jsr lcd_instruction
lda #%00000110 ; Increment and shift cursor; don't shift display
jsr lcd_instruction
lda #%00000001 ; Clear display
jsr lcd_instruction
lda #"R"
jsr print_char
lda #"e"
jsr print_char
lda #"a"
jsr print_char
lda #"d"
jsr print_char
lda #"y"
jsr print_char
lda #LED_OFF
sta PORTA
loop:
jsr test_button_on
jsr test_button_off
jmp loop
test_button_on:
lda PORTA
and #BUTTON_MASK
cmp #BUTTON_ON
beq set_led_on
rts
test_button_off:
lda PORTA
and #BUTTON_MASK
cmp #BUTTON_OFF
beq set_led_off
rts
set_led_on:
lda #%00000001 ; Clear display
jsr lcd_instruction
lda #"O"
jsr print_char
lda #"N"
jsr print_char
lda #LED_ON
sta PORTA
rts
set_led_off:
lda #%00000001 ; Clear display
jsr lcd_instruction
lda #"O"
jsr print_char
lda #"F"
jsr print_char
lda #"F"
jsr print_char
lda #LED_OFF
sta PORTA
rts
lcd_instruction:
sta PORTB
lda #0 ; Clear RS/RW/E bits
sta PORTA
lda #E ; Set E bit to send instruction
sta PORTA
lda #0 ; Clear RS/RW/E bits
sta PORTA
rts
print_char:
sta PORTB
lda #RS ; Set RS; Clear RW/E bits
sta PORTA
lda #(RS | E) ; Set E bit to send instruction
sta PORTA
lda #RS ; Clear E bits
sta PORTA
rts
.org $fffc
.word reset
.word $0000