-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlcd.s
162 lines (136 loc) · 2.92 KB
/
lcd.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
.include "defs.inc"
.include "via.inc"
.proc lcd_wait
lda #%00000000 ; Set all pins on port B to input
sta DDRB
lda #<~(RS | E | RW) ; Clear RS/RW/E bits
and PORTA
sta PORTA
loop:
lda #RW ; Clear RS/E bits
ora PORTA
sta PORTA
lda #(RW | E) ; Set RW and E bits to check busy
ora PORTA
sta PORTA
lda #<~(RS | E | RW) ; Clear RS/RW/E bits
and PORTA
sta PORTA
bit PORTB ; Set N flag according to bit 7
bmi loop
lda #%11111111 ; Set all pins on port B to output
sta DDRB
rts
.endproc
.proc lcd_cmd
sta PORTB
jsr lcd_wait
lda #<~(RS | E | RW) ; Clear RS/RW/E bits
and PORTA
sta PORTA
lda #E ; Set E bit to send instruction
ora PORTA
sta PORTA
lda #<~(RS | E | RW) ; Clear RS/RW/E bits
and PORTA
sta PORTA
rts
.endproc
lcd_data:
.proc lcd_putc
sta PORTB
jsr lcd_wait
lda #<~(RS | E | RW) ; Clear RS/RW/E bits
and PORTA
sta PORTA
lda #(RS | E) ; Set RS and E bits to send data
ora PORTA
sta PORTA
lda #<~(RS | E | RW) ; Clear RS/RW/E bits
and PORTA
sta PORTA
rts
.endproc
.macro TO_ASCII
.local skip
clc
adc #$30
cmp #$3A
bcc skip
adc #6
skip:
.endmacro
.proc lcd_puthex
pha
lsr
lsr
lsr
lsr
TO_ASCII
jsr lcd_putc
pla
and #$f
TO_ASCII
jsr lcd_putc
rts
.endproc
.proc lcd_puts
sty r0
sta r0+1
ldy #0
loop:
lda (r0),y
beq done
jsr lcd_putc
iny
jmp loop
done:
rts
.endproc
.proc lcd_init
lda #%00111000 ; Set 8-bit mode; 2-line display; 5x8 font
jsr lcd_cmd
lda #%00000001 ; Clear display
jsr lcd_cmd
lda #%00001110 ; Display on; cursor on; blink off
jsr lcd_cmd
lda #%00000110 ; Increment and shift cursor; don't shift display
jmp lcd_cmd
.endproc
.proc lcd_home
lda #%00000010 ; Return home
jmp lcd_cmd
.endproc
.proc lcd_clear
lda #%00000001 ; Clear display
jmp lcd_cmd
.endproc
.proc lcd_loc
; a contains address
ora #%10000000 ; Set DDRAM address
jmp lcd_cmd
.endproc
.proc lcd_scroll
; a contains LCD_SCROLL_LEFT or LCD_SCROLL_RIGHT
ora #%0000011000
jmp lcd_cmd
.endproc
.proc lcd_chars
; a::y is pointer to character data
sta r0+1
lda #0
sta r0
lda #%01000000 ; Set CGRAM address 0
jsr lcd_cmd
loop:
lda (r0),y
bmi done
jsr lcd_data
iny
bne loop
inc r0+1
jmp loop
done:
; set DDRAM address for future writes
jmp lcd_home
.endproc