419 |
kaklik |
1 |
CCS PCM C Compiler, Version 3.245, 27853 16-XII-07 14:06
|
|
|
2 |
|
|
|
3 |
Filename: C:\windows\profiles\kaklik\My Documents\projekty\programy\C\PIC_C\test\C16F876A\LCD\main.lst
|
|
|
4 |
|
|
|
5 |
ROM used: 326 words (4%)
|
|
|
6 |
Largest free fragment is 2048
|
|
|
7 |
RAM used: 7 (4%) at main() level
|
|
|
8 |
15 (9%) worst case
|
|
|
9 |
Stack: 4 locations
|
|
|
10 |
|
|
|
11 |
*
|
|
|
12 |
0000: MOVLW 00
|
|
|
13 |
0001: MOVWF 0A
|
|
|
14 |
0002: GOTO 0FC
|
|
|
15 |
0003: NOP
|
|
|
16 |
.................... #include "main.h"
|
|
|
17 |
.................... #include <16F877.h>
|
|
|
18 |
.................... //////// Standard Header file for the PIC16F877 device ////////////////
|
|
|
19 |
.................... #device PIC16F877
|
|
|
20 |
.................... #list
|
|
|
21 |
....................
|
|
|
22 |
.................... #device adc=8
|
|
|
23 |
....................
|
|
|
24 |
.................... #FUSES NOWDT //No Watch Dog Timer
|
|
|
25 |
.................... #FUSES XT //Crystal osc <= 4mhz
|
|
|
26 |
.................... #FUSES NOPUT //No Power Up Timer
|
|
|
27 |
.................... #FUSES NOPROTECT //Code not protected from reading
|
|
|
28 |
.................... #FUSES NOBROWNOUT //No brownout reset
|
|
|
29 |
.................... #FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
|
|
|
30 |
.................... #FUSES NOCPD //No EE protection
|
|
|
31 |
.................... #FUSES NOWRT //Program memory not write protected
|
|
|
32 |
.................... #FUSES NODEBUG //No Debug mode for ICD
|
|
|
33 |
....................
|
|
|
34 |
.................... #use delay(clock=4000000)
|
|
|
35 |
0026: MOVLW 23
|
|
|
36 |
0027: MOVWF 04
|
|
|
37 |
0028: MOVF 00,W
|
|
|
38 |
0029: BTFSC 03.2
|
|
|
39 |
002A: GOTO 03A
|
|
|
40 |
002B: MOVLW 01
|
|
|
41 |
002C: MOVWF 78
|
|
|
42 |
002D: CLRF 77
|
|
|
43 |
002E: DECFSZ 77,F
|
|
|
44 |
002F: GOTO 02E
|
|
|
45 |
0030: DECFSZ 78,F
|
|
|
46 |
0031: GOTO 02D
|
|
|
47 |
0032: MOVLW 4A
|
|
|
48 |
0033: MOVWF 77
|
|
|
49 |
0034: DECFSZ 77,F
|
|
|
50 |
0035: GOTO 034
|
|
|
51 |
0036: NOP
|
|
|
52 |
0037: NOP
|
|
|
53 |
0038: DECFSZ 00,F
|
|
|
54 |
0039: GOTO 02B
|
|
|
55 |
003A: RETLW 00
|
|
|
56 |
....................
|
|
|
57 |
....................
|
|
|
58 |
....................
|
|
|
59 |
....................
|
|
|
60 |
.................... #define LCD_RS PIN_C7 // rizeni registru LCD displeje <lcd.c>
|
|
|
61 |
.................... #define LCD_E PIN_B7 // enable LCD displeje <lcd.c>
|
|
|
62 |
.................... #define LCD_D0 PIN_B3 // data LCD <lcd.c>
|
|
|
63 |
.................... #define LCD_D1 PIN_B2
|
|
|
64 |
.................... #define LCD_D2 PIN_B1
|
|
|
65 |
.................... #define LCD_D3 PIN_B0
|
|
|
66 |
....................
|
|
|
67 |
.................... #include "LCD.C"
|
|
|
68 |
.................... // LCD modul pro ovladani dvouradkoveho LCD modulu se standardnim Hitachi radicem
|
|
|
69 |
.................... // (c)miho 2002,2005
|
|
|
70 |
.................... //
|
|
|
71 |
.................... // Historie:
|
|
|
72 |
.................... //
|
|
|
73 |
.................... // 0.00 Uvodni verze se snadnou definici portu LCD displeje
|
|
|
74 |
.................... // 0.01 Oprava portu (zapomenute stare identifikatory)
|
|
|
75 |
.................... // 0.02 Doplnena moznost pripojeni datoveho portu LCD na libovolne porty
|
|
|
76 |
.................... // 0.03 Doplnena procedura lcd_clr pro smazani displeje
|
|
|
77 |
.................... //
|
|
|
78 |
.................... //
|
|
|
79 |
.................... // Funkce:
|
|
|
80 |
.................... //
|
|
|
81 |
.................... // lcd_init() inicializuje LCD displej a porty, nutno volat jako prvni
|
|
|
82 |
.................... //
|
|
|
83 |
.................... // lcd_putc(c) zapis snaku do lcd displeje, zpracovava nasledujici ridici znaky
|
|
|
84 |
.................... // \f = \x0C - nova stranka - smazani displeje
|
|
|
85 |
.................... // \n = \x0A - odradkovani (prechod na druhou radku)
|
|
|
86 |
.................... // \b = \x08 - backspace - posunuti kurzoru o 1 pozici zpet
|
|
|
87 |
.................... // \r = \x0D - goto home to position 1,1
|
|
|
88 |
.................... // \0 .. \7 - definovatelne znaky v pozicich 0 az 7 v CGRAM
|
|
|
89 |
.................... // \20 .. \27 - alternativne zapsane znaky (oktalove) v pozicich 0 az 7 CGRAM
|
|
|
90 |
.................... // Pozor na to, ze funkce printf konci tisk pokud narazi na \0 (konec retezce)
|
|
|
91 |
.................... //
|
|
|
92 |
.................... // lcd_gotoxy(x,y) presune kurzor na uvedenou adresu
|
|
|
93 |
.................... // nekontroluje parametry
|
|
|
94 |
.................... //
|
|
|
95 |
.................... // lcd_cursor_on zapne kurzor
|
|
|
96 |
.................... // lcd_cursor_off vypne kurzor
|
|
|
97 |
.................... //
|
|
|
98 |
.................... // lcd_clr smaze displej
|
|
|
99 |
.................... //
|
|
|
100 |
.................... // lcd_define_char(Index, Def) Makro, ktere definuje znaky od pozice Index obsahem definicniho
|
|
|
101 |
.................... // retezce Def. Kazdych 8 znaku retezce Def definuje dalsi znak v CGRAM.
|
|
|
102 |
.................... // Kapacita CGRAM je celkem 8 znaku s indexem 0 az 7.
|
|
|
103 |
.................... // Na konci se provede lcd_gotoxy(1,1).
|
|
|
104 |
.................... // Na konci teto knihovny je priklad pouziti definovanych znaku
|
|
|
105 |
.................... //
|
|
|
106 |
.................... //
|
|
|
107 |
.................... // Definice portu: // Datovy port displeje pripojeny na 4 bity za sebou na jeden port
|
|
|
108 |
.................... //
|
|
|
109 |
.................... // #define LCD_RS PIN_B2 // rizeni registru LCD displeje
|
|
|
110 |
.................... // #define LCD_E PIN_B1 // enable LCD displeje
|
|
|
111 |
.................... // #define LCD_DATA_LSB PIN_C2 // pripojeni LSB bitu datoveho portu LCD displeje (celkem 4 bity vzestupne za sebou)
|
|
|
112 |
.................... //
|
|
|
113 |
.................... //
|
|
|
114 |
.................... // Alternativni definice: // Datovy port displeje pripojeny na libovolne 4 bitove porty (vede na kod delsi asi o 25 slov)
|
|
|
115 |
.................... //
|
|
|
116 |
.................... // #define LCD_RS PIN_B2 // rizeni registru LCD displeje
|
|
|
117 |
.................... // #define LCD_E PIN_B1 // enable LCD displeje
|
|
|
118 |
.................... // #define LCD_D0 PIN_C2 // D0 - datove bity pripojene na libovolne porty
|
|
|
119 |
.................... // #define LCD_D1 PIN_C3 // D1
|
|
|
120 |
.................... // #define LCD_D2 PIN_C4 // D2
|
|
|
121 |
.................... // #define LCD_D3 PIN_C5 // D3
|
|
|
122 |
....................
|
|
|
123 |
....................
|
|
|
124 |
....................
|
|
|
125 |
....................
|
|
|
126 |
.................... // Privatni sekce, cist jen v pripade, ze neco nefunguje
|
|
|
127 |
....................
|
|
|
128 |
....................
|
|
|
129 |
....................
|
|
|
130 |
....................
|
|
|
131 |
.................... #ifdef LCD_DATA_LSB
|
|
|
132 |
.................... // Generovane defince portu pro ucely teto knihovny aby kod generoval spravne IO operace a soucasne
|
|
|
133 |
.................... // bylo mozne jednoduse deklarovat pripojene piny LCD displeje pri pouziti teto knihovny. Problem spociva
|
|
|
134 |
.................... // v tom, ze se musi spravne ridit smery portu a soucasne datovy port zabira jen 4 bity ze zadaneho portu
|
|
|
135 |
.................... //
|
|
|
136 |
.................... #define LCD_SHIFT (LCD_DATA_LSB&7) // pocet bitu posuvu datoveho kanalu v datovem portu
|
|
|
137 |
.................... #define LCD_PORT (LCD_DATA_LSB>>3) // adresa LCD datoveho portu
|
|
|
138 |
.................... #define LCD_TRIS (LCD_PORT+0x80) // adresa prislusneho TRIS registru
|
|
|
139 |
.................... #define LCD_MASK (0xF<<LCD_SHIFT) // maska platnych bitu
|
|
|
140 |
.................... //
|
|
|
141 |
.................... #if LCD_SHIFT>4 // kontrola mezi
|
|
|
142 |
.................... #error LCD data port LSB bit not in range 0..4
|
|
|
143 |
.................... #endif
|
|
|
144 |
.................... #endif
|
|
|
145 |
....................
|
|
|
146 |
....................
|
|
|
147 |
.................... // Definice konstant pro LCD display
|
|
|
148 |
.................... //
|
|
|
149 |
.................... #define LCD_CURSOR_ON_ 0x0E // kurzor jako blikajici radka pod znakem
|
|
|
150 |
.................... #define LCD_CURSOR_OFF_ 0x0C // zadny kurzor
|
|
|
151 |
.................... #define LCD_LINE_2 0x40 // adresa 1. znaku 2. radky
|
|
|
152 |
....................
|
|
|
153 |
....................
|
|
|
154 |
.................... // Definice rezimu LCD displeje
|
|
|
155 |
.................... //
|
|
|
156 |
.................... BYTE const LCD_INIT_STRING[4] =
|
|
|
157 |
.................... {
|
|
|
158 |
.................... 0x28, // intrfejs 4 bity, 2 radky, font 5x7
|
|
|
159 |
.................... LCD_CURSOR_OFF_, // display on, kurzor off,
|
|
|
160 |
.................... 0x01, // clear displeje
|
|
|
161 |
.................... 0x06 // inkrement pozice kurzoru (posun kurzoru doprava)
|
|
|
162 |
.................... };
|
|
|
163 |
....................
|
|
|
164 |
....................
|
|
|
165 |
.................... // Odesle nibble do displeje (posle data a klikne signalem e)
|
|
|
166 |
.................... //
|
|
|
167 |
.................... void lcd_send_nibble( BYTE n )
|
|
|
168 |
.................... {
|
|
|
169 |
.................... #ifdef LCD_DATA_LSB
|
|
|
170 |
.................... // data jsou za sebou na 4 bitech jednoho portu
|
|
|
171 |
.................... *LCD_PORT = (*LCD_PORT & ~LCD_MASK) | ((n << LCD_SHIFT) & LCD_MASK); // nastav datove bity portu a ostatni zachovej
|
|
|
172 |
.................... #else
|
|
|
173 |
.................... // data jsou na libovolnych 4 bitech libovolnych portu
|
|
|
174 |
.................... output_bit(LCD_D0,bit_test(n,0));
|
|
|
175 |
003B: BTFSC 29.0
|
|
|
176 |
003C: GOTO 03F
|
|
|
177 |
003D: BCF 06.3
|
|
|
178 |
003E: GOTO 040
|
|
|
179 |
003F: BSF 06.3
|
|
|
180 |
0040: BSF 03.5
|
|
|
181 |
0041: BCF 06.3
|
|
|
182 |
.................... output_bit(LCD_D1,bit_test(n,1));
|
|
|
183 |
0042: BCF 03.5
|
|
|
184 |
0043: BTFSC 29.1
|
|
|
185 |
0044: GOTO 047
|
|
|
186 |
0045: BCF 06.2
|
|
|
187 |
0046: GOTO 048
|
|
|
188 |
0047: BSF 06.2
|
|
|
189 |
0048: BSF 03.5
|
|
|
190 |
0049: BCF 06.2
|
|
|
191 |
.................... output_bit(LCD_D2,bit_test(n,2));
|
|
|
192 |
004A: BCF 03.5
|
|
|
193 |
004B: BTFSC 29.2
|
|
|
194 |
004C: GOTO 04F
|
|
|
195 |
004D: BCF 06.1
|
|
|
196 |
004E: GOTO 050
|
|
|
197 |
004F: BSF 06.1
|
|
|
198 |
0050: BSF 03.5
|
|
|
199 |
0051: BCF 06.1
|
|
|
200 |
.................... output_bit(LCD_D3,bit_test(n,3));
|
|
|
201 |
0052: BCF 03.5
|
|
|
202 |
0053: BTFSC 29.3
|
|
|
203 |
0054: GOTO 057
|
|
|
204 |
0055: BCF 06.0
|
|
|
205 |
0056: GOTO 058
|
|
|
206 |
0057: BSF 06.0
|
|
|
207 |
0058: BSF 03.5
|
|
|
208 |
0059: BCF 06.0
|
|
|
209 |
.................... #endif
|
|
|
210 |
.................... output_bit(LCD_E,1); // vzestupna hrana
|
|
|
211 |
005A: BCF 03.5
|
|
|
212 |
005B: BSF 06.7
|
|
|
213 |
005C: BSF 03.5
|
|
|
214 |
005D: BCF 06.7
|
|
|
215 |
.................... delay_us(1); // pockej alespon 450ns od e nebo alespon 195ns od dat
|
|
|
216 |
005E: NOP
|
|
|
217 |
.................... output_bit(LCD_E,0); // sestupna hrana (minimalni perioda e je 1us)
|
|
|
218 |
005F: BCF 03.5
|
|
|
219 |
0060: BCF 06.7
|
|
|
220 |
0061: BSF 03.5
|
|
|
221 |
0062: BCF 06.7
|
|
|
222 |
.................... }
|
|
|
223 |
0063: BCF 03.5
|
|
|
224 |
0064: RETLW 00
|
|
|
225 |
....................
|
|
|
226 |
....................
|
|
|
227 |
.................... // Odesle bajt do registru LCD
|
|
|
228 |
.................... //
|
|
|
229 |
.................... // Pokud je Adr=0 .. instrukcni registr
|
|
|
230 |
.................... // Pokud je Adr=1 .. datovy registr
|
|
|
231 |
.................... //
|
|
|
232 |
.................... void lcd_send_byte( BOOLEAN Adr, BYTE n )
|
|
|
233 |
.................... {
|
|
|
234 |
.................... output_bit(LCD_RS,Adr); // vyber registr
|
|
|
235 |
0065: MOVF 27,F
|
|
|
236 |
0066: BTFSS 03.2
|
|
|
237 |
0067: GOTO 06A
|
|
|
238 |
0068: BCF 07.7
|
|
|
239 |
0069: GOTO 06B
|
|
|
240 |
006A: BSF 07.7
|
|
|
241 |
006B: BCF 20.7
|
|
|
242 |
006C: MOVF 20,W
|
|
|
243 |
006D: BSF 03.5
|
|
|
244 |
006E: MOVWF 07
|
|
|
245 |
*
|
|
|
246 |
0104: MOVLW FF
|
|
|
247 |
0105: BCF 03.5
|
|
|
248 |
0106: MOVWF 20
|
|
|
249 |
.................... swap(n);
|
|
|
250 |
*
|
|
|
251 |
006F: BCF 03.5
|
|
|
252 |
0070: SWAPF 28,F
|
|
|
253 |
.................... lcd_send_nibble(n); // posli horni pulku bajtu
|
|
|
254 |
0071: MOVF 28,W
|
|
|
255 |
0072: MOVWF 29
|
|
|
256 |
0073: CALL 03B
|
|
|
257 |
.................... swap(n);
|
|
|
258 |
0074: SWAPF 28,F
|
|
|
259 |
.................... lcd_send_nibble(n); // posli spodni pulku bajtu
|
|
|
260 |
0075: MOVF 28,W
|
|
|
261 |
0076: MOVWF 29
|
|
|
262 |
0077: CALL 03B
|
|
|
263 |
.................... delay_us(40); // minimalni doba na provedeni prikazu
|
|
|
264 |
0078: MOVLW 0D
|
|
|
265 |
0079: MOVWF 77
|
|
|
266 |
007A: DECFSZ 77,F
|
|
|
267 |
007B: GOTO 07A
|
|
|
268 |
.................... }
|
|
|
269 |
007C: RETLW 00
|
|
|
270 |
....................
|
|
|
271 |
....................
|
|
|
272 |
.................... // Provede inicializaci LCD displeje, smaze obsah a nastavi mod displeje
|
|
|
273 |
.................... //
|
|
|
274 |
.................... // Tato procedura se musi volat pred pouzitim ostatnich lcd_ procedur
|
|
|
275 |
.................... //
|
|
|
276 |
.................... void lcd_init()
|
|
|
277 |
.................... {
|
|
|
278 |
....................
|
|
|
279 |
.................... int i; // pocitadlo cyklu
|
|
|
280 |
....................
|
|
|
281 |
.................... delay_ms(20); // spozdeni pro provedeni startu displeje po zapnuti napajeni
|
|
|
282 |
007D: MOVLW 14
|
|
|
283 |
007E: MOVWF 23
|
|
|
284 |
007F: CALL 026
|
|
|
285 |
....................
|
|
|
286 |
.................... #ifdef LCD_DATA_LSB
|
|
|
287 |
.................... // data jsou na 4 bitech za sebou, nastav smer pro vsechny dalsi prenosy
|
|
|
288 |
.................... *LCD_TRIS = *LCD_TRIS & ~LCD_MASK; // nuluj odpovidajici bity tris registru datoveho portu LCD
|
|
|
289 |
.................... #endif
|
|
|
290 |
....................
|
|
|
291 |
.................... output_bit(LCD_RS,0); // nastav jako vystup a nastav klidovy stav
|
|
|
292 |
0080: BCF 07.7
|
|
|
293 |
0081: BCF 20.7
|
|
|
294 |
0082: MOVF 20,W
|
|
|
295 |
0083: BSF 03.5
|
|
|
296 |
0084: MOVWF 07
|
|
|
297 |
.................... output_bit(LCD_E, 0); // nastav jako vystup a nastav klidovy stav
|
|
|
298 |
0085: BCF 03.5
|
|
|
299 |
0086: BCF 06.7
|
|
|
300 |
0087: BSF 03.5
|
|
|
301 |
0088: BCF 06.7
|
|
|
302 |
....................
|
|
|
303 |
.................... for (i=0; i<3; i++) // nastav lcd do rezimu 8 bitu sbernice
|
|
|
304 |
0089: BCF 03.5
|
|
|
305 |
008A: CLRF 21
|
|
|
306 |
008B: MOVF 21,W
|
|
|
307 |
008C: SUBLW 02
|
|
|
308 |
008D: BTFSS 03.0
|
|
|
309 |
008E: GOTO 097
|
|
|
310 |
.................... {
|
|
|
311 |
.................... delay_ms(2); // muze byt rozdelany prenos dat (2x 4 bity) nebo pomaly povel
|
|
|
312 |
008F: MOVLW 02
|
|
|
313 |
0090: MOVWF 23
|
|
|
314 |
0091: CALL 026
|
|
|
315 |
.................... lcd_send_nibble(3); // rezim 8 bitu
|
|
|
316 |
0092: MOVLW 03
|
|
|
317 |
0093: MOVWF 29
|
|
|
318 |
0094: CALL 03B
|
|
|
319 |
.................... }
|
|
|
320 |
0095: INCF 21,F
|
|
|
321 |
0096: GOTO 08B
|
|
|
322 |
....................
|
|
|
323 |
.................... delay_us(40); // cas na zpracovani
|
|
|
324 |
0097: MOVLW 0D
|
|
|
325 |
0098: MOVWF 77
|
|
|
326 |
0099: DECFSZ 77,F
|
|
|
327 |
009A: GOTO 099
|
|
|
328 |
.................... lcd_send_nibble(2); // nastav rezim 4 bitu (plati od nasledujiciho prenosu)
|
|
|
329 |
009B: MOVLW 02
|
|
|
330 |
009C: MOVWF 29
|
|
|
331 |
009D: CALL 03B
|
|
|
332 |
.................... delay_us(40); // cas na zpracovani
|
|
|
333 |
009E: MOVLW 0D
|
|
|
334 |
009F: MOVWF 77
|
|
|
335 |
00A0: DECFSZ 77,F
|
|
|
336 |
00A1: GOTO 0A0
|
|
|
337 |
....................
|
|
|
338 |
.................... for (i=0;i<3;i++) // proved inicializaci (nastaveni modu, smazani apod)
|
|
|
339 |
00A2: CLRF 21
|
|
|
340 |
00A3: MOVF 21,W
|
|
|
341 |
00A4: SUBLW 02
|
|
|
342 |
00A5: BTFSS 03.0
|
|
|
343 |
00A6: GOTO 0B3
|
|
|
344 |
.................... {
|
|
|
345 |
.................... lcd_send_byte(0,LCD_INIT_STRING[i]);
|
|
|
346 |
00A7: MOVF 21,W
|
|
|
347 |
00A8: CALL 004
|
|
|
348 |
00A9: MOVWF 22
|
|
|
349 |
00AA: CLRF 27
|
|
|
350 |
00AB: MOVF 22,W
|
|
|
351 |
00AC: MOVWF 28
|
|
|
352 |
00AD: CALL 065
|
|
|
353 |
.................... delay_ms(2);
|
|
|
354 |
00AE: MOVLW 02
|
|
|
355 |
00AF: MOVWF 23
|
|
|
356 |
00B0: CALL 026
|
|
|
357 |
.................... }
|
|
|
358 |
00B1: INCF 21,F
|
|
|
359 |
00B2: GOTO 0A3
|
|
|
360 |
.................... }
|
|
|
361 |
00B3: BCF 0A.3
|
|
|
362 |
00B4: BCF 0A.4
|
|
|
363 |
00B5: GOTO 133 (RETURN)
|
|
|
364 |
....................
|
|
|
365 |
....................
|
|
|
366 |
.................... // Proved presun kurzoru
|
|
|
367 |
.................... //
|
|
|
368 |
.................... // Pozice 1.1 je domu
|
|
|
369 |
.................... //
|
|
|
370 |
.................... void lcd_gotoxy( BYTE x, BYTE y)
|
|
|
371 |
.................... {
|
|
|
372 |
....................
|
|
|
373 |
.................... BYTE Adr;
|
|
|
374 |
....................
|
|
|
375 |
.................... Adr=x-1;
|
|
|
376 |
00B6: MOVLW 01
|
|
|
377 |
00B7: SUBWF 23,W
|
|
|
378 |
00B8: MOVWF 25
|
|
|
379 |
.................... if(y==2)
|
|
|
380 |
00B9: MOVF 24,W
|
|
|
381 |
00BA: SUBLW 02
|
|
|
382 |
00BB: BTFSS 03.2
|
|
|
383 |
00BC: GOTO 0BF
|
|
|
384 |
.................... Adr+=LCD_LINE_2;
|
|
|
385 |
00BD: MOVLW 40
|
|
|
386 |
00BE: ADDWF 25,F
|
|
|
387 |
....................
|
|
|
388 |
.................... lcd_send_byte(0,0x80|Adr);
|
|
|
389 |
00BF: MOVF 25,W
|
|
|
390 |
00C0: IORLW 80
|
|
|
391 |
00C1: MOVWF 26
|
|
|
392 |
00C2: CLRF 27
|
|
|
393 |
00C3: MOVF 26,W
|
|
|
394 |
00C4: MOVWF 28
|
|
|
395 |
00C5: CALL 065
|
|
|
396 |
.................... }
|
|
|
397 |
00C6: RETLW 00
|
|
|
398 |
....................
|
|
|
399 |
....................
|
|
|
400 |
.................... // Zapis znaku na displej, zpracovani ridicich znaku
|
|
|
401 |
.................... //
|
|
|
402 |
.................... void lcd_putc( char c)
|
|
|
403 |
.................... {
|
|
|
404 |
....................
|
|
|
405 |
.................... switch (c)
|
|
|
406 |
.................... {
|
|
|
407 |
00C7: MOVF 22,W
|
|
|
408 |
00C8: XORLW 0C
|
|
|
409 |
00C9: BTFSC 03.2
|
|
|
410 |
00CA: GOTO 0D5
|
|
|
411 |
00CB: XORLW 06
|
|
|
412 |
00CC: BTFSC 03.2
|
|
|
413 |
00CD: GOTO 0DD
|
|
|
414 |
00CE: XORLW 07
|
|
|
415 |
00CF: BTFSC 03.2
|
|
|
416 |
00D0: GOTO 0E3
|
|
|
417 |
00D1: XORLW 05
|
|
|
418 |
00D2: BTFSC 03.2
|
|
|
419 |
00D3: GOTO 0E8
|
|
|
420 |
00D4: GOTO 0ED
|
|
|
421 |
.................... case '\f' : lcd_send_byte(0,1); // smaz displej
|
|
|
422 |
00D5: CLRF 27
|
|
|
423 |
00D6: MOVLW 01
|
|
|
424 |
00D7: MOVWF 28
|
|
|
425 |
00D8: CALL 065
|
|
|
426 |
.................... delay_ms(2);
|
|
|
427 |
00D9: MOVLW 02
|
|
|
428 |
00DA: MOVWF 23
|
|
|
429 |
00DB: CALL 026
|
|
|
430 |
.................... break;
|
|
|
431 |
00DC: GOTO 0F9
|
|
|
432 |
.................... case '\n' : lcd_gotoxy(1,2); break; // presun se na 1. znak 2. radky
|
|
|
433 |
00DD: MOVLW 01
|
|
|
434 |
00DE: MOVWF 23
|
|
|
435 |
00DF: MOVLW 02
|
|
|
436 |
00E0: MOVWF 24
|
|
|
437 |
00E1: CALL 0B6
|
|
|
438 |
00E2: GOTO 0F9
|
|
|
439 |
.................... case '\r' : lcd_gotoxy(1,1); break; // presun home
|
|
|
440 |
00E3: MOVLW 01
|
|
|
441 |
00E4: MOVWF 23
|
|
|
442 |
00E5: MOVWF 24
|
|
|
443 |
00E6: CALL 0B6
|
|
|
444 |
00E7: GOTO 0F9
|
|
|
445 |
.................... case '\b' : lcd_send_byte(0,0x10); break; // posun kurzor o 1 zpet
|
|
|
446 |
00E8: CLRF 27
|
|
|
447 |
00E9: MOVLW 10
|
|
|
448 |
00EA: MOVWF 28
|
|
|
449 |
00EB: CALL 065
|
|
|
450 |
00EC: GOTO 0F9
|
|
|
451 |
.................... default : if (c<0x20) c&=0x7; // preklopeni definovatelnych znaku na rozsah 0 az 0x1F
|
|
|
452 |
00ED: MOVF 22,W
|
|
|
453 |
00EE: SUBLW 1F
|
|
|
454 |
00EF: BTFSS 03.0
|
|
|
455 |
00F0: GOTO 0F3
|
|
|
456 |
00F1: MOVLW 07
|
|
|
457 |
00F2: ANDWF 22,F
|
|
|
458 |
.................... lcd_send_byte(1,c); break; // zapis znak
|
|
|
459 |
00F3: MOVLW 01
|
|
|
460 |
00F4: MOVWF 27
|
|
|
461 |
00F5: MOVF 22,W
|
|
|
462 |
00F6: MOVWF 28
|
|
|
463 |
00F7: CALL 065
|
|
|
464 |
00F8: GOTO 0F9
|
|
|
465 |
.................... }
|
|
|
466 |
.................... }
|
|
|
467 |
00F9: BCF 0A.3
|
|
|
468 |
00FA: BCF 0A.4
|
|
|
469 |
00FB: GOTO 144 (RETURN)
|
|
|
470 |
....................
|
|
|
471 |
....................
|
|
|
472 |
.................... // Zapni kurzor
|
|
|
473 |
.................... //
|
|
|
474 |
.................... void lcd_cursor_on()
|
|
|
475 |
.................... {
|
|
|
476 |
.................... lcd_send_byte(0,LCD_CURSOR_ON_);
|
|
|
477 |
.................... }
|
|
|
478 |
....................
|
|
|
479 |
....................
|
|
|
480 |
.................... // Vypni kurzor
|
|
|
481 |
.................... //
|
|
|
482 |
.................... void lcd_cursor_off()
|
|
|
483 |
.................... {
|
|
|
484 |
.................... lcd_send_byte(0,LCD_CURSOR_OFF_);
|
|
|
485 |
.................... }
|
|
|
486 |
....................
|
|
|
487 |
....................
|
|
|
488 |
.................... // Smaz displej
|
|
|
489 |
.................... //
|
|
|
490 |
.................... void lcd_clr()
|
|
|
491 |
.................... {
|
|
|
492 |
.................... lcd_putc('\f');
|
|
|
493 |
.................... }
|
|
|
494 |
....................
|
|
|
495 |
....................
|
|
|
496 |
.................... // Definice vlastnich fontu
|
|
|
497 |
.................... //
|
|
|
498 |
.................... // Vlastnich definic muze byt jen 8 do pozic 0 az 7 pameti CGRAM radice lcd displeje
|
|
|
499 |
.................... // Pro snadne definovani jsou pripraveny nasledujici definice a na konci souboru je uveden
|
|
|
500 |
.................... // priklad pouziti definovanych znaku.
|
|
|
501 |
....................
|
|
|
502 |
....................
|
|
|
503 |
.................... // Pomocna procedura pro posilani ridicich dat do radice displeje
|
|
|
504 |
.................... //
|
|
|
505 |
.................... void lcd_putc2(int Data)
|
|
|
506 |
.................... {
|
|
|
507 |
.................... lcd_send_byte(1,Data);
|
|
|
508 |
.................... }
|
|
|
509 |
....................
|
|
|
510 |
....................
|
|
|
511 |
.................... // Pomocne definice pro programovani obsahu CGRAM
|
|
|
512 |
.................... //
|
|
|
513 |
.................... #define lcd_define_start(Code) lcd_send_byte(0,0x40+(Code<<3)); delay_ms(2)
|
|
|
514 |
.................... #define lcd_define_def(String) printf(lcd_putc2,String);
|
|
|
515 |
.................... #define lcd_define_end() lcd_send_byte(0,3); delay_ms(2)
|
|
|
516 |
....................
|
|
|
517 |
....................
|
|
|
518 |
.................... // Vlastni vykonne makro pro definovani fontu do pozice Index CGRAM s definicnim retezcem Def
|
|
|
519 |
.................... //
|
|
|
520 |
.................... #define lcd_define_char(Index, Def) lcd_define_start(Index); lcd_define_def(Def); lcd_define_end();
|
|
|
521 |
....................
|
|
|
522 |
....................
|
|
|
523 |
.................... // Pripravene definice fontu vybranych znaku
|
|
|
524 |
.................... // V tabulce nesmi byt 00 (konec retezce v printf()), misto toho davame 80
|
|
|
525 |
.................... //
|
|
|
526 |
.................... #define LCD_CHAR_BAT100 "\x0E\x1F\x1F\x1F\x1F\x1F\x1F\x1F" /* symbol plne baterie */
|
|
|
527 |
.................... #define LCD_CHAR_BAT50 "\x0E\x1F\x11\x11\x13\x17\x1F\x1F" /* symbol polovicni baterie */
|
|
|
528 |
.................... #define LCD_CHAR_BAT0 "\x0E\x1F\x11\x11\x11\x11\x11\x1F" /* symbol vybite baterie */
|
|
|
529 |
.................... #define LCD_CHAR_UP "\x80\x04\x0E\x15\x04\x04\x04\x80" /* symbol sipka nahoru */
|
|
|
530 |
.................... #define LCD_CHAR_DOWN "\x80\x04\x04\x04\x15\x0E\x04\x80" /* symbol Sipka dolu */
|
|
|
531 |
.................... #define LCD_CHAR_LUA "\x04\x0E\x11\x11\x1F\x11\x11\x80" /* A s carkou */
|
|
|
532 |
.................... #define LCD_CHAR_LLA "\x01\x02\x0E\x01\x1F\x11\x0F\x80" /* a s carkou */
|
|
|
533 |
.................... #define LCD_CHAR_HUC "\x0A\x0E\x11\x10\x10\x11\x0E\x80" /* C s hackem */
|
|
|
534 |
.................... #define LCD_CHAR_HLC "\x0A\x04\x0E\x10\x10\x11\x0E\x80" /* c s hackem */
|
|
|
535 |
.................... #define LCD_CHAR_HUD "\x0A\x1C\x12\x11\x11\x12\x1C\x80" /* D s hackem */
|
|
|
536 |
.................... #define LCD_CHAR_HLD "\x05\x03\x0D\x13\x11\x11\x0F\x80" /* d s hackem */
|
|
|
537 |
.................... #define LCD_CHAR_LUE "\x04\x1F\x10\x10\x1E\x10\x1F\x80" /* E s carkou */
|
|
|
538 |
.................... #define LCD_CHAR_LLE "\x01\x02\x0E\x11\x1F\x10\x0E\x80" /* e s carkou */
|
|
|
539 |
.................... #define LCD_CHAR_HUE "\x0A\x1F\x10\x1E\x10\x10\x1F\x80" /* E s hackem */
|
|
|
540 |
.................... #define LCD_CHAR_HLE "\x0A\x04\x0E\x11\x1F\x10\x0E\x80" /* e s hackem */
|
|
|
541 |
.................... #define LCD_CHAR_LUI "\x04\x0E\x04\x04\x04\x04\x0E\x80" /* I s carkou */
|
|
|
542 |
.................... #define LCD_CHAR_LLI "\x02\x04\x80\x0C\x04\x04\x0E\x80" /* i s carkou */
|
|
|
543 |
.................... #define LCD_CHAR_HUN "\x0A\x15\x11\x19\x15\x13\x11\x80" /* N s hackem */
|
|
|
544 |
.................... #define LCD_CHAR_HLN "\x0A\x04\x16\x19\x11\x11\x11\x80" /* n s hackem */
|
|
|
545 |
.................... #define LCD_CHAR_LUO "\x04\x0E\x11\x11\x11\x11\x0E\x80" /* O s carkou */
|
|
|
546 |
.................... #define LCD_CHAR_LLO "\x02\x04\x0E\x11\x11\x11\x0E\x80" /* o s carkou */
|
|
|
547 |
.................... #define LCD_CHAR_HUR "\x0A\x1E\x11\x1E\x14\x12\x11\x80" /* R s hackem */
|
|
|
548 |
.................... #define LCD_CHAR_HLR "\x0A\x04\x16\x19\x10\x10\x10\x80" /* r s hackem */
|
|
|
549 |
.................... #define LCD_CHAR_HUS "\x0A\x0F\x10\x0E\x01\x01\x1E\x80" /* S s hackem */
|
|
|
550 |
.................... #define LCD_CHAR_HLS "\x0A\x04\x0E\x10\x0E\x01\x1E\x80" /* s s hackem */
|
|
|
551 |
.................... #define LCD_CHAR_HUT "\x0A\x1F\x04\x04\x04\x04\x04\x80" /* T s hackem */
|
|
|
552 |
.................... #define LCD_CHAR_HLT "\x0A\x0C\x1C\x08\x08\x09\x06\x80" /* t s hackem */
|
|
|
553 |
.................... #define LCD_CHAR_LUU "\x02\x15\x11\x11\x11\x11\x0E\x80" /* U s carkou */
|
|
|
554 |
.................... #define LCD_CHAR_LLU "\x02\x04\x11\x11\x11\x13\x0D\x80" /* u s carkou */
|
|
|
555 |
.................... #define LCD_CHAR_CUU "\x06\x17\x11\x11\x11\x11\x0E\x80" /* U s krouzkem */
|
|
|
556 |
.................... #define LCD_CHAR_CLU "\x06\x06\x11\x11\x11\x11\x0E\x80" /* u s krouzkem */
|
|
|
557 |
.................... #define LCD_CHAR_LUY "\x02\x15\x11\x0A\x04\x04\x04\x80" /* Y s carkou */
|
|
|
558 |
.................... #define LCD_CHAR_LLY "\x02\x04\x11\x11\x0F\x01\x0E\x80" /* y s carkou */
|
|
|
559 |
.................... #define LCD_CHAR_HUZ "\x0A\x1F\x01\x02\x04\x08\x1F\x80" /* Z s hackem */
|
|
|
560 |
.................... #define LCD_CHAR_HLZ "\x0A\x04\x1F\x02\x04\x08\x1F\x80" /* z s hackem */
|
|
|
561 |
....................
|
|
|
562 |
....................
|
|
|
563 |
.................... // Priklad pouziti definovanych znaku
|
|
|
564 |
.................... //
|
|
|
565 |
.................... //
|
|
|
566 |
.................... //void lcd_sample()
|
|
|
567 |
.................... //{
|
|
|
568 |
.................... // lcd_define_char(0,LCD_CHAR_BAT50); // Priklad definice znaku baterie do pozice 0
|
|
|
569 |
.................... // lcd_define_char(2,LCD_CHAR_HLE LCD_CHAR_LUI); // Priklad definice znaku e s hackem a I s carkou od pozice 2
|
|
|
570 |
.................... // // vsimnete si, ze neni carka mezi retezci s definici (oba retezce definuji
|
|
|
571 |
.................... // // jediny definicni retezec)
|
|
|
572 |
.................... // printf(lcd_putc,"\fZnaky:\20\22\23"); // priklad vypisu znaku z pozice 0, 2 a 3
|
|
|
573 |
.................... // delay_ms(1000);
|
|
|
574 |
.................... // lcd_define_char(0,LCD_CHAR_BAT0); // Predefinovani tvaru znaku v pozici 0
|
|
|
575 |
.................... // delay_ms(1000);
|
|
|
576 |
.................... //}
|
|
|
577 |
....................
|
|
|
578 |
....................
|
|
|
579 |
.................... void main()
|
|
|
580 |
.................... {
|
|
|
581 |
00FC: CLRF 04
|
|
|
582 |
00FD: MOVLW 1F
|
|
|
583 |
00FE: ANDWF 03,F
|
|
|
584 |
00FF: BSF 03.5
|
|
|
585 |
0100: BSF 1F.0
|
|
|
586 |
0101: BSF 1F.1
|
|
|
587 |
0102: BSF 1F.2
|
|
|
588 |
0103: BCF 1F.3
|
|
|
589 |
....................
|
|
|
590 |
.................... setup_adc_ports(NO_ANALOGS);
|
|
|
591 |
*
|
|
|
592 |
0107: BSF 03.5
|
|
|
593 |
0108: BSF 1F.0
|
|
|
594 |
0109: BSF 1F.1
|
|
|
595 |
010A: BSF 1F.2
|
|
|
596 |
010B: BCF 1F.3
|
|
|
597 |
.................... setup_adc(ADC_OFF);
|
|
|
598 |
010C: BCF 03.5
|
|
|
599 |
010D: BCF 1F.0
|
|
|
600 |
.................... setup_psp(PSP_DISABLED);
|
|
|
601 |
010E: BSF 03.5
|
|
|
602 |
010F: BCF 09.4
|
|
|
603 |
.................... setup_spi(FALSE);
|
|
|
604 |
0110: BCF 03.5
|
|
|
605 |
0111: BCF 14.5
|
|
|
606 |
0112: BCF 20.5
|
|
|
607 |
0113: MOVF 20,W
|
|
|
608 |
0114: BSF 03.5
|
|
|
609 |
0115: MOVWF 07
|
|
|
610 |
0116: BCF 03.5
|
|
|
611 |
0117: BSF 20.4
|
|
|
612 |
0118: MOVF 20,W
|
|
|
613 |
0119: BSF 03.5
|
|
|
614 |
011A: MOVWF 07
|
|
|
615 |
011B: BCF 03.5
|
|
|
616 |
011C: BCF 20.3
|
|
|
617 |
011D: MOVF 20,W
|
|
|
618 |
011E: BSF 03.5
|
|
|
619 |
011F: MOVWF 07
|
|
|
620 |
0120: MOVLW 00
|
|
|
621 |
0121: BCF 03.5
|
|
|
622 |
0122: MOVWF 14
|
|
|
623 |
0123: BSF 03.5
|
|
|
624 |
0124: MOVWF 14
|
|
|
625 |
.................... setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
|
|
|
626 |
0125: MOVF 01,W
|
|
|
627 |
0126: ANDLW C7
|
|
|
628 |
0127: IORLW 08
|
|
|
629 |
0128: MOVWF 01
|
|
|
630 |
.................... setup_timer_1(T1_DISABLED);
|
|
|
631 |
0129: BCF 03.5
|
|
|
632 |
012A: CLRF 10
|
|
|
633 |
.................... setup_timer_2(T2_DISABLED,0,1);
|
|
|
634 |
012B: MOVLW 00
|
|
|
635 |
012C: MOVWF 78
|
|
|
636 |
012D: MOVWF 12
|
|
|
637 |
012E: MOVLW 00
|
|
|
638 |
012F: BSF 03.5
|
|
|
639 |
0130: MOVWF 12
|
|
|
640 |
....................
|
|
|
641 |
.................... lcd_init();
|
|
|
642 |
0131: BCF 03.5
|
|
|
643 |
0132: GOTO 07D
|
|
|
644 |
....................
|
|
|
645 |
.................... while(true);
|
|
|
646 |
0133: GOTO 133
|
|
|
647 |
.................... {
|
|
|
648 |
.................... Delay_ms(100);
|
|
|
649 |
0134: MOVLW 64
|
|
|
650 |
0135: MOVWF 23
|
|
|
651 |
0136: CALL 026
|
|
|
652 |
....................
|
|
|
653 |
.................... LCD_gotoxy(1,1);
|
|
|
654 |
0137: MOVLW 01
|
|
|
655 |
0138: MOVWF 23
|
|
|
656 |
0139: MOVWF 24
|
|
|
657 |
013A: CALL 0B6
|
|
|
658 |
.................... printf(lcd_putc,"Ahoj, Display funguje");
|
|
|
659 |
013B: CLRF 21
|
|
|
660 |
013C: MOVF 21,W
|
|
|
661 |
013D: CALL 00C
|
|
|
662 |
013E: IORLW 00
|
|
|
663 |
013F: BTFSC 03.2
|
|
|
664 |
0140: GOTO 145
|
|
|
665 |
0141: INCF 21,F
|
|
|
666 |
0142: MOVWF 22
|
|
|
667 |
0143: GOTO 0C7
|
|
|
668 |
0144: GOTO 13C
|
|
|
669 |
.................... }
|
|
|
670 |
....................
|
|
|
671 |
.................... }
|
|
|
672 |
0145: SLEEP
|
|
|
673 |
|
|
|
674 |
Configuration Fuses:
|
|
|
675 |
Word 1: 3F39 XT NOWDT NOPUT NOPROTECT NOBROWNOUT NOLVP NOCPD NOWRT NODEBUG
|