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