0,0 → 1,1175 |
CCS PCW C Compiler, Version 3.110, 15448 |
|
Filename: d:\@kaklik\programy\pic_c\prenos\letadlo\prijimac\main.LST |
|
ROM used: 687 (67%) |
Largest free fragment is 337 |
RAM used: 12 (18%) at main() level |
25 (37%) worst case |
Stack: 5 locations |
|
* |
0000: MOVLW 00 |
0001: MOVWF 0A |
0002: GOTO 1CE |
0003: NOP |
.................... // Prijimac |
.................... |
.................... #DEFINE DEBUG PIN_A2 // ladici pomocne synchronizacni impulzy |
.................... |
.................... #include "main.h" |
.................... #include <16F84.h> |
.................... //////// Standard Header file for the PIC16F84 device //////////////// |
.................... #device PIC16F84 |
.................... #list |
.................... |
.................... #use delay(clock=4000000) |
* |
0015: MOVLW 1C |
0016: MOVWF 04 |
0017: MOVF 00,W |
0018: BTFSC 03.2 |
0019: GOTO 029 |
001A: MOVLW 01 |
001B: MOVWF 0D |
001C: CLRF 0C |
001D: DECFSZ 0C,F |
001E: GOTO 01D |
001F: DECFSZ 0D,F |
0020: GOTO 01C |
0021: MOVLW 4A |
0022: MOVWF 0C |
0023: DECFSZ 0C,F |
0024: GOTO 023 |
0025: NOP |
0026: NOP |
0027: DECFSZ 00,F |
0028: GOTO 01A |
0029: RETLW 00 |
.................... #fuses XT,NOWDT,PUT |
.................... |
.................... |
.................... #include "..\common.h" |
.................... #DEFINE OSA_X 1 // adresy os |
.................... #DEFINE OSA_Y 2 |
.................... #DEFINE TLs 3 |
.................... #DEFINE IMPULS 250 // sirka impulsu |
.................... #DEFINE SYNC_NIBBLE 0b1111 // magiske cislo sync niblu |
.................... |
.................... |
.................... #DEFINE LCD_RS PIN_B1 // rizeni registru LCD displeje |
.................... #DEFINE LCD_E PIN_B0 // enable LCD displeje |
.................... #DEFINE LCD_DATA_LSB PIN_B2 // pripojeni LSB bitu datoveho portu LCD displeje (celkem 4 bity vzestupne za sebou) |
.................... #INCLUDE "MYLCD.C" |
.................... // LCD modul pro ovladani dvouradkoveho LCD modulu se standardnim Hitachi radicem |
.................... // (c)miho 2002 |
.................... // |
.................... // Historie: |
.................... // |
.................... // 0.0 Uvodni verze se snadnou definici portu LCD 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_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: |
.................... // |
.................... // #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) |
.................... |
.................... |
.................... |
.................... |
.................... // Privatni sekce, cist jen v pripade, ze neco nefunguje |
.................... |
.................... |
.................... |
.................... |
.................... // 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 dataoveho 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 |
.................... |
.................... |
.................... // 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) |
.................... }; |
* |
0004: BCF 0A.0 |
0005: BCF 0A.1 |
0006: BCF 0A.2 |
0007: ADDWF 02,F |
0008: RETLW 28 |
0009: RETLW 0C |
000A: RETLW 01 |
000B: RETLW 06 |
.................... |
.................... |
.................... // Odesle nibble do displeje (posle data a klikne signalem e) |
.................... // |
.................... void lcd_send_nibble( BYTE n ) |
.................... { |
.................... *LCD_PORT = (*LCD_PORT & ~LCD_MASK) | ((n << LCD_SHIFT) & LCD_MASK); // nastav datove bity portu a ostatni zachovej |
* |
002A: MOVF 06,W |
002B: ANDLW C3 |
002C: MOVWF 23 |
002D: RLF 22,W |
002E: MOVWF 0C |
002F: RLF 0C,F |
0030: MOVLW FC |
0031: ANDWF 0C,F |
0032: MOVF 0C,W |
0033: ANDLW 3C |
0034: IORWF 23,W |
0035: MOVWF 06 |
.................... output_bit(LCD_E,1); // vzestupna hrana |
0036: BSF 06.0 |
0037: BSF 03.5 |
0038: BCF 06.0 |
.................... delay_us(1); // pockej alespon 450ns od e nebo alespon 195ns od dat |
0039: NOP |
.................... output_bit(LCD_E,0); // sestupna hrana (minimalni perioda e je 1us) |
003A: BCF 03.5 |
003B: BCF 06.0 |
003C: BSF 03.5 |
003D: BCF 06.0 |
003E: BCF 03.5 |
003F: 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 |
0040: MOVF 20,F |
0041: BTFSS 03.2 |
0042: GOTO 045 |
0043: BCF 06.1 |
0044: GOTO 046 |
0045: BSF 06.1 |
0046: BSF 03.5 |
0047: BCF 06.1 |
.................... swap(n); |
0048: BCF 03.5 |
0049: SWAPF 21,F |
.................... lcd_send_nibble(n); // posli horni pulku bajtu |
004A: MOVF 21,W |
004B: MOVWF 22 |
004C: CALL 02A |
.................... swap(n); |
004D: SWAPF 21,F |
.................... lcd_send_nibble(n); // posli spodni pulku bajtu |
004E: MOVF 21,W |
004F: MOVWF 22 |
0050: CALL 02A |
.................... delay_us(40); // minimalni doba na provedeni prikazu |
0051: MOVLW 0D |
0052: MOVWF 0C |
0053: DECFSZ 0C,F |
0054: GOTO 053 |
0055: 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 |
0056: MOVLW 14 |
0057: MOVWF 1C |
0058: CALL 015 |
.................... |
.................... *LCD_TRIS = *LCD_TRIS & ~LCD_MASK; // nuluj odpovidajici bity tris registru datoveho portu LCD |
0059: MOVLW C3 |
005A: BSF 03.5 |
005B: ANDWF 06,F |
.................... |
.................... output_bit(LCD_RS,0); // nastav jako vystup a nastav klidovy stav |
005C: BCF 03.5 |
005D: BCF 06.1 |
005E: BSF 03.5 |
005F: BCF 06.1 |
.................... output_bit(LCD_E,0); // nastav jako vystup a nastav klidovy stav |
0060: BCF 03.5 |
0061: BCF 06.0 |
0062: BSF 03.5 |
0063: BCF 06.0 |
.................... |
.................... for (i=0; i<3; i++) // nastav lcd do rezimu 8 bitu sbernice |
0064: BCF 03.5 |
0065: CLRF 19 |
0066: MOVF 19,W |
0067: SUBLW 02 |
0068: BTFSS 03.0 |
0069: GOTO 072 |
.................... { |
.................... delay_ms(2); // muze byt rozdelany prenos dat (2x 4 bity) nebo pomaly povel |
006A: MOVLW 02 |
006B: MOVWF 1C |
006C: CALL 015 |
.................... lcd_send_nibble(3); // rezim 8 bitu |
006D: MOVLW 03 |
006E: MOVWF 22 |
006F: CALL 02A |
.................... } |
0070: INCF 19,F |
0071: GOTO 066 |
.................... |
.................... delay_us(40); // cas na zpracovani |
0072: MOVLW 0D |
0073: MOVWF 0C |
0074: DECFSZ 0C,F |
0075: GOTO 074 |
.................... lcd_send_nibble(2); // nastav rezim 4 bitu (plati od nasledujiciho prenosu) |
0076: MOVLW 02 |
0077: MOVWF 22 |
0078: CALL 02A |
.................... delay_us(40); // cas na zpracovani |
0079: MOVLW 0D |
007A: MOVWF 0C |
007B: DECFSZ 0C,F |
007C: GOTO 07B |
.................... |
.................... for (i=0;i<3;i++) // proved inicializaci (nastaveni modu, smazani apod) |
007D: CLRF 19 |
007E: MOVF 19,W |
007F: SUBLW 02 |
0080: BTFSS 03.0 |
0081: GOTO 08E |
.................... { |
.................... lcd_send_byte(0,LCD_INIT_STRING[i]); |
0082: MOVF 19,W |
0083: CALL 004 |
0084: MOVWF 1A |
0085: CLRF 20 |
0086: MOVF 1A,W |
0087: MOVWF 21 |
0088: CALL 040 |
.................... delay_ms(2); |
0089: MOVLW 02 |
008A: MOVWF 1C |
008B: CALL 015 |
.................... } |
008C: INCF 19,F |
008D: GOTO 07E |
008E: GOTO 1D2 (RETURN) |
.................... } |
.................... |
.................... |
.................... // Proved presun kurzoru |
.................... // |
.................... // Pozice 1.1 je domu |
.................... // |
.................... void lcd_gotoxy( BYTE x, BYTE y) |
.................... { |
.................... |
.................... BYTE Adr; |
.................... |
.................... Adr=x-1; |
008F: MOVLW 01 |
0090: SUBWF 1C,W |
0091: MOVWF 1E |
.................... if(y==2) |
0092: MOVF 1D,W |
0093: SUBLW 02 |
0094: BTFSS 03.2 |
0095: GOTO 098 |
.................... Adr+=LCD_LINE_2; |
0096: MOVLW 40 |
0097: ADDWF 1E,F |
.................... |
.................... lcd_send_byte(0,0x80|Adr); |
0098: MOVF 1E,W |
0099: IORLW 80 |
009A: MOVWF 1F |
009B: CLRF 20 |
009C: MOVF 1F,W |
009D: MOVWF 21 |
009E: CALL 040 |
009F: RETLW 00 |
.................... } |
.................... |
.................... |
.................... // Zapis znaku na displej, zpracovani ridicich znaku |
.................... // |
.................... void lcd_putc( char c) |
.................... { |
.................... |
.................... switch (c) |
00A0: MOVF 1B,W |
00A1: MOVWF 0C |
00A2: MOVLW 0C |
00A3: SUBWF 0C,W |
00A4: BTFSC 03.2 |
00A5: GOTO 0B3 |
00A6: MOVLW 0A |
00A7: SUBWF 0C,W |
00A8: BTFSC 03.2 |
00A9: GOTO 0BB |
00AA: MOVLW 0D |
00AB: SUBWF 0C,W |
00AC: BTFSC 03.2 |
00AD: GOTO 0C1 |
00AE: MOVLW 08 |
00AF: SUBWF 0C,W |
00B0: BTFSC 03.2 |
00B1: GOTO 0C6 |
00B2: GOTO 0CB |
.................... { |
.................... case '\f' : lcd_send_byte(0,1); // smaz displej |
00B3: CLRF 20 |
00B4: MOVLW 01 |
00B5: MOVWF 21 |
00B6: CALL 040 |
.................... delay_ms(2); |
00B7: MOVLW 02 |
00B8: MOVWF 1C |
00B9: CALL 015 |
.................... break; |
00BA: GOTO 0D7 |
.................... case '\n' : lcd_gotoxy(1,2); break; // presun se na 1. znak 2. radky |
00BB: MOVLW 01 |
00BC: MOVWF 1C |
00BD: MOVLW 02 |
00BE: MOVWF 1D |
00BF: CALL 08F |
00C0: GOTO 0D7 |
.................... case '\r' : lcd_gotoxy(1,1); break; // presun home |
00C1: MOVLW 01 |
00C2: MOVWF 1C |
00C3: MOVWF 1D |
00C4: CALL 08F |
00C5: GOTO 0D7 |
.................... case '\b' : lcd_send_byte(0,0x10); break; // posun kurzor o 1 zpet |
00C6: CLRF 20 |
00C7: MOVLW 10 |
00C8: MOVWF 21 |
00C9: CALL 040 |
00CA: GOTO 0D7 |
.................... default : if (c<0x20) c&=0x7; // preklopeni definovatelnych znaku na rozsah 0 az 0x1F |
00CB: MOVF 1B,W |
00CC: SUBLW 1F |
00CD: BTFSS 03.0 |
00CE: GOTO 0D1 |
00CF: MOVLW 07 |
00D0: ANDWF 1B,F |
.................... lcd_send_byte(1,c); break; // zapis znak |
00D1: MOVLW 01 |
00D2: MOVWF 20 |
00D3: MOVF 1B,W |
00D4: MOVWF 21 |
00D5: CALL 040 |
00D6: GOTO 0D7 |
.................... } |
00D7: 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_); |
.................... } |
.................... |
.................... |
.................... // 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_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); |
.................... //} |
.................... |
.................... |
.................... #DEFINE PRIJIMAC PIN_A3 // pin na ktery je pripojen prijimac |
.................... #DEFINE SERVO_X PIN_A0 // pin na ktery je pripojeno servo |
.................... #DEFINE SERVO_Y PIN_A1 |
.................... |
.................... |
.................... // Prijme datovy nibble vcetne zasynchronizovani |
.................... // Chybi dodelat timeout |
.................... int8 prijmi_nibble(int8* datovy, int8* data) |
.................... { |
.................... int8 i; |
.................... |
.................... #IFDEF DEBUG |
.................... int1 tmp; |
.................... #ENDIF |
.................... |
.................... *data=0; |
00D8: MOVF 1E,W |
00D9: MOVWF 04 |
00DA: CLRF 00 |
.................... |
.................... // Cekam na dlouhou nulu |
.................... for (i=4; i>0; i--) |
00DB: MOVLW 04 |
00DC: MOVWF 1F |
00DD: MOVF 1F,F |
00DE: BTFSC 03.2 |
00DF: GOTO 0EE |
.................... { |
.................... if (input(PRIJIMAC)) i=4; |
00E0: BSF 03.5 |
00E1: BSF 05.3 |
00E2: BCF 03.5 |
00E3: BTFSS 05.3 |
00E4: GOTO 0E7 |
00E5: MOVLW 04 |
00E6: MOVWF 1F |
.................... delay_us(IMPULS/2); |
00E7: MOVLW 29 |
00E8: MOVWF 0C |
00E9: DECFSZ 0C,F |
00EA: GOTO 0E9 |
00EB: NOP |
.................... } |
00EC: DECF 1F,F |
00ED: GOTO 0DD |
.................... |
.................... // Cekam na jednicku (start ramce) |
.................... for (; !input(PRIJIMAC); ) |
00EE: BSF 03.5 |
00EF: BSF 05.3 |
00F0: BCF 03.5 |
00F1: BTFSS 05.3 |
.................... { |
.................... } |
00F2: GOTO 0EE |
.................... |
.................... // Ctu typ nibblu |
.................... delay_us(2*IMPULS+2*IMPULS/3); |
00F3: MOVLW DD |
00F4: MOVWF 0C |
00F5: DECFSZ 0C,F |
00F6: GOTO 0F5 |
00F7: NOP |
00F8: NOP |
.................... *datovy=input(PRIJIMAC); |
00F9: MOVF 1D,W |
00FA: MOVWF 04 |
00FB: BSF 03.5 |
00FC: BSF 05.3 |
00FD: MOVLW 00 |
00FE: BCF 03.5 |
00FF: BTFSC 05.3 |
0100: MOVLW 01 |
0101: MOVWF 00 |
.................... |
.................... // Prenasim bity |
.................... for (i=0; i<4; i++) |
0102: CLRF 1F |
0103: MOVF 1F,W |
0104: SUBLW 03 |
0105: BTFSS 03.0 |
0106: GOTO 128 |
.................... { |
.................... delay_us(2*IMPULS); |
0107: MOVLW A6 |
0108: MOVWF 0C |
0109: DECFSZ 0C,F |
010A: GOTO 109 |
010B: NOP |
.................... *data >>= 1; |
010C: MOVF 1E,W |
010D: MOVWF 04 |
010E: BCF 03.0 |
010F: RRF 00,W |
0110: MOVWF 0C |
0111: MOVWF 00 |
.................... if (input(PRIJIMAC)) *data +=0b1000; |
0112: BSF 03.5 |
0113: BSF 05.3 |
0114: BCF 03.5 |
0115: BTFSS 05.3 |
0116: GOTO 11C |
0117: MOVF 1E,W |
0118: MOVWF 04 |
0119: MOVLW 08 |
011A: ADDWF 00,W |
011B: MOVWF 00 |
.................... |
.................... #IFDEF DEBUG |
.................... output_bit(DEBUG,tmp); |
011C: BTFSC 20.0 |
011D: GOTO 120 |
011E: BCF 05.2 |
011F: GOTO 121 |
0120: BSF 05.2 |
0121: BSF 03.5 |
0122: BCF 05.2 |
.................... tmp=!tmp; |
0123: MOVLW 01 |
0124: BCF 03.5 |
0125: XORWF 20,F |
.................... #ELSE |
.................... delay_us(20); |
.................... #ENDIF |
.................... } |
0126: INCF 1F,F |
0127: GOTO 103 |
.................... |
.................... return FALSE; |
0128: MOVLW 00 |
0129: MOVWF 0D |
012A: RETLW 00 |
.................... } |
.................... |
.................... |
.................... // Prijme datovy ramec |
.................... // Pokud nastane chyba vraci TRUE |
.................... int8 prijmi_ramec(int8* kanal, int8* data) |
.................... { |
.................... int8 datovy; |
.................... int8 suma; |
.................... |
.................... // Cekej na synchronizacni nibble |
.................... do |
.................... { |
.................... if (prijmi_nibble(&datovy, data)) return 1; // chyba timout |
012B: MOVLW 1B |
012C: MOVWF 1D |
012D: MOVF 1A,W |
012E: MOVWF 1E |
012F: CALL 0D8 |
0130: MOVF 0D,F |
0131: BTFSC 03.2 |
0132: GOTO 136 |
0133: MOVLW 01 |
0134: MOVWF 0D |
0135: GOTO 186 |
.................... } |
.................... while(datovy); |
0136: MOVF 1B,F |
0137: BTFSS 03.2 |
0138: GOTO 12B |
.................... |
.................... // Zkontroluj magickou hodnotu |
.................... if (*data != SYNC_NIBBLE) return 2; // chyba magickeho kodu ramce |
0139: MOVF 1A,W |
013A: MOVWF 04 |
013B: MOVF 00,W |
013C: SUBLW 0F |
013D: BTFSC 03.2 |
013E: GOTO 142 |
013F: MOVLW 02 |
0140: MOVWF 0D |
0141: GOTO 186 |
.................... |
.................... // Prijmi cislo kanalu |
.................... if (prijmi_nibble(&datovy, kanal)) return 1; // chyba timeout |
0142: MOVLW 1B |
0143: MOVWF 1D |
0144: MOVF 19,W |
0145: MOVWF 1E |
0146: CALL 0D8 |
0147: MOVF 0D,F |
0148: BTFSC 03.2 |
0149: GOTO 14D |
014A: MOVLW 01 |
014B: MOVWF 0D |
014C: GOTO 186 |
.................... if (!datovy) return 3; // chyba typu nibblu |
014D: MOVF 1B,F |
014E: BTFSS 03.2 |
014F: GOTO 153 |
0150: MOVLW 03 |
0151: MOVWF 0D |
0152: GOTO 186 |
.................... |
.................... // Prijmi data |
.................... if (prijmi_nibble(&datovy, data)) return 1; // chyba timeout |
0153: MOVLW 1B |
0154: MOVWF 1D |
0155: MOVF 1A,W |
0156: MOVWF 1E |
0157: CALL 0D8 |
0158: MOVF 0D,F |
0159: BTFSC 03.2 |
015A: GOTO 15E |
015B: MOVLW 01 |
015C: MOVWF 0D |
015D: GOTO 186 |
.................... if (!datovy) return 3; // chyba typu nibblu |
015E: MOVF 1B,F |
015F: BTFSS 03.2 |
0160: GOTO 164 |
0161: MOVLW 03 |
0162: MOVWF 0D |
0163: GOTO 186 |
.................... |
.................... // Prijmi zabezpeceni |
.................... if (prijmi_nibble(&datovy, &suma)) return 1; // chyba timeout |
0164: MOVLW 1B |
0165: MOVWF 1D |
0166: MOVLW 1C |
0167: MOVWF 1E |
0168: CALL 0D8 |
0169: MOVF 0D,F |
016A: BTFSC 03.2 |
016B: GOTO 16F |
016C: MOVLW 01 |
016D: MOVWF 0D |
016E: GOTO 186 |
.................... if (!datovy) return 3; // chyba typu nibblu |
016F: MOVF 1B,F |
0170: BTFSS 03.2 |
0171: GOTO 175 |
0172: MOVLW 03 |
0173: MOVWF 0D |
0174: GOTO 186 |
.................... |
.................... // Zkontroluj kontrolni soucet |
.................... |
.................... |
.................... //lcd_gotoxy(1,1); |
.................... //printf(lcd_putc,"R:%3U %3U %3U ",*kanal,*data,suma); |
.................... //delay_ms(1000); |
.................... |
.................... |
.................... if (((*kanal+*data) & 0b1111) != suma) return 3; // chyba kontrolniho souctu |
0175: MOVF 19,W |
0176: MOVWF 04 |
0177: MOVF 00,W |
0178: MOVWF 1D |
0179: MOVF 1A,W |
017A: MOVWF 04 |
017B: MOVF 00,W |
017C: ADDWF 1D,W |
017D: ANDLW 0F |
017E: SUBWF 1C,W |
017F: BTFSC 03.2 |
0180: GOTO 184 |
0181: MOVLW 03 |
0182: MOVWF 0D |
0183: GOTO 186 |
.................... |
.................... return 0; |
0184: MOVLW 00 |
0185: MOVWF 0D |
0186: GOTO 1FA (RETURN) |
.................... } |
.................... |
.................... |
.................... |
.................... int8 x,y; |
.................... int8 xc,yc; // pocitadla aktualizace x a y |
.................... int e1,e2,e3,e4; // pocitadla chyb - ladici |
.................... |
.................... void main() |
.................... { |
* |
01CE: CLRF 04 |
01CF: MOVLW 1F |
01D0: ANDWF 03,F |
.................... lcd_init(); // zinicializuj LCD display |
01D1: GOTO 056 |
.................... delay_ms(5); |
01D2: MOVLW 05 |
01D3: MOVWF 1C |
01D4: CALL 015 |
.................... printf(lcd_putc,"Ahoj..."); |
* |
000C: BCF 0A.0 |
000D: BCF 0A.1 |
000E: BCF 0A.2 |
000F: ADDWF 02,F |
0010: RETLW 41 |
0011: RETLW 68 |
0012: RETLW 6F |
0013: RETLW 6A |
0014: RETLW 00 |
* |
01D5: CLRF 19 |
01D6: MOVF 19,W |
01D7: CALL 00C |
01D8: INCF 19,F |
01D9: MOVWF 1B |
01DA: CALL 0A0 |
01DB: MOVLW 04 |
01DC: SUBWF 19,W |
01DD: BTFSS 03.2 |
01DE: GOTO 1D6 |
01DF: MOVLW 03 |
01E0: MOVWF 1A |
01E1: MOVLW 2E |
01E2: MOVWF 1B |
01E3: CALL 0A0 |
01E4: DECFSZ 1A,F |
01E5: GOTO 1E1 |
.................... delay_ms(300); |
01E6: MOVLW 02 |
01E7: MOVWF 19 |
01E8: MOVLW 96 |
01E9: MOVWF 1C |
01EA: CALL 015 |
01EB: DECFSZ 19,F |
01EC: GOTO 1E8 |
.................... |
.................... x = 0; |
01ED: CLRF 0E |
.................... y = 0; |
01EE: CLRF 0F |
.................... xc=0; |
01EF: CLRF 10 |
.................... yc=0; |
01F0: CLRF 11 |
.................... e1=0; |
01F1: CLRF 12 |
.................... e2=0; |
01F2: CLRF 13 |
.................... e3=0; |
01F3: CLRF 14 |
.................... e4=0; |
01F4: CLRF 15 |
.................... |
.................... while (true) |
.................... { |
.................... int8 kanal, data, e; |
.................... /* int8 kanal, data, suma; |
.................... int1 tmp; |
.................... int8 datovy; |
.................... |
.................... decoder: |
.................... |
.................... if (prijmi_nibble(&datovy,&kanal)) goto decoder; |
.................... if (datovy) goto decoder; |
.................... |
.................... // if (kanal!=15) {e1++; goto decoder;}; |
.................... if (prijmi_nibble(&datovy, &kanal)) goto decoder; // nacti identifikator osy |
.................... |
.................... if (prijmi_nibble(&datovy, &data)) goto decoder; // nacti 1. nibble; pri chybe zacni znovu |
.................... if (prijmi_nibble(&datovy, &suma)) goto decoder; // nacti 2. nibble; pri chybe zacni znovu |
.................... if (((kanal+data) & 0b1111) != suma) {e1++; goto decoder;} // zacni znovu, pokud jsou ruzne nibble |
.................... |
.................... */ |
.................... e = prijmi_ramec(&kanal,&data); |
01F5: MOVLW 16 |
01F6: MOVWF 19 |
01F7: MOVLW 17 |
01F8: MOVWF 1A |
01F9: GOTO 12B |
01FA: MOVF 0D,W |
01FB: MOVWF 18 |
.................... //lcd_gotoxy(1,1); |
.................... //printf(lcd_putc,"Q:%3U %3U %3U ",kanal,data,e); |
.................... //delay_ms(1000); |
.................... if (!e) |
01FC: MOVF 18,F |
01FD: BTFSS 03.2 |
01FE: GOTO 210 |
.................... switch (kanal) // rozeskoc se podle adresy osy |
01FF: MOVLW 01 |
0200: SUBWF 16,W |
0201: ADDLW FD |
0202: BTFSC 03.0 |
0203: GOTO 210 |
0204: ADDLW 03 |
0205: GOTO 2A8 |
.................... { |
.................... case OSA_X: |
.................... { |
.................... x=data; |
0206: MOVF 17,W |
0207: MOVWF 0E |
.................... xc++; |
0208: INCF 10,F |
.................... break; |
0209: GOTO 210 |
.................... }; |
.................... case OSA_Y: |
.................... { |
.................... y=data; |
020A: MOVF 17,W |
020B: MOVWF 0F |
.................... yc++; |
020C: INCF 11,F |
.................... break; |
020D: GOTO 210 |
.................... }; |
.................... case TLs: |
.................... { |
.................... e4++; |
020E: INCF 15,F |
.................... break; |
020F: GOTO 210 |
.................... }; |
.................... }; |
* |
02A8: BCF 0A.0 |
02A9: BSF 0A.1 |
02AA: BCF 0A.2 |
02AB: ADDWF 02,F |
02AC: GOTO 206 |
02AD: GOTO 20A |
02AE: GOTO 20E |
.................... |
.................... // ladici vypisy |
.................... lcd_gotoxy(1,1); // vytiskni X a Y |
* |
0210: MOVLW 01 |
0211: MOVWF 1C |
0212: MOVWF 1D |
0213: CALL 08F |
.................... printf(lcd_putc,"X%2U %3U%3U%3U ", x, xc, e1, e); |
* |
019C: MOVF 0D,W |
019D: MOVF 19,W |
019E: MOVWF 1B |
019F: MOVLW 64 |
01A0: MOVWF 1C |
01A1: CALL 187 |
01A2: MOVF 0C,W |
01A3: MOVWF 19 |
01A4: MOVF 0D,W |
01A5: MOVLW 30 |
01A6: BTFSS 03.2 |
01A7: GOTO 1AF |
01A8: BTFSC 1A.0 |
01A9: BSF 1A.3 |
01AA: BTFSC 1A.3 |
01AB: GOTO 1B5 |
01AC: BTFSC 1A.4 |
01AD: MOVLW 20 |
01AE: GOTO 1B1 |
01AF: BCF 1A.3 |
01B0: BCF 1A.4 |
01B1: ADDWF 0D,F |
01B2: MOVF 0D,W |
01B3: MOVWF 1B |
01B4: CALL 0A0 |
01B5: MOVF 19,W |
01B6: MOVWF 1B |
01B7: MOVLW 0A |
01B8: MOVWF 1C |
01B9: CALL 187 |
01BA: MOVF 0C,W |
01BB: MOVWF 19 |
01BC: MOVF 0D,W |
01BD: MOVLW 30 |
01BE: BTFSS 03.2 |
01BF: GOTO 1C4 |
01C0: BTFSC 1A.3 |
01C1: GOTO 1C8 |
01C2: BTFSC 1A.4 |
01C3: MOVLW 20 |
01C4: ADDWF 0D,F |
01C5: MOVF 0D,W |
01C6: MOVWF 1B |
01C7: CALL 0A0 |
01C8: MOVLW 30 |
01C9: ADDWF 19,F |
01CA: MOVF 19,W |
01CB: MOVWF 1B |
01CC: CALL 0A0 |
01CD: RETLW 00 |
* |
0214: MOVLW 58 |
0215: MOVWF 1B |
0216: CALL 0A0 |
0217: MOVF 0E,W |
0218: MOVWF 19 |
0219: MOVLW 11 |
021A: MOVWF 1A |
021B: CALL 19C |
021C: MOVLW 20 |
021D: MOVWF 1B |
021E: CALL 0A0 |
021F: MOVF 10,W |
0220: MOVWF 19 |
0221: MOVLW 10 |
0222: MOVWF 1A |
0223: CALL 19C |
0224: MOVF 12,W |
0225: MOVWF 19 |
0226: MOVLW 10 |
0227: MOVWF 1A |
0228: CALL 19C |
0229: MOVF 18,W |
022A: MOVWF 19 |
022B: MOVLW 10 |
022C: MOVWF 1A |
022D: CALL 19C |
022E: MOVLW 20 |
022F: MOVWF 1B |
0230: CALL 0A0 |
0231: MOVLW 20 |
0232: MOVWF 1B |
0233: CALL 0A0 |
.................... lcd_gotoxy(1,2); |
0234: MOVLW 01 |
0235: MOVWF 1C |
0236: MOVLW 02 |
0237: MOVWF 1D |
0238: CALL 08F |
.................... printf(lcd_putc,"Y%2U %3U%3U%3U ", y, yc, e3, data); |
0239: MOVLW 59 |
023A: MOVWF 1B |
023B: CALL 0A0 |
023C: MOVF 0F,W |
023D: MOVWF 19 |
023E: MOVLW 11 |
023F: MOVWF 1A |
0240: CALL 19C |
0241: MOVLW 20 |
0242: MOVWF 1B |
0243: CALL 0A0 |
0244: MOVF 11,W |
0245: MOVWF 19 |
0246: MOVLW 10 |
0247: MOVWF 1A |
0248: CALL 19C |
0249: MOVF 14,W |
024A: MOVWF 19 |
024B: MOVLW 10 |
024C: MOVWF 1A |
024D: CALL 19C |
024E: MOVF 17,W |
024F: MOVWF 19 |
0250: MOVLW 10 |
0251: MOVWF 1A |
0252: CALL 19C |
0253: MOVLW 20 |
0254: MOVWF 1B |
0255: CALL 0A0 |
0256: MOVLW 20 |
0257: MOVWF 1B |
0258: CALL 0A0 |
.................... |
.................... // ovladani serv |
.................... output_high(SERVO_X); |
0259: BSF 03.5 |
025A: BCF 05.0 |
025B: BCF 03.5 |
025C: BSF 05.0 |
.................... delay_ms(1); |
025D: MOVLW 01 |
025E: MOVWF 1C |
025F: CALL 015 |
.................... for (data=x; data--; data>0) |
0260: MOVF 0E,W |
0261: MOVWF 17 |
0262: MOVF 17,W |
0263: DECF 17,F |
0264: XORLW 00 |
0265: BTFSC 03.2 |
0266: GOTO 271 |
.................... delay_us(65); |
0267: MOVLW 15 |
0268: MOVWF 0C |
0269: DECFSZ 0C,F |
026A: GOTO 269 |
026B: NOP |
026C: MOVF 17,F |
026D: BTFSS 03.2 |
026E: GOTO 270 |
026F: MOVLW 00 |
0270: GOTO 262 |
.................... output_low(SERVO_X); |
0271: BSF 03.5 |
0272: BCF 05.0 |
0273: BCF 03.5 |
0274: BCF 05.0 |
.................... |
.................... output_high(SERVO_Y); |
0275: BSF 03.5 |
0276: BCF 05.1 |
0277: BCF 03.5 |
0278: BSF 05.1 |
.................... delay_ms(1); |
0279: MOVLW 01 |
027A: MOVWF 1C |
027B: CALL 015 |
.................... for (data=y; data--; data>0) |
027C: MOVF 0F,W |
027D: MOVWF 17 |
027E: MOVF 17,W |
027F: DECF 17,F |
0280: XORLW 00 |
0281: BTFSC 03.2 |
0282: GOTO 28D |
.................... delay_us(65); |
0283: MOVLW 15 |
0284: MOVWF 0C |
0285: DECFSZ 0C,F |
0286: GOTO 285 |
0287: NOP |
0288: MOVF 17,F |
0289: BTFSS 03.2 |
028A: GOTO 28C |
028B: MOVLW 00 |
028C: GOTO 27E |
.................... output_low(SERVO_Y); |
028D: BSF 03.5 |
028E: BCF 05.1 |
028F: BCF 03.5 |
0290: BCF 05.1 |
.................... |
.................... for (data=30-x-y; data--; data>0) |
0291: MOVF 0E,W |
0292: SUBLW 1E |
0293: MOVWF 0D |
0294: MOVF 0F,W |
0295: SUBWF 0D,W |
0296: MOVWF 17 |
0297: MOVF 17,W |
0298: DECF 17,F |
0299: XORLW 00 |
029A: BTFSC 03.2 |
029B: GOTO 2A6 |
.................... delay_us(65); |
029C: MOVLW 15 |
029D: MOVWF 0C |
029E: DECFSZ 0C,F |
029F: GOTO 29E |
02A0: NOP |
02A1: MOVF 17,F |
02A2: BTFSS 03.2 |
02A3: GOTO 2A5 |
02A4: MOVLW 00 |
02A5: GOTO 297 |
.................... |
.................... } |
02A6: GOTO 1F5 |
.................... } |
.................... |
02A7: SLEEP |
.................... |
.................... |