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