0,0 → 1,829 |
CCS PCM C Compiler, Version 3.221, 27853 26-XII-05 16:54 |
|
Filename: D:\KAKLIK\programy\PIC_C\mereni\mys\PIC16F88\mys.LST |
|
ROM used: 566 words (14%) |
Largest free fragment is 2048 |
RAM used: 13 (7%) at main() level |
30 (17%) worst case |
Stack: 5 locations |
|
* |
0000: MOVLW 00 |
0001: MOVWF 0A |
0002: GOTO 186 |
0003: NOP |
.................... #include "D:\KAKLIK\programy\PIC_C\mereni\mys\PIC16F88\mys.h" |
.................... #include <16F88.h> |
.................... //////// Standard Header file for the PIC16F88 device //////////////// |
.................... #device PIC16F88 |
.................... #list |
.................... |
.................... #device adc=8 |
.................... #fuses NOWDT,INTRC, NOPUT, MCLR, BROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG, NOPROTECT, FCMEN, IESO |
.................... #use delay(clock=4000000) |
* |
0028: MOVLW 31 |
0029: MOVWF 04 |
002A: MOVF 00,W |
002B: BTFSC 03.2 |
002C: GOTO 03C |
002D: MOVLW 01 |
002E: MOVWF 78 |
002F: CLRF 77 |
0030: DECFSZ 77,F |
0031: GOTO 030 |
0032: DECFSZ 78,F |
0033: GOTO 02F |
0034: MOVLW 4A |
0035: MOVWF 77 |
0036: DECFSZ 77,F |
0037: GOTO 036 |
0038: NOP |
0039: NOP |
003A: DECFSZ 00,F |
003B: GOTO 02D |
003C: RETLW 00 |
.................... |
.................... |
.................... |
.................... #define LCD_RS PIN_B3 // rizeni registru LCD displeje |
.................... #define LCD_E PIN_B0 // enable LCD displeje |
.................... #define LCD_DATA_LSB PIN_A0 // pripojeni LSB bitu datoveho portu LCD displeje (celkem 4 bity vzestupne za sebou) |
.................... #include "C:\library\CCS\lcd.c" |
.................... // LCD modul pro ovladani dvouradkoveho LCD modulu se standardnim Hitachi radicem |
.................... // (c)miho 2002,2005 |
.................... // |
.................... // Historie: |
.................... // |
.................... // 0.00 Uvodni verze se snadnou definici portu LCD displeje |
.................... // 0.01 Oprava portu (zapomenute stare identifikatory) |
.................... // 0.02 Doplnena moznost pripojeni datoveho portu LCD na libovolne porty |
.................... // 0.03 Doplnena procedura lcd_clr pro smazani displeje |
.................... // |
.................... // |
.................... // Funkce: |
.................... // |
.................... // lcd_init() inicializuje LCD displej a porty, nutno volat jako prvni |
.................... // |
.................... // lcd_putc(c) zapis snaku do lcd displeje, zpracovava nasledujici ridici znaky |
.................... // \f = \x0C - nova stranka - smazani displeje |
.................... // \n = \x0A - odradkovani (prechod na druhou radku) |
.................... // \b = \x08 - backspace - posunuti kurzoru o 1 pozici zpet |
.................... // \r = \x0D - goto home to position 1,1 |
.................... // \0 .. \7 - definovatelne znaky v pozicich 0 az 7 v CGRAM |
.................... // \20 .. \27 - alternativne zapsane znaky (oktalove) v pozicich 0 az 7 CGRAM |
.................... // Pozor na to, ze funkce printf konci tisk pokud narazi na \0 (konec retezce) |
.................... // |
.................... // lcd_gotoxy(x,y) presune kurzor na uvedenou adresu |
.................... // nekontroluje parametry |
.................... // |
.................... // lcd_cursor_on zapne kurzor |
.................... // lcd_cursor_off vypne kurzor |
.................... // |
.................... // lcd_clr smaze displej |
.................... // |
.................... // lcd_define_char(Index, Def) Makro, ktere definuje znaky od pozice Index obsahem definicniho |
.................... // retezce Def. Kazdych 8 znaku retezce Def definuje dalsi znak v CGRAM. |
.................... // Kapacita CGRAM je celkem 8 znaku s indexem 0 az 7. |
.................... // Na konci se provede lcd_gotoxy(1,1). |
.................... // Na konci teto knihovny je priklad pouziti definovanych znaku |
.................... // |
.................... // |
.................... // Definice portu: // Datovy port displeje pripojeny na 4 bity za sebou na jeden port |
.................... // |
.................... // #define LCD_RS PIN_B2 // rizeni registru LCD displeje |
.................... // #define LCD_E PIN_B1 // enable LCD displeje |
.................... // #define LCD_DATA_LSB PIN_C2 // pripojeni LSB bitu datoveho portu LCD displeje (celkem 4 bity vzestupne za sebou) |
.................... // |
.................... // |
.................... // Alternativni definice: // Datovy port displeje pripojeny na libovolne 4 bitove porty (vede na kod delsi asi o 25 slov) |
.................... // |
.................... // #define LCD_RS PIN_B2 // rizeni registru LCD displeje |
.................... // #define LCD_E PIN_B1 // enable LCD displeje |
.................... // #define LCD_D0 PIN_C2 // D0 - datove bity pripojene na libovolne porty |
.................... // #define LCD_D1 PIN_C3 // D1 |
.................... // #define LCD_D2 PIN_C4 // D2 |
.................... // #define LCD_D3 PIN_C5 // D3 |
.................... |
.................... |
.................... |
.................... |
.................... // Privatni sekce, cist jen v pripade, ze neco nefunguje |
.................... |
.................... |
.................... |
.................... |
.................... #ifdef LCD_DATA_LSB |
.................... // Generovane defince portu pro ucely teto knihovny aby kod generoval spravne IO operace a soucasne |
.................... // bylo mozne jednoduse deklarovat pripojene piny LCD displeje pri pouziti teto knihovny. Problem spociva |
.................... // v tom, ze se musi spravne ridit smery portu a soucasne datovy port zabira jen 4 bity ze zadaneho portu |
.................... // |
.................... #define LCD_SHIFT (LCD_DATA_LSB&7) // pocet bitu posuvu datoveho kanalu v datovem portu |
.................... #define LCD_PORT (LCD_DATA_LSB>>3) // adresa LCD datoveho portu |
.................... #define LCD_TRIS (LCD_PORT+0x80) // adresa prislusneho TRIS registru |
.................... #define LCD_MASK (0xF<<LCD_SHIFT) // maska platnych bitu |
.................... // |
.................... #if LCD_SHIFT>4 // kontrola mezi |
.................... #error LCD data port LSB bit not in range 0..4 |
.................... #endif |
.................... #endif |
.................... |
.................... |
.................... // Definice konstant pro LCD display |
.................... // |
.................... #define LCD_CURSOR_ON_ 0x0E // kurzor jako blikajici radka pod znakem |
.................... #define LCD_CURSOR_OFF_ 0x0C // zadny kurzor |
.................... #define LCD_LINE_2 0x40 // adresa 1. znaku 2. radky |
.................... |
.................... |
.................... // Definice rezimu LCD displeje |
.................... // |
.................... BYTE const LCD_INIT_STRING[4] = |
.................... { |
.................... 0x28, // intrfejs 4 bity, 2 radky, font 5x7 |
.................... LCD_CURSOR_OFF_, // display on, kurzor off, |
.................... 0x01, // clear displeje |
.................... 0x06 // inkrement pozice kurzoru (posun kurzoru doprava) |
.................... }; |
.................... |
.................... |
.................... // Odesle nibble do displeje (posle data a klikne signalem e) |
.................... // |
.................... void lcd_send_nibble( BYTE n ) |
.................... { |
.................... #ifdef LCD_DATA_LSB |
.................... // data jsou za sebou na 4 bitech jednoho portu |
.................... *LCD_PORT = (*LCD_PORT & ~LCD_MASK) | ((n << LCD_SHIFT) & LCD_MASK); // nastav datove bity portu a ostatni zachovej |
003D: MOVF 05,W |
003E: ANDLW F0 |
003F: MOVWF 38 |
0040: MOVF 37,W |
0041: ANDLW 0F |
0042: IORWF 38,W |
0043: MOVWF 05 |
.................... #else |
.................... // data jsou na libovolnych 4 bitech libovolnych portu |
.................... output_bit(LCD_D0,bit_test(n,0)); |
.................... output_bit(LCD_D1,bit_test(n,1)); |
.................... output_bit(LCD_D2,bit_test(n,2)); |
.................... output_bit(LCD_D3,bit_test(n,3)); |
.................... #endif |
.................... output_bit(LCD_E,1); // vzestupna hrana |
0044: BSF 06.0 |
0045: BSF 03.5 |
0046: BCF 06.0 |
.................... delay_us(1); // pockej alespon 450ns od e nebo alespon 195ns od dat |
0047: NOP |
.................... output_bit(LCD_E,0); // sestupna hrana (minimalni perioda e je 1us) |
0048: BCF 03.5 |
0049: BCF 06.0 |
004A: BSF 03.5 |
004B: BCF 06.0 |
.................... } |
004C: BCF 03.5 |
004D: RETLW 00 |
.................... |
.................... |
.................... // Odesle bajt do registru LCD |
.................... // |
.................... // Pokud je Adr=0 .. instrukcni registr |
.................... // Pokud je Adr=1 .. datovy registr |
.................... // |
.................... void lcd_send_byte( BOOLEAN Adr, BYTE n ) |
.................... { |
.................... output_bit(LCD_RS,Adr); // vyber registr |
004E: MOVF 35,F |
004F: BTFSS 03.2 |
0050: GOTO 053 |
0051: BCF 06.3 |
0052: GOTO 054 |
0053: BSF 06.3 |
0054: BSF 03.5 |
0055: BCF 06.3 |
.................... swap(n); |
0056: BCF 03.5 |
0057: SWAPF 36,F |
.................... lcd_send_nibble(n); // posli horni pulku bajtu |
0058: MOVF 36,W |
0059: MOVWF 37 |
005A: CALL 03D |
.................... swap(n); |
005B: SWAPF 36,F |
.................... lcd_send_nibble(n); // posli spodni pulku bajtu |
005C: MOVF 36,W |
005D: MOVWF 37 |
005E: CALL 03D |
.................... delay_us(40); // minimalni doba na provedeni prikazu |
005F: MOVLW 0D |
0060: MOVWF 77 |
0061: DECFSZ 77,F |
0062: GOTO 061 |
.................... } |
0063: RETLW 00 |
.................... |
.................... |
.................... // Provede inicializaci LCD displeje, smaze obsah a nastavi mod displeje |
.................... // |
.................... // Tato procedura se musi volat pred pouzitim ostatnich lcd_ procedur |
.................... // |
.................... void lcd_init() |
.................... { |
.................... |
.................... int i; // pocitadlo cyklu |
.................... |
.................... delay_ms(20); // spozdeni pro provedeni startu displeje po zapnuti napajeni |
0064: MOVLW 14 |
0065: MOVWF 31 |
0066: CALL 028 |
.................... |
.................... #ifdef LCD_DATA_LSB |
.................... // data jsou na 4 bitech za sebou, nastav smer pro vsechny dalsi prenosy |
.................... *LCD_TRIS = *LCD_TRIS & ~LCD_MASK; // nuluj odpovidajici bity tris registru datoveho portu LCD |
0067: MOVLW F0 |
0068: BSF 03.5 |
0069: ANDWF 05,F |
.................... #endif |
.................... |
.................... output_bit(LCD_RS,0); // nastav jako vystup a nastav klidovy stav |
006A: BCF 03.5 |
006B: BCF 06.3 |
006C: BSF 03.5 |
006D: BCF 06.3 |
.................... output_bit(LCD_E, 0); // nastav jako vystup a nastav klidovy stav |
006E: BCF 03.5 |
006F: BCF 06.0 |
0070: BSF 03.5 |
0071: BCF 06.0 |
.................... |
.................... for (i=0; i<3; i++) // nastav lcd do rezimu 8 bitu sbernice |
0072: BCF 03.5 |
0073: CLRF 28 |
0074: MOVF 28,W |
0075: SUBLW 02 |
0076: BTFSS 03.0 |
0077: GOTO 080 |
.................... { |
.................... delay_ms(2); // muze byt rozdelany prenos dat (2x 4 bity) nebo pomaly povel |
0078: MOVLW 02 |
0079: MOVWF 31 |
007A: CALL 028 |
.................... lcd_send_nibble(3); // rezim 8 bitu |
007B: MOVLW 03 |
007C: MOVWF 37 |
007D: CALL 03D |
.................... } |
007E: INCF 28,F |
007F: GOTO 074 |
.................... |
.................... delay_us(40); // cas na zpracovani |
0080: MOVLW 0D |
0081: MOVWF 77 |
0082: DECFSZ 77,F |
0083: GOTO 082 |
.................... lcd_send_nibble(2); // nastav rezim 4 bitu (plati od nasledujiciho prenosu) |
0084: MOVLW 02 |
0085: MOVWF 37 |
0086: CALL 03D |
.................... delay_us(40); // cas na zpracovani |
0087: MOVLW 0D |
0088: MOVWF 77 |
0089: DECFSZ 77,F |
008A: GOTO 089 |
.................... |
.................... for (i=0;i<3;i++) // proved inicializaci (nastaveni modu, smazani apod) |
008B: CLRF 28 |
008C: MOVF 28,W |
008D: SUBLW 02 |
008E: BTFSS 03.0 |
008F: GOTO 09C |
.................... { |
.................... lcd_send_byte(0,LCD_INIT_STRING[i]); |
0090: MOVF 28,W |
0091: CALL 004 |
0092: MOVWF 29 |
0093: CLRF 35 |
0094: MOVF 29,W |
0095: MOVWF 36 |
0096: CALL 04E |
.................... delay_ms(2); |
0097: MOVLW 02 |
0098: MOVWF 31 |
0099: CALL 028 |
.................... } |
009A: INCF 28,F |
009B: GOTO 08C |
.................... } |
009C: BCF 0A.3 |
009D: GOTO 1D4 (RETURN) |
.................... |
.................... |
.................... // Proved presun kurzoru |
.................... // |
.................... // Pozice 1.1 je domu |
.................... // |
.................... void lcd_gotoxy( BYTE x, BYTE y) |
.................... { |
.................... |
.................... BYTE Adr; |
.................... |
.................... Adr=x-1; |
009E: MOVLW 01 |
009F: SUBWF 31,W |
00A0: MOVWF 33 |
.................... if(y==2) |
00A1: MOVF 32,W |
00A2: SUBLW 02 |
00A3: BTFSS 03.2 |
00A4: GOTO 0A7 |
.................... Adr+=LCD_LINE_2; |
00A5: MOVLW 40 |
00A6: ADDWF 33,F |
.................... |
.................... lcd_send_byte(0,0x80|Adr); |
00A7: MOVF 33,W |
00A8: IORLW 80 |
00A9: MOVWF 34 |
00AA: CLRF 35 |
00AB: MOVF 34,W |
00AC: MOVWF 36 |
00AD: CALL 04E |
.................... } |
00AE: RETLW 00 |
.................... |
.................... |
.................... // Zapis znaku na displej, zpracovani ridicich znaku |
.................... // |
.................... void lcd_putc( char c) |
.................... { |
.................... |
.................... switch (c) |
.................... { |
00AF: MOVF 30,W |
00B0: XORLW 0C |
00B1: BTFSC 03.2 |
00B2: GOTO 0BD |
00B3: XORLW 06 |
00B4: BTFSC 03.2 |
00B5: GOTO 0C5 |
00B6: XORLW 07 |
00B7: BTFSC 03.2 |
00B8: GOTO 0CB |
00B9: XORLW 05 |
00BA: BTFSC 03.2 |
00BB: GOTO 0D0 |
00BC: GOTO 0D5 |
.................... case '\f' : lcd_send_byte(0,1); // smaz displej |
00BD: CLRF 35 |
00BE: MOVLW 01 |
00BF: MOVWF 36 |
00C0: CALL 04E |
.................... delay_ms(2); |
00C1: MOVLW 02 |
00C2: MOVWF 31 |
00C3: CALL 028 |
.................... break; |
00C4: GOTO 0E1 |
.................... case '\n' : lcd_gotoxy(1,2); break; // presun se na 1. znak 2. radky |
00C5: MOVLW 01 |
00C6: MOVWF 31 |
00C7: MOVLW 02 |
00C8: MOVWF 32 |
00C9: CALL 09E |
00CA: GOTO 0E1 |
.................... case '\r' : lcd_gotoxy(1,1); break; // presun home |
00CB: MOVLW 01 |
00CC: MOVWF 31 |
00CD: MOVWF 32 |
00CE: CALL 09E |
00CF: GOTO 0E1 |
.................... case '\b' : lcd_send_byte(0,0x10); break; // posun kurzor o 1 zpet |
00D0: CLRF 35 |
00D1: MOVLW 10 |
00D2: MOVWF 36 |
00D3: CALL 04E |
00D4: GOTO 0E1 |
.................... default : if (c<0x20) c&=0x7; // preklopeni definovatelnych znaku na rozsah 0 az 0x1F |
00D5: MOVF 30,W |
00D6: SUBLW 1F |
00D7: BTFSS 03.0 |
00D8: GOTO 0DB |
00D9: MOVLW 07 |
00DA: ANDWF 30,F |
.................... lcd_send_byte(1,c); break; // zapis znak |
00DB: MOVLW 01 |
00DC: MOVWF 35 |
00DD: MOVF 30,W |
00DE: MOVWF 36 |
00DF: CALL 04E |
00E0: GOTO 0E1 |
.................... } |
.................... } |
00E1: RETLW 00 |
.................... |
.................... |
.................... // Zapni kurzor |
.................... // |
.................... void lcd_cursor_on() |
.................... { |
.................... lcd_send_byte(0,LCD_CURSOR_ON_); |
.................... } |
.................... |
.................... |
.................... // Vypni kurzor |
.................... // |
.................... void lcd_cursor_off() |
.................... { |
.................... lcd_send_byte(0,LCD_CURSOR_OFF_); |
.................... } |
.................... |
.................... |
.................... // Smaz displej |
.................... // |
.................... void lcd_clr() |
.................... { |
.................... lcd_putc('\f'); |
.................... } |
.................... |
.................... |
.................... // Definice vlastnich fontu |
.................... // |
.................... // Vlastnich definic muze byt jen 8 do pozic 0 az 7 pameti CGRAM radice lcd displeje |
.................... // Pro snadne definovani jsou pripraveny nasledujici definice a na konci souboru je uveden |
.................... // priklad pouziti definovanych znaku. |
.................... |
.................... |
.................... // Pomocna procedura pro posilani ridicich dat do radice displeje |
.................... // |
.................... void lcd_putc2(int Data) |
.................... { |
.................... lcd_send_byte(1,Data); |
.................... } |
.................... |
.................... |
.................... // Pomocne definice pro programovani obsahu CGRAM |
.................... // |
.................... #define lcd_define_start(Code) lcd_send_byte(0,0x40+(Code<<3)); delay_ms(2) |
.................... #define lcd_define_def(String) printf(lcd_putc2,String); |
.................... #define lcd_define_end() lcd_send_byte(0,3); delay_ms(2) |
.................... |
.................... |
.................... // Vlastni vykonne makro pro definovani fontu do pozice Index CGRAM s definicnim retezcem Def |
.................... // |
.................... #define lcd_define_char(Index, Def) lcd_define_start(Index); lcd_define_def(Def); lcd_define_end(); |
.................... |
.................... |
.................... // Pripravene definice fontu vybranych znaku |
.................... // V tabulce nesmi byt 00 (konec retezce v printf()), misto toho davame 80 |
.................... // |
.................... #define LCD_CHAR_BAT100 "\x0E\x1F\x1F\x1F\x1F\x1F\x1F\x1F" /* symbol plne baterie */ |
.................... #define LCD_CHAR_BAT50 "\x0E\x1F\x11\x11\x13\x17\x1F\x1F" /* symbol polovicni baterie */ |
.................... #define LCD_CHAR_BAT0 "\x0E\x1F\x11\x11\x11\x11\x11\x1F" /* symbol vybite baterie */ |
.................... #define LCD_CHAR_UP "\x80\x04\x0E\x15\x04\x04\x04\x80" /* symbol sipka nahoru */ |
.................... #define LCD_CHAR_DOWN "\x80\x04\x04\x04\x15\x0E\x04\x80" /* symbol Sipka dolu */ |
.................... #define LCD_CHAR_LUA "\x04\x0E\x11\x11\x1F\x11\x11\x80" /* A s carkou */ |
.................... #define LCD_CHAR_LLA "\x01\x02\x0E\x01\x1F\x11\x0F\x80" /* a s carkou */ |
.................... #define LCD_CHAR_HUC "\x0A\x0E\x11\x10\x10\x11\x0E\x80" /* C s hackem */ |
.................... #define LCD_CHAR_HLC "\x0A\x04\x0E\x10\x10\x11\x0E\x80" /* c s hackem */ |
.................... #define LCD_CHAR_HUD "\x0A\x1C\x12\x11\x11\x12\x1C\x80" /* D s hackem */ |
.................... #define LCD_CHAR_HLD "\x05\x03\x0D\x13\x11\x11\x0F\x80" /* d s hackem */ |
.................... #define LCD_CHAR_LUE "\x04\x1F\x10\x10\x1E\x10\x1F\x80" /* E s carkou */ |
.................... #define LCD_CHAR_LLE "\x01\x02\x0E\x11\x1F\x10\x0E\x80" /* e s carkou */ |
.................... #define LCD_CHAR_HUE "\x0A\x1F\x10\x1E\x10\x10\x1F\x80" /* E s hackem */ |
.................... #define LCD_CHAR_HLE "\x0A\x04\x0E\x11\x1F\x10\x0E\x80" /* e s hackem */ |
.................... #define LCD_CHAR_LUI "\x04\x0E\x04\x04\x04\x04\x0E\x80" /* I s carkou */ |
.................... #define LCD_CHAR_LLI "\x02\x04\x80\x0C\x04\x04\x0E\x80" /* i s carkou */ |
.................... #define LCD_CHAR_HUN "\x0A\x15\x11\x19\x15\x13\x11\x80" /* N s hackem */ |
.................... #define LCD_CHAR_HLN "\x0A\x04\x16\x19\x11\x11\x11\x80" /* n s hackem */ |
.................... #define LCD_CHAR_LUO "\x04\x0E\x11\x11\x11\x11\x0E\x80" /* O s carkou */ |
.................... #define LCD_CHAR_LLO "\x02\x04\x0E\x11\x11\x11\x0E\x80" /* o s carkou */ |
.................... #define LCD_CHAR_HUR "\x0A\x1E\x11\x1E\x14\x12\x11\x80" /* R s hackem */ |
.................... #define LCD_CHAR_HLR "\x0A\x04\x16\x19\x10\x10\x10\x80" /* r s hackem */ |
.................... #define LCD_CHAR_HUS "\x0A\x0F\x10\x0E\x01\x01\x1E\x80" /* S s hackem */ |
.................... #define LCD_CHAR_HLS "\x0A\x04\x0E\x10\x0E\x01\x1E\x80" /* s s hackem */ |
.................... #define LCD_CHAR_HUT "\x0A\x1F\x04\x04\x04\x04\x04\x80" /* T s hackem */ |
.................... #define LCD_CHAR_HLT "\x0A\x0C\x1C\x08\x08\x09\x06\x80" /* t s hackem */ |
.................... #define LCD_CHAR_LUU "\x02\x15\x11\x11\x11\x11\x0E\x80" /* U s carkou */ |
.................... #define LCD_CHAR_LLU "\x02\x04\x11\x11\x11\x13\x0D\x80" /* u s carkou */ |
.................... #define LCD_CHAR_CUU "\x06\x17\x11\x11\x11\x11\x0E\x80" /* U s krouzkem */ |
.................... #define LCD_CHAR_CLU "\x06\x06\x11\x11\x11\x11\x0E\x80" /* u s krouzkem */ |
.................... #define LCD_CHAR_LUY "\x02\x15\x11\x0A\x04\x04\x04\x80" /* Y s carkou */ |
.................... #define LCD_CHAR_LLY "\x02\x04\x11\x11\x0F\x01\x0E\x80" /* y s carkou */ |
.................... #define LCD_CHAR_HUZ "\x0A\x1F\x01\x02\x04\x08\x1F\x80" /* Z s hackem */ |
.................... #define LCD_CHAR_HLZ "\x0A\x04\x1F\x02\x04\x08\x1F\x80" /* z s hackem */ |
.................... |
.................... |
.................... // Priklad pouziti definovanych znaku |
.................... // |
.................... // |
.................... //void lcd_sample() |
.................... //{ |
.................... // lcd_define_char(0,LCD_CHAR_BAT50); // Priklad definice znaku baterie do pozice 0 |
.................... // lcd_define_char(2,LCD_CHAR_HLE LCD_CHAR_LUI); // Priklad definice znaku e s hackem a I s carkou od pozice 2 |
.................... // // vsimnete si, ze neni carka mezi retezci s definici (oba retezce definuji |
.................... // // jediny definicni retezec) |
.................... // printf(lcd_putc,"\fZnaky:\20\22\23"); // priklad vypisu znaku z pozice 0, 2 a 3 |
.................... // delay_ms(1000); |
.................... // lcd_define_char(0,LCD_CHAR_BAT0); // Predefinovani tvaru znaku v pozici 0 |
.................... // delay_ms(1000); |
.................... //} |
.................... |
.................... |
.................... #include "C:\library\kaklik\CCS\mys_chip_SPI.c" // modul umoznujici komunikaci s cidlem v mysi |
.................... //////////////////////////////////////////////////////////////////////////////// |
.................... // |
.................... // Modul pro prime ovladani senzoru v opticke mysi. |
.................... // (Pouziva SPI jednotku) |
.................... // |
.................... // |
.................... //////////////////////////////////////////////////////////////////////////////// |
.................... |
.................... #define SPI_DATA PIN_B2 // je treba nadefinovat datovy pin, aby se vedelo, ktery pin se ma vypinat pri cteni dat. |
.................... |
.................... // Address |
.................... #define PRODUCT_ID 0x00 |
.................... #define PRODUCT_ID4 0x01 |
.................... #define MOTION_STATUS 0x02 // |
.................... #define DELTA_X 0x03 // vycteni os |
.................... #define DELTA_Y 0x04 // -//- |
.................... #define OPERATION_MODE 0x85 // zapis do ridiciho registru |
.................... #define CONFIGURATION 0x86 // zmeni nastaveni rozliseni, atd. |
.................... |
.................... void chip_write(command) |
.................... { |
.................... output_high(PIN_B2); |
* |
001B: BSF 03.5 |
001C: BCF 06.2 |
001D: BCF 03.5 |
001E: BSF 06.2 |
.................... spi_write(command); |
001F: MOVF 28,W |
0020: MOVWF 13 |
0021: BSF 03.5 |
0022: BTFSC 14.0 |
0023: GOTO 026 |
0024: BCF 03.5 |
0025: GOTO 021 |
.................... } |
0026: BCF 03.5 |
0027: RETLW 00 |
.................... |
.................... signed int8 chip_read(command) |
.................... { |
.................... output_high(SPI_DATA); |
* |
016E: BSF 03.5 |
016F: BCF 06.2 |
0170: BCF 03.5 |
0171: BSF 06.2 |
.................... spi_write(command); |
0172: MOVF 28,W |
0173: MOVWF 13 |
0174: BSF 03.5 |
0175: BTFSC 14.0 |
0176: GOTO 179 |
0177: BCF 03.5 |
0178: GOTO 174 |
.................... output_float(SPI_DATA); |
0179: BSF 06.2 |
.................... return spi_read(0); |
017A: BCF 03.5 |
017B: MOVF 13,W |
017C: CLRF 13 |
017D: BSF 03.5 |
017E: BTFSC 14.0 |
017F: GOTO 182 |
0180: BCF 03.5 |
0181: GOTO 17D |
0182: BCF 03.5 |
0183: MOVF 13,W |
0184: MOVWF 78 |
.................... } |
0185: RETLW 00 |
.................... |
.................... |
.................... void main() |
.................... { |
0186: CLRF 04 |
0187: MOVLW 1F |
0188: ANDWF 03,F |
0189: BSF 03.5 |
018A: BCF 1F.4 |
018B: BCF 1F.5 |
018C: MOVF 1B,W |
018D: ANDLW 80 |
018E: MOVWF 1B |
018F: MOVLW 07 |
0190: MOVWF 1C |
0191: MOVF 1C,W |
0192: BCF 03.5 |
0193: BCF 0D.6 |
0194: MOVLW 60 |
0195: BSF 03.5 |
0196: MOVWF 0F |
.................... unsigned int8 hodnota; |
.................... signed int16 x=0,y=0; |
0197: BCF 03.5 |
0198: CLRF 22 |
0199: CLRF 23 |
019A: CLRF 24 |
019B: CLRF 25 |
.................... signed int8 xd,yd; |
.................... |
.................... setup_adc_ports(NO_ANALOGS|VSS_VDD); |
019C: BSF 03.5 |
019D: BCF 1F.4 |
019E: BCF 1F.5 |
019F: MOVF 1B,W |
01A0: ANDLW 80 |
01A1: MOVWF 1B |
.................... setup_adc(ADC_OFF); |
01A2: BCF 03.5 |
01A3: BCF 1F.0 |
.................... setup_spi(SPI_MASTER|SPI_H_TO_L|SPI_XMIT_L_TO_H|SPI_CLK_DIV_64); |
01A4: BCF 14.5 |
01A5: BSF 03.5 |
01A6: BCF 06.2 |
01A7: BSF 06.1 |
01A8: BCF 06.4 |
01A9: MOVLW 32 |
01AA: BCF 03.5 |
01AB: MOVWF 14 |
01AC: MOVLW 00 |
01AD: BSF 03.5 |
01AE: MOVWF 14 |
.................... setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
01AF: MOVF 01,W |
01B0: ANDLW C7 |
01B1: IORLW 08 |
01B2: MOVWF 01 |
.................... setup_timer_1(T1_DISABLED); |
01B3: BCF 03.5 |
01B4: CLRF 10 |
.................... setup_timer_2(T2_DISABLED,0,1); |
01B5: MOVLW 00 |
01B6: MOVWF 78 |
01B7: MOVWF 12 |
01B8: MOVLW 00 |
01B9: BSF 03.5 |
01BA: MOVWF 12 |
.................... setup_comparator(NC_NC_NC_NC); |
01BB: MOVLW 07 |
01BC: MOVWF 1C |
01BD: MOVF 05,W |
01BE: MOVLW 03 |
01BF: MOVWF 77 |
01C0: DECFSZ 77,F |
01C1: GOTO 1C0 |
01C2: MOVF 1C,W |
01C3: BCF 03.5 |
01C4: BCF 0D.6 |
.................... setup_vref(FALSE); |
01C5: BSF 03.5 |
01C6: CLRF 1D |
.................... |
.................... chip_write(OPERATION_MODE); |
01C7: MOVLW 85 |
01C8: BCF 03.5 |
01C9: MOVWF 28 |
01CA: CALL 01B |
.................... chip_write(0x00); // vypne sleep mode |
01CB: CLRF 28 |
01CC: CALL 01B |
.................... |
.................... chip_write(CONFIGURATION); |
01CD: MOVLW 86 |
01CE: MOVWF 28 |
01CF: CALL 01B |
.................... chip_write(0b00000110); // nastavi rozliseni na 600cpi |
01D0: MOVLW 06 |
01D1: MOVWF 28 |
01D2: CALL 01B |
.................... |
.................... lcd_init(); |
01D3: GOTO 064 |
.................... Delay_ms(200); |
01D4: MOVLW C8 |
01D5: MOVWF 31 |
01D6: CALL 028 |
.................... |
.................... While(true) |
.................... { |
.................... LCD_gotoxy(1,1); |
01D7: MOVLW 01 |
01D8: MOVWF 31 |
01D9: MOVWF 32 |
01DA: CALL 09E |
.................... printf(lcd_putc,"status: %X", hodnota); |
01DB: CLRF 28 |
01DC: MOVF 28,W |
01DD: CALL 00C |
01DE: INCF 28,F |
01DF: MOVWF 77 |
01E0: MOVWF 30 |
01E1: CALL 0AF |
01E2: MOVLW 08 |
01E3: SUBWF 28,W |
01E4: BTFSS 03.2 |
01E5: GOTO 1DC |
01E6: MOVF 21,W |
01E7: MOVWF 29 |
01E8: MOVLW 37 |
01E9: MOVWF 2A |
01EA: GOTO 0E2 |
.................... delay_ms(20); |
01EB: MOVLW 14 |
01EC: MOVWF 31 |
01ED: CALL 028 |
.................... |
.................... LCD_gotoxy(1,2); |
01EE: MOVLW 01 |
01EF: MOVWF 31 |
01F0: MOVLW 02 |
01F1: MOVWF 32 |
01F2: CALL 09E |
.................... printf(lcd_putc,"X=%ld Y=%ld", x, y); |
01F3: MOVLW 58 |
01F4: MOVWF 30 |
01F5: CALL 0AF |
01F6: MOVLW 3D |
01F7: MOVWF 30 |
01F8: CALL 0AF |
01F9: MOVLW 10 |
01FA: MOVWF 04 |
01FB: MOVF 23,W |
01FC: MOVWF 29 |
01FD: MOVF 22,W |
01FE: MOVWF 28 |
01FF: CALL 104 |
0200: MOVLW 20 |
0201: MOVWF 30 |
0202: CALL 0AF |
0203: MOVLW 59 |
0204: MOVWF 30 |
0205: CALL 0AF |
0206: MOVLW 3D |
0207: MOVWF 30 |
0208: CALL 0AF |
0209: MOVLW 10 |
020A: MOVWF 04 |
020B: MOVF 25,W |
020C: MOVWF 29 |
020D: MOVF 24,W |
020E: MOVWF 28 |
020F: CALL 104 |
.................... delay_ms(20); |
0210: MOVLW 14 |
0211: MOVWF 31 |
0212: CALL 028 |
.................... |
.................... hodnota=chip_read(MOTION_STATUS); |
0213: MOVLW 02 |
0214: MOVWF 28 |
0215: CALL 16E |
0216: MOVF 78,W |
0217: MOVWF 21 |
.................... |
.................... xd=chip_read(DELTA_X); |
0218: MOVLW 03 |
0219: MOVWF 28 |
021A: CALL 16E |
021B: MOVF 78,W |
021C: MOVWF 26 |
.................... yd=chip_read(DELTA_Y); |
021D: MOVLW 04 |
021E: MOVWF 28 |
021F: CALL 16E |
0220: MOVF 78,W |
0221: MOVWF 27 |
.................... |
.................... x+=xd; |
0222: CLRF 7A |
0223: MOVF 26,W |
0224: BTFSC 26.7 |
0225: DECF 7A,F |
0226: ADDWF 22,F |
0227: BTFSC 03.0 |
0228: INCF 23,F |
0229: MOVF 7A,W |
022A: ADDWF 23,F |
.................... y+=yd; |
022B: CLRF 7A |
022C: MOVF 27,W |
022D: BTFSC 27.7 |
022E: DECF 7A,F |
022F: ADDWF 24,F |
0230: BTFSC 03.0 |
0231: INCF 25,F |
0232: MOVF 7A,W |
0233: ADDWF 25,F |
.................... } |
0234: GOTO 1D7 |
.................... } |
.................... |
0235: SLEEP |
|
Configuration Fuses: |
Word 1: 3F79 NOWDT NOPUT MCLR BROWNOUT NOLVP NOCPD NOWRT NODEBUG CCPB0 NOPROTECT INTRC |
Word 2: 3FFF FCMEN IESO |