-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlcd.asm
More file actions
201 lines (195 loc) · 6.2 KB
/
lcd.asm
File metadata and controls
201 lines (195 loc) · 6.2 KB
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
; ##############################################################################
;
; Project: ICECARINT V1.0
; File Name: lcd.asm
; Processor: PIC16F914
; Frequency: 8 MHz
;
; ##############################################################################
;
; Display Message to LCD 8x2
; LCD Data: PORTB
; LCD RS: PORTE0
; LCD RW: PORTE1
; LCD E: PORTE2
;
; ##############################################################################
#include p16f914.inc
#include lcd.inc
; ------------------------------------------------------------------------------
; LCD module
; ------------------------------------------------------------------------------
lcd code
; ------------------------------------------------------------------------------
; Config lcd
; ------------------------------------------------------------------------------
lcd_conf
bcf STATUS,RP0
bcf STATUS,RP1
; Configure pins direction
bsf STATUS,RP0
movlw H'18'
andwf TRISE,F
clrf TRISB
; Disable analog input pins
movlw H'1F'
andwf ANSEL,F
; Config Timer0 and disable pull-ups on port b
movlw H'C2'
movwf OPTION_REG
bcf STATUS,RP0
return
; ------------------------------------------------------------------------------
; Prepare lcd
; ------------------------------------------------------------------------------
lcd_prepare
bcf STATUS,RP0
bcf STATUS,RP1
; Clear Display
movlw H'01'
call lcd_ctrl
; Function Set
movlw H'38'
call lcd_ctrl
; Return Home
movlw H'02'
call lcd_ctrl
; Display ON
movlw H'0E'
call lcd_ctrl
; Entry Display Set
movlw H'06'
call lcd_ctrl
; Cursor Shift
; movlw H'1C'
; call lcd_ctrl
return
; ------------------------------------------------------------------------------
; Write message row1
; ------------------------------------------------------------------------------
lcd_write_msg1
bcf STATUS,RP0
bcf STATUS,RP1
; Goto row1
call lcd_to_row1
movf LCDDAT0,W
call lcd_char
movf LCDDAT1,W
call lcd_char
movf LCDDAT2,W
call lcd_char
movf LCDDAT3,W
call lcd_char
movf LCDDAT4,W
call lcd_char
movf LCDDAT5,W
call lcd_char
movf LCDDAT6,W
call lcd_char
movf LCDDAT7,W
call lcd_char
return
; ------------------------------------------------------------------------------
; Write message row2
; ------------------------------------------------------------------------------
lcd_write_msg2
bcf STATUS,RP0
bcf STATUS,RP1
; Goto row2
call lcd_to_row2
movf LCDDAT8,W
call lcd_char
movf LCDDAT9,W
call lcd_char
movf LCDDATA,W
call lcd_char
movf LCDDATB,W
call lcd_char
movf LCDDATC,W
call lcd_char
movf LCDDATD,W
call lcd_char
movf LCDDATE,W
call lcd_char
movf LCDDATF,W
call lcd_char
return
; ------------------------------------------------------------------------------
; Go to lcd row1
; ------------------------------------------------------------------------------
lcd_to_row1
movlw H'02'
call lcd_ctrl
return
; ------------------------------------------------------------------------------
; Go to lcd row2
; ------------------------------------------------------------------------------
lcd_to_row2
movlw H'C0'
call lcd_ctrl
return
; ------------------------------------------------------------------------------
; Control command lcd
; ------------------------------------------------------------------------------
lcd_ctrl
movwf PORTB
bcf PORTE,RE0
bcf PORTE,RE1
bsf PORTE,RE2
nop
bcf PORTE,RE2
call delay_1ms
call delay_1ms
return
; ------------------------------------------------------------------------------
; Character command lcd
; ------------------------------------------------------------------------------
lcd_char
movwf PORTB
bsf PORTE,RE0
bcf PORTE,RE1
bsf PORTE,RE2
nop
bcf PORTE,RE2
call wait_lcd_bf
return
; ------------------------------------------------------------------------------
; 1ms delay
; ------------------------------------------------------------------------------
delay_1ms
movlw H'06'
movwf TMR0
bcf INTCON,T0IF
wait_1ms
btfss INTCON,T0IF
goto wait_1ms
return
; ------------------------------------------------------------------------------
; Wait lcds busy flag
; ------------------------------------------------------------------------------
wait_lcd_bf
bsf STATUS,RP0
movlw H'FF'
movwf TRISB
bcf STATUS,RP0
bcf PORTE,0
bsf PORTE,1
wait_bf
bsf PORTE,2
nop
bcf PORTE,2
btfsc PORTB,7
goto wait_bf
bsf STATUS,RP0
clrf TRISB
bcf STATUS,RP0
return
; ------------------------------------------------------------------------------
; Variables declaration
; ------------------------------------------------------------------------------
global lcd_conf
global lcd_prepare
global lcd_write_msg1
global lcd_write_msg2
; ------------------------------------------------------------------------------
end