Rev 2 | Blame | Last modification | View Log | Download
CCS PCW C Compiler, Version 3.110, 15448
Filename: d:\kaklik\programy\pic_c\robot\tank\main.LST
ROM used: 893 (22%)
Largest free fragment is 2048
RAM used: 82 (43%) at main() level
101 (53%) worst case
Stack: 3 locations
*
0000: MOVLW 00
0001: MOVWF 0A
0002: GOTO 2CB
0003: NOP
.................... #include "D:\@KAKLIK\programy\PIC_C\robot\tank\main.h"
.................... #include <16F873.h>
.................... //////// Standard Header file for the PIC16F873 device ////////////////
.................... #device PIC16F873
.................... #list
....................
.................... #use delay(clock=4000000)
00A8: MOVLW 73
00A9: MOVWF 04
00AA: MOVF 00,W
00AB: BTFSC 03.2
00AC: GOTO 0BC
00AD: MOVLW 01
00AE: MOVWF 21
00AF: CLRF 20
00B0: DECFSZ 20,F
00B1: GOTO 0B0
00B2: DECFSZ 21,F
00B3: GOTO 0AF
00B4: MOVLW 4A
00B5: MOVWF 20
00B6: DECFSZ 20,F
00B7: GOTO 0B6
00B8: NOP
00B9: NOP
00BA: DECFSZ 00,F
00BB: GOTO 0AD
00BC: RETLW 00
.................... #fuses XT,NOWDT,NOLVP
....................
....................
....................
.................... //motory
.................... #define FR output_high(PIN_B4);output_low(PIN_B5) // Vpred
.................... #define FL output_high(PIN_B6);output_low(PIN_B7)
.................... #define BR output_high(PIN_B5);output_low(PIN_B4) // Vzad
.................... #define BL output_high(PIN_B7);output_low(PIN_B6)
.................... #define STOPR output_low(PIN_B4);output_low(PIN_B5)
.................... #define STOPL output_low(PIN_B6);output_low(PIN_B7)
....................
.................... //cidla
.................... #define RSENSOR 1 // Senzory na caru
.................... #define LSENSOR 0
.................... //#define BUMPER SENSOR_2 // Senzor na cihlu
....................
.................... //human interface
.................... #DEFINE LED PIN_A2
....................
.................... #DEFINE SOUND_HI PIN_B2
.................... #DEFINE SOUND_LO PIN_B3
.................... #include "sound.c"
.................... // Knihovna pro generovani hudebnich zvuku dane frekvence a delky nebo
.................... // dane noty temperovaneho ladeni a delky.
.................... //
.................... // Pro gnerovani nepouziva zadnou podporu HW, vse se generuje ciste SW.
.................... //
.................... // (c)miho 2003
.................... //
.................... // Historie
.................... // 1.00 Uvodni verze
.................... //
....................
....................
.................... // Konfiguracni parametry
.................... //#define SOUND_HI PIN_xx // Pozitivni vystup
.................... //#define SOUND_LO PIN_xx // Komplementarni vystup
.................... #ifndef SOUND_REZIE
.................... #define SOUND_REZIE 72 // Piskvorcova konstanta zahrnuje celkovou rezii ve smycce
.................... #endif
.................... #ifndef SOUND_CLOCK
.................... #define SOUND_CLOCK 4000000 // Frelvence krystalu v Hz
.................... #endif
....................
....................
.................... // Definice hudebnich tonu (not) pro proceduru SoundNote()
.................... #define SOUND_C 0
.................... #define SOUND_Cis 1
.................... #define SOUND_D 2
.................... #define SOUND_Dis 3
.................... #define SOUND_E 4
.................... #define SOUND_F 5
.................... #define SOUND_Fis 6
.................... #define SOUND_G 7
.................... #define SOUND_Gis 8
.................... #define SOUND_A 9
.................... #define SOUND_Ais 10
.................... #define SOUND_H 11
.................... #define SOUND_Space 12 // Pomlka
....................
....................
.................... // Prototypy verejnych procedur
....................
.................... void SoundBeep(unsigned int16 Frequency, unsigned int16 Duration);
.................... // Predava se frekvence v Hz a doba trvani v ms (0 znamena ticho)
....................
.................... void SoundNote(unsigned int8 Note, Octave, unsigned int16 Duration);
.................... // Predava se cislo noty (0 je C), posunuti v oktavach (0 nejnizsi ton,
.................... // SOUND_Space je ticho), doba trvani v ms
....................
.................... // Alternativni makra pro generovani konstatnich tonu
.................... // SoundBeepMacro(Frequency, Duration) - frekvence nesmi byt 0
.................... // SoundNoteMacro(Note, Octave, Duration) - nepodporuje SOUND_Space
.................... // SoundSpaceMacro(Duration) - hraje ticho
....................
.................... // Privatni cast
....................
....................
.................... #ORG 0x100, 0x128 // Aby skok nebyl pres hranici 0x100
.................... void DelaySpecial(unsigned int16 Time)
.................... // Pomocna procedura pro mereni spozdeni s granularitou 1 instrukcni takt
.................... // Cas v instrukcnich cyklech, skutecny cas je vetsi o _konstantni_ rezii
.................... // Maximalni cas je 65536 us
.................... {
.................... unsigned int8 TimeHi; // Pro pristup k horni casti Time
....................
.................... *0x0A = LABEL_ADDRESS(Next)>>8; // Nastav PCLATH
*
0100: MOVLW 01
0101: MOVWF 23
0102: MOVLW 0A
0103: MOVWF 7E
0104: MOVF 23,W
0105: MOVWF 0A
.................... #asm
.................... movf Time,w // Zpracuj nejnizsi 3 bity
0106: MOVF 7B,W
.................... xorlw 7 // Pro hodnotu 0 skakej pres vsechny nopy
0107: XORLW 07
.................... andlw 7 // Ber jen spodni 3 bity
0108: ANDLW 07
.................... addwf 2,f // Preskoc zadny az vsech 8 nopu (2 je PCL)
0109: ADDWF 02,F
.................... Next:
.................... nop // Spozdeni s granularitou 1 takt
010A: NOP
.................... nop
010B: NOP
.................... nop
010C: NOP
.................... nop
010D: NOP
.................... nop
010E: NOP
.................... nop
010F: NOP
.................... nop
0110: NOP
.................... nop
.................... #endasm
0111: NOP
.................... Time = Time >> 3; // Zahod spodni 3 bity
0112: RRF 7C,F
0113: RRF 7B,F
0114: RRF 7C,F
0115: RRF 7B,F
0116: RRF 7C,F
0117: RRF 7B,F
0118: MOVLW 1F
0119: ANDWF 7C,F
.................... TimeHi=Time>>8; // Oddel horni cast citace
011A: MOVF 7C,W
011B: MOVWF 7D
.................... Time++; // Korekce na casovani typu dcfsz
011C: INCF 7B,F
011D: BTFSC 03.2
011E: INCF 7C,F
.................... TimeHi++;
011F: INCF 7D,F
.................... #asm
.................... Loop:
.................... nop // Smycka musi trvat 8 taktu
0120: NOP
.................... nop // a ma 16 bitu dlouhy citac
0121: NOP
.................... nop
0122: NOP
.................... decfsz Time
0123: DECFSZ 7B,F
.................... goto Next1
0124: GOTO 126
.................... decfsz TimeHi
0125: DECFSZ 7D,F
.................... Next1:
.................... goto Loop
.................... #endasm
0126: GOTO 120
0127: RETLW 00
....................
.................... }
....................
....................
.................... unsigned int32 SoundCount; // Pocet pulperid geneovaneho signalu
.................... unsigned int32 SoundPeriod; // Delka pulperiody v us (zmensene o SOUND_REZIE)
....................
....................
.................... void SoundLoop()
.................... // Pomocna funkce - hlavni zvukova smycka
.................... {
.................... int1 Data;
.................... unsigned int16 i;
....................
.................... for(i=SoundCount;i>0;i--) // Pocet pulperiod
*
019F: MOVF 26,W
01A0: MOVWF 78
01A1: MOVF 25,W
01A2: MOVWF 77
01A3: MOVF 77,F
01A4: BTFSS 03.2
01A5: GOTO 1A9
01A6: MOVF 78,F
01A7: BTFSC 03.2
01A8: GOTO 1C9
.................... {
.................... output_bit(SOUND_HI,Data); // Nastav vystup
01A9: BTFSC 76.0
01AA: GOTO 1AD
01AB: BCF 06.2
01AC: GOTO 1AE
01AD: BSF 06.2
01AE: BSF 03.5
01AF: BCF 06.2
.................... output_bit(SOUND_LO,~Data);
01B0: BCF 03.5
01B1: BTFSS 76.0
01B2: GOTO 1B5
01B3: BCF 06.3
01B4: GOTO 1B6
01B5: BSF 06.3
01B6: BSF 03.5
01B7: BCF 06.3
.................... Data=~Data; // Otoc stav vystupu
01B8: MOVLW 01
01B9: BCF 03.5
01BA: XORWF 76,F
.................... DelaySpecial(SoundPeriod); // Pockej po dobu plperiody
01BB: MOVF 2A,W
01BC: MOVWF 7A
01BD: MOVF 29,W
01BE: MOVWF 79
01BF: MOVF 2A,W
01C0: MOVWF 7C
01C1: MOVF 29,W
01C2: MOVWF 7B
01C3: CALL 100
.................... }
01C4: MOVF 77,W
01C5: BTFSC 03.2
01C6: DECF 78,F
01C7: DECF 77,F
01C8: GOTO 1A3
.................... }
....................
....................
.................... void SoundBeep(unsigned int16 Frequency, unsigned int16 Duration)
.................... // Predava se frekvence v Hz a doba trvani v ms (0 znamena ticho)
.................... // Rozumne frekvence jsou v rozsahu cca 10Hz az 5000Hz pro krystal 4MHz,
.................... // cas do cca 5s (2*Cas/1000*Freq musi byt < nez 65536)
.................... {
.................... if (Frequency==0)
*
0129: MOVF 72,F
012A: BTFSS 03.2
012B: GOTO 140
012C: MOVF 73,F
012D: BTFSS 03.2
012E: GOTO 140
.................... {
.................... for(;Duration>0;Duration--)
012F: MOVF 74,F
0130: BTFSS 03.2
0131: GOTO 135
0132: MOVF 75,F
0133: BTFSC 03.2
0134: GOTO 13F
.................... {
.................... DelaySpecial(1000); // Zhruba 1ms
0135: MOVLW 03
0136: MOVWF 7C
0137: MOVLW E8
0138: MOVWF 7B
0139: CALL 100
.................... }
013A: MOVF 74,W
013B: BTFSC 03.2
013C: DECF 75,F
013D: DECF 74,F
013E: GOTO 12F
.................... return;
013F: GOTO 1C9
.................... }
....................
.................... SoundPeriod=(SOUND_CLOCK/4/2)/Frequency-SOUND_REZIE;
0140: CLRF 79
0141: MOVLW 07
0142: MOVWF 78
0143: MOVLW A1
0144: MOVWF 77
0145: MOVLW 20
0146: MOVWF 76
0147: CLRF 7D
0148: CLRF 7C
0149: MOVF 73,W
014A: MOVWF 7B
014B: MOVF 72,W
014C: MOVWF 7A
014D: CALL 004
014E: MOVF 23,W
014F: MOVWF 79
0150: MOVF 22,W
0151: MOVWF 78
0152: MOVF 21,W
0153: MOVWF 77
0154: MOVF 20,W
0155: MOVWF 76
0156: MOVLW 48
0157: SUBWF 76,W
0158: MOVWF 29
0159: MOVF 77,W
015A: MOVWF 2A
015B: MOVLW 00
015C: BTFSS 03.0
015D: MOVLW 01
015E: SUBWF 2A,F
015F: MOVF 78,W
0160: MOVWF 2B
0161: MOVLW 00
0162: BTFSS 03.0
0163: MOVLW 01
0164: SUBWF 2B,F
0165: MOVF 79,W
0166: MOVWF 2C
0167: MOVLW 00
0168: BTFSS 03.0
0169: MOVLW 01
016A: SUBWF 2C,F
....................
.................... SoundCount=Duration; // Vypocet poctu pulperiod signalu Duration*Frequency*2/1000
016B: CLRF 28
016C: CLRF 27
016D: MOVF 75,W
016E: MOVWF 26
016F: MOVF 74,W
0170: MOVWF 25
.................... SoundCount*=Frequency;
0171: MOVF 28,W
0172: MOVWF 79
0173: MOVF 27,W
0174: MOVWF 78
0175: MOVF 26,W
0176: MOVWF 77
0177: MOVF 25,W
0178: MOVWF 76
0179: CLRF 7D
017A: CLRF 7C
017B: MOVF 73,W
017C: MOVWF 7B
017D: MOVF 72,W
017E: MOVWF 7A
017F: GOTO 066
0180: MOVF 23,W
0181: MOVWF 28
0182: MOVF 22,W
0183: MOVWF 27
0184: MOVF 21,W
0185: MOVWF 26
0186: MOVF 20,W
0187: MOVWF 25
.................... SoundCount/=500;
0188: MOVF 28,W
0189: MOVWF 79
018A: MOVF 27,W
018B: MOVWF 78
018C: MOVF 26,W
018D: MOVWF 77
018E: MOVF 25,W
018F: MOVWF 76
0190: CLRF 7D
0191: CLRF 7C
0192: MOVLW 01
0193: MOVWF 7B
0194: MOVLW F4
0195: MOVWF 7A
0196: CALL 004
0197: MOVF 23,W
0198: MOVWF 28
0199: MOVF 22,W
019A: MOVWF 27
019B: MOVF 21,W
019C: MOVWF 26
019D: MOVF 20,W
019E: MOVWF 25
....................
.................... SoundLoop(); // Pozor pouzivaji se globalni parametry
*
01C9: RETLW 00
.................... }
....................
.................... // Definice casu pulperody pro nejnizsi oktavu, v mikrosekundach
.................... // Periody tonu v dalsich oktavach se ziskavaji rotaci vpravo
.................... #define SOUND_Peri_C (30578*(SOUND_CLOCK/1000)/1000/4/2) // Perioda 30578us
.................... #define SOUND_Peri_Cis (28862*(SOUND_CLOCK/1000)/1000/4/2) // Perioda 28862us
.................... #define SOUND_Peri_D (27242*(SOUND_CLOCK/1000)/1000/4/2) // Perioda 27242us
.................... #define SOUND_Peri_Dis (25713*(SOUND_CLOCK/1000)/1000/4/2) // Perioda 25713us
.................... #define SOUND_Peri_E (24270*(SOUND_CLOCK/1000)/1000/4/2) // Perioda 24270us
.................... #define SOUND_Peri_F (22908*(SOUND_CLOCK/1000)/1000/4/2) // Perioda 22908us
.................... #define SOUND_Peri_Fis (21622*(SOUND_CLOCK/1000)/1000/4/2) // Perioda 21622us
.................... #define SOUND_Peri_G (20408*(SOUND_CLOCK/1000)/1000/4/2) // Perioda 20408us
.................... #define SOUND_Peri_Gis (19263*(SOUND_CLOCK/1000)/1000/4/2) // Perioda 19263us
.................... #define SOUND_Peri_A (18182*(SOUND_CLOCK/1000)/1000/4/2) // Perioda 18182us
.................... #define SOUND_Peri_Ais (17161*(SOUND_CLOCK/1000)/1000/4/2) // Perioda 17161us
.................... #define SOUND_Peri_H (16198*(SOUND_CLOCK/1000)/1000/4/2) // Perioda 16198us
....................
.................... #if SOUND_Peri_C > 65535
.................... #error "Sound Clock too high (Note C requires delay > 65535 cycles)"
.................... #endif
....................
.................... const int16 Table[12] = SOUND_Peri_C, SOUND_Peri_Cis, SOUND_Peri_D, SOUND_Peri_Dis,
.................... SOUND_Peri_E, SOUND_Peri_F, SOUND_Peri_Fis, SOUND_Peri_G,
.................... SOUND_Peri_Gis, SOUND_Peri_A, SOUND_Peri_Ais, SOUND_Peri_H;
....................
.................... void SoundNote(unsigned int8 Note, Octave, unsigned int16 Duration)
.................... // Predava se cislo noty (0 je C), posunuti v oktavach (0 nejnizsi ton)
.................... // doba trvani v ms (0 znamena ticho)
.................... // Zahraje zadanou notu v zadane oktave dane delky
.................... {
....................
.................... if (Note==SOUND_Space)
.................... {
.................... for(;Duration>0;Duration--)
.................... DelaySpecial(1000); // Zhruba 1ms
.................... return;
.................... }
....................
.................... SoundPeriod=(Table[Note]>>Octave)-0; // Zde je chyba prekladace, nula musi zusat
....................
.................... SoundCount=Duration;
.................... SoundCount*=1000;
.................... SoundCount/=SoundPeriod;
....................
.................... SoundPeriod=SoundPeriod-SOUND_REZIE;
....................
.................... SoundLoop(); // Pozor pouzivaji se globalni parametry
.................... }
....................
....................
.................... // Sada maker, ktera neobsahuji slozity vypocet a jsou
.................... // tedy vhodna pro jednoduche pipnuti. Parametry jsou stejne
.................... // jako o funkci.
.................... #define SoundBeepMacro(F,D) \
.................... SoundPeriod=SOUND_CLOCK/4/2/F-SOUND_REZIE; \
.................... SoundCount=D*F/500; \
.................... SoundLoop();
....................
.................... #define SoundNoteMacro(N,O,D) \
.................... SoundPeriod=(Table[N]>>O)-SOUND_REZIE; \
.................... SoundCount=D*1000/(Table[N]>>O); \
.................... SoundLoop();
....................
.................... #define SoundPauseMacro(D) \
.................... { \
.................... #if D>255 \
.................... unsigned int16 i=D; \
.................... #else \
.................... unsigned int8 i=D; \
.................... #endif \
.................... for(;i>0;i--) \
.................... { \
.................... DelaySpecial(1000); \
.................... } \
.................... }
....................
....................
.................... #DEFINE TXo PIN_C0 // Vysilac
.................... #include "C:\library\kaklik\CCS\AX25.c" // Podprogram pro prenos telemetrie
.................... //#define PTT PIN_A2 // PTT control
.................... //#define TXo PIN_C0 // To the transmitter modulator
.................... #define PERIODAH delay_us(222) // Halfperiod H 222;78/1200 500;430/500
.................... #define TAILH delay_us(78)
.................... #define PERIODAL delay_us(412) // Halfperiod L 412;345/1200 1000;880/500
.................... #define TAILL delay_us(345)
.................... #byte STATUS = 3 // CPUs status register
....................
.................... byte SendData[16] = {'A'<<1, 'L'<<1, 'L'<<1, ' '<<1, ' '<<1, ' '<<1, 0x60,
.................... 'C'<<1, 'Z'<<1, '0'<<1, 'R'<<1, 'R'<<1, 'R'<<1, 0x61,
.................... 0x03, 0xF0};
....................
.................... boolean bit;
.................... int fcslo, fcshi; // variabloes for calculating FCS (CRC)
.................... int stuff; // stuff counter for extra 0
.................... int flag_flag; // if it is sending flag (7E)
.................... int fcs_flag; // if it is sending Frame Check Sequence
.................... int i; // for for
....................
.................... void flipout() //flips the state of output pin a_1
.................... {
.................... stuff = 0; //since this is a 0, reset the stuff counter
.................... if (bit)
.................... {
.................... bit=FALSE; //if the state of the pin was low, make it high.
.................... }
.................... else
.................... {
.................... bit=TRUE; //if the state of the pin was high make it low
.................... }
.................... }
....................
.................... void fcsbit(byte tbyte)
.................... {
.................... #asm
.................... BCF STATUS,0
.................... RRF fcshi,F // rotates the entire 16 bits
.................... RRF fcslo,F // to the right
.................... #endasm
.................... if (((STATUS & 0x01)^(tbyte)) ==0x01)
.................... {
.................... fcshi = fcshi^0x84;
.................... fcslo = fcslo^0x08;
.................... }
.................... }
....................
.................... void SendBit ()
.................... {
.................... if (bit)
.................... {
.................... output_high(TXo);
.................... PERIODAH;
.................... output_low(TXo);
.................... PERIODAH;
.................... output_high(TXo);
.................... PERIODAH;
.................... output_low(TXo);
.................... TAILH;
.................... }
.................... else
.................... {
.................... output_high(TXo);
.................... PERIODAL;
.................... output_low(TXo);
.................... TAILL;
.................... };
.................... }
....................
.................... void SendByte (byte inbyte)
.................... {
.................... int k, bt;
....................
.................... for (k=0;k<8;k++) //do the following for each of the 8 bits in the byte
.................... {
.................... bt = inbyte & 0x01; //strip off the rightmost bit of the byte to be sent (inbyte)
.................... if ((fcs_flag == FALSE) & (flag_flag == FALSE)) fcsbit(bt); //do FCS calc, but only if this
.................... //is not a flag or fcs byte
.................... if (bt == 0)
.................... {
.................... flipout();
.................... } // if this bit is a zero, flip the output state
.................... else
.................... { //otherwise if it is a 1, do the following:
.................... if (flag_flag == FALSE) stuff++; //increment the count of consequtive 1's
.................... if ((flag_flag == FALSE) & (stuff == 5))
.................... { //stuff an extra 0, if 5 1's in a row
.................... SendBit();
.................... flipout(); //flip the output state to stuff a 0
.................... }//end of if
.................... }//end of else
.................... // delay_us(850); //introduces a delay that creates 1200 baud
.................... SendBit();
.................... inbyte = inbyte>>1; //go to the next bit in the byte
.................... }//end of for
.................... }//end of SendByte
....................
.................... void SendPacket(char *data)
.................... {
.................... bit=FALSE;
....................
.................... fcslo=fcshi=0xFF; //The 2 FCS Bytes are initialized to FF
.................... stuff = 0; //The variable stuff counts the number of 1's in a row. When it gets to 5
.................... // it is time to stuff a 0.
....................
.................... // output_low(PTT); // Blinking LED
.................... // delay_ms(1000);
.................... // output_high(PTT);
....................
.................... flag_flag = TRUE; //The variable flag is true if you are transmitted flags (7E's) false otherwise.
.................... fcs_flag = FALSE; //The variable fcsflag is true if you are transmitting FCS bytes, false otherwise.
....................
.................... for(i=0; i<10; i++) SendByte(0x7E); //Sends flag bytes. Adjust length for txdelay
.................... //each flag takes approx 6.7 ms
.................... flag_flag = FALSE; //done sending flags
....................
.................... for(i=0; i<16; i++) SendByte(SendData[i]); //send the packet bytes
....................
.................... for(i=0; 0 != *data; i++)
.................... {
.................... SendByte(*data); //send the packet bytes
.................... data++;
.................... };
....................
.................... fcs_flag = TRUE; //about to send the FCS bytes
.................... fcslo =fcslo^0xff; //must XOR them with FF before sending
.................... fcshi = fcshi^0xff;
.................... SendByte(fcslo); //send the low byte of fcs
.................... SendByte(fcshi); //send the high byte of fcs
.................... fcs_flag = FALSE; //done sending FCS
.................... flag_flag = TRUE; //about to send flags
.................... SendByte(0x7e); // Send a flag to end packet
.................... }
....................
....................
....................
....................
....................
.................... //program
.................... #define MEZERA 38 // jak se muze jet dlouho bez cary
.................... #define COUVEJ 700 // kolik se ma couvat po detekci diry
.................... #define CIKCAK 40 // kolik se ma jet cik/cak
.................... #define PRES_DIRU 350 // jak predpokladame velkou diru
.................... #define TRESHOLD 50
....................
.................... #define L 0 // left
.................... #define R 1 // right
.................... #define S 2 // straight
....................
.................... char AXstring[40]; // Buffer pro prenos telemetrie
....................
.................... int movement; // smer minuleho pohybu
.................... int line; // na ktere strane byla detekovana cara
.................... int dira; // pocitadlo pro nalezeni preruseni cary
.................... int n; // pomocna promena pro cyklus FOR
....................
.................... void cik_cak() // Hledani cary
.................... {
.................... n=CIKCAK/2; // poprve hned zatoc opacne, nez se jelo pred detekci diry
.................... switch(movement) // zmenime smer zataceni
.................... {
.................... case L:
.................... FL;STOPR; // doprava
.................... movement=R; // poznamenej kam jedem
.................... line=L; // kdyz prejedem, tak bude cara vlevo
.................... break;
.................... case R:
.................... FR;STOPL; // doleva
.................... movement=L; // poznamenej kam jedem
.................... line=R; // kdyz prejedem, tak bude cara vpravo
.................... break;
.................... }
....................
.................... while(true) // jed cik-cak, dokud nenajdes caru
.................... {
.................... set_adc_channel(RSENSOR);
.................... if (TRESHOLD > read_adc()) // je cara ??
.................... {
.................... STOPL;
.................... STOPR;
.................... break;
.................... };
.................... if (CIKCAK < n++) // Jedeme uz dost dlouho cik??Pak jed cak.
.................... {
.................... n=0;
.................... STOPL;
.................... STOPR;
.................... switch(movement) // zmenime smer zataceni
.................... {
.................... case L:
.................... FL; // doprava
.................... movement=R; // poznamenej kam jedem
.................... line=L; // kdyz prejedem, tak bude cara vlevo
.................... break;
.................... case R:
.................... FR; // doleva
.................... movement=L; // poznamenej kam jedem
.................... line=R; // kdyz prejedem, tak bude cara vpravo
.................... break;
.................... }
.................... }
.................... }
.................... }
....................
....................
.................... void diagnostika()
.................... {
.................... int n;
....................
.................... while (input(PIN_C4))
01CA: BSF 44.4
01CB: MOVF 44,W
01CC: BSF 03.5
01CD: MOVWF 07
01CE: BCF 03.5
01CF: BTFSS 07.4
01D0: GOTO 2C9
.................... {
....................
.................... for (n=500; n<5000; n+=100)
01D1: MOVLW F4
01D2: MOVWF 71
.................... {
.................... SoundBeep(n,50); //beep
01D3: CLRF 73
01D4: MOVF 71,W
01D5: MOVWF 72
01D6: CLRF 75
01D7: MOVLW 32
01D8: MOVWF 74
01D9: CALL 129
.................... };
01DA: MOVLW 64
01DB: ADDWF 71,F
01DC: GOTO 1D3
.................... Delay_ms(1000);
01DD: MOVLW 04
01DE: MOVWF 72
01DF: MOVLW FA
01E0: MOVWF 73
01E1: CALL 0A8
01E2: DECFSZ 72,F
01E3: GOTO 1DF
....................
.................... STOPL; //zastav vse
01E4: BSF 03.5
01E5: BCF 06.6
01E6: BCF 03.5
01E7: BCF 06.6
01E8: BSF 03.5
01E9: BCF 06.7
01EA: BCF 03.5
01EB: BCF 06.7
.................... STOPR;
01EC: BSF 03.5
01ED: BCF 06.4
01EE: BCF 03.5
01EF: BCF 06.4
01F0: BSF 03.5
01F1: BCF 06.5
01F2: BCF 03.5
01F3: BCF 06.5
....................
.................... FR; //pravy pas
01F4: BSF 03.5
01F5: BCF 06.4
01F6: BCF 03.5
01F7: BSF 06.4
01F8: BSF 03.5
01F9: BCF 06.5
01FA: BCF 03.5
01FB: BCF 06.5
.................... Delay_ms(1000);
01FC: MOVLW 04
01FD: MOVWF 72
01FE: MOVLW FA
01FF: MOVWF 73
0200: CALL 0A8
0201: DECFSZ 72,F
0202: GOTO 1FE
.................... STOPR;
0203: BSF 03.5
0204: BCF 06.4
0205: BCF 03.5
0206: BCF 06.4
0207: BSF 03.5
0208: BCF 06.5
0209: BCF 03.5
020A: BCF 06.5
.................... Delay_ms(1000);
020B: MOVLW 04
020C: MOVWF 72
020D: MOVLW FA
020E: MOVWF 73
020F: CALL 0A8
0210: DECFSZ 72,F
0211: GOTO 20D
.................... BR;
0212: BSF 03.5
0213: BCF 06.5
0214: BCF 03.5
0215: BSF 06.5
0216: BSF 03.5
0217: BCF 06.4
0218: BCF 03.5
0219: BCF 06.4
.................... Delay_ms(1000);
021A: MOVLW 04
021B: MOVWF 72
021C: MOVLW FA
021D: MOVWF 73
021E: CALL 0A8
021F: DECFSZ 72,F
0220: GOTO 21C
.................... STOPR;
0221: BSF 03.5
0222: BCF 06.4
0223: BCF 03.5
0224: BCF 06.4
0225: BSF 03.5
0226: BCF 06.5
0227: BCF 03.5
0228: BCF 06.5
.................... Delay_ms(1000);
0229: MOVLW 04
022A: MOVWF 72
022B: MOVLW FA
022C: MOVWF 73
022D: CALL 0A8
022E: DECFSZ 72,F
022F: GOTO 22B
....................
.................... FL; //levy pas
0230: BSF 03.5
0231: BCF 06.6
0232: BCF 03.5
0233: BSF 06.6
0234: BSF 03.5
0235: BCF 06.7
0236: BCF 03.5
0237: BCF 06.7
.................... Delay_ms(1000);
0238: MOVLW 04
0239: MOVWF 72
023A: MOVLW FA
023B: MOVWF 73
023C: CALL 0A8
023D: DECFSZ 72,F
023E: GOTO 23A
.................... STOPL;
023F: BSF 03.5
0240: BCF 06.6
0241: BCF 03.5
0242: BCF 06.6
0243: BSF 03.5
0244: BCF 06.7
0245: BCF 03.5
0246: BCF 06.7
.................... Delay_ms(1000);
0247: MOVLW 04
0248: MOVWF 72
0249: MOVLW FA
024A: MOVWF 73
024B: CALL 0A8
024C: DECFSZ 72,F
024D: GOTO 249
.................... BL;
024E: BSF 03.5
024F: BCF 06.7
0250: BCF 03.5
0251: BSF 06.7
0252: BSF 03.5
0253: BCF 06.6
0254: BCF 03.5
0255: BCF 06.6
.................... Delay_ms(1000);
0256: MOVLW 04
0257: MOVWF 72
0258: MOVLW FA
0259: MOVWF 73
025A: CALL 0A8
025B: DECFSZ 72,F
025C: GOTO 258
.................... STOPL;
025D: BSF 03.5
025E: BCF 06.6
025F: BCF 03.5
0260: BCF 06.6
0261: BSF 03.5
0262: BCF 06.7
0263: BCF 03.5
0264: BCF 06.7
.................... Delay_ms(1000);
0265: MOVLW 04
0266: MOVWF 72
0267: MOVLW FA
0268: MOVWF 73
0269: CALL 0A8
026A: DECFSZ 72,F
026B: GOTO 267
....................
.................... FL; //oba pasy
026C: BSF 03.5
026D: BCF 06.6
026E: BCF 03.5
026F: BSF 06.6
0270: BSF 03.5
0271: BCF 06.7
0272: BCF 03.5
0273: BCF 06.7
.................... FR;
0274: BSF 03.5
0275: BCF 06.4
0276: BCF 03.5
0277: BSF 06.4
0278: BSF 03.5
0279: BCF 06.5
027A: BCF 03.5
027B: BCF 06.5
.................... Delay_ms(1000);
027C: MOVLW 04
027D: MOVWF 72
027E: MOVLW FA
027F: MOVWF 73
0280: CALL 0A8
0281: DECFSZ 72,F
0282: GOTO 27E
.................... STOPL;
0283: BSF 03.5
0284: BCF 06.6
0285: BCF 03.5
0286: BCF 06.6
0287: BSF 03.5
0288: BCF 06.7
0289: BCF 03.5
028A: BCF 06.7
.................... STOPR;
028B: BSF 03.5
028C: BCF 06.4
028D: BCF 03.5
028E: BCF 06.4
028F: BSF 03.5
0290: BCF 06.5
0291: BCF 03.5
0292: BCF 06.5
.................... Delay_ms(1000);
0293: MOVLW 04
0294: MOVWF 72
0295: MOVLW FA
0296: MOVWF 73
0297: CALL 0A8
0298: DECFSZ 72,F
0299: GOTO 295
.................... BL;
029A: BSF 03.5
029B: BCF 06.7
029C: BCF 03.5
029D: BSF 06.7
029E: BSF 03.5
029F: BCF 06.6
02A0: BCF 03.5
02A1: BCF 06.6
.................... BR;
02A2: BSF 03.5
02A3: BCF 06.5
02A4: BCF 03.5
02A5: BSF 06.5
02A6: BSF 03.5
02A7: BCF 06.4
02A8: BCF 03.5
02A9: BCF 06.4
.................... Delay_ms(1000);
02AA: MOVLW 04
02AB: MOVWF 72
02AC: MOVLW FA
02AD: MOVWF 73
02AE: CALL 0A8
02AF: DECFSZ 72,F
02B0: GOTO 2AC
.................... STOPL;
02B1: BSF 03.5
02B2: BCF 06.6
02B3: BCF 03.5
02B4: BCF 06.6
02B5: BSF 03.5
02B6: BCF 06.7
02B7: BCF 03.5
02B8: BCF 06.7
.................... STOPR;
02B9: BSF 03.5
02BA: BCF 06.4
02BB: BCF 03.5
02BC: BCF 06.4
02BD: BSF 03.5
02BE: BCF 06.5
02BF: BCF 03.5
02C0: BCF 06.5
.................... Delay_ms(1000);
02C1: MOVLW 04
02C2: MOVWF 72
02C3: MOVLW FA
02C4: MOVWF 73
02C5: CALL 0A8
02C6: DECFSZ 72,F
02C7: GOTO 2C3
.................... }
02C8: GOTO 1CA
02C9: BCF 0A.3
02CA: GOTO 2F0 (RETURN)
.................... }
....................
.................... void main()
.................... {
02CB: CLRF 04
02CC: MOVLW 1F
02CD: ANDWF 03,F
02CE: MOVLW 07
02CF: BSF 03.5
02D0: MOVWF 1F
02D1: MOVLW 82
02D2: BCF 03.5
02D3: MOVWF 2D
02D4: MOVLW 98
02D5: MOVWF 2E
02D6: MOVWF 2F
02D7: MOVLW 40
02D8: MOVWF 30
02D9: MOVWF 31
02DA: MOVWF 32
02DB: MOVLW 60
02DC: MOVWF 33
02DD: MOVLW 86
02DE: MOVWF 34
02DF: MOVLW B4
02E0: MOVWF 35
02E1: MOVLW 60
02E2: MOVWF 36
02E3: MOVLW A4
02E4: MOVWF 37
02E5: MOVWF 38
02E6: MOVWF 39
02E7: MOVLW 61
02E8: MOVWF 3A
02E9: MOVLW 03
02EA: MOVWF 3B
02EB: MOVLW F0
02EC: MOVWF 3C
02ED: MOVLW FF
02EE: MOVWF 44
.................... diagnostika();
02EF: GOTO 1CA
....................
.................... SoundBeep(640,200); //beep
02F0: MOVLW 02
02F1: MOVWF 73
02F2: MOVLW 80
02F3: MOVWF 72
02F4: CLRF 75
02F5: MOVLW C8
02F6: MOVWF 74
02F7: CALL 129
.................... Delay_ms(50);
02F8: MOVLW 32
02F9: MOVWF 73
02FA: CALL 0A8
.................... SoundBeep(640,200);
02FB: MOVLW 02
02FC: MOVWF 73
02FD: MOVLW 80
02FE: MOVWF 72
02FF: CLRF 75
0300: MOVLW C8
0301: MOVWF 74
0302: CALL 129
....................
.................... setup_adc_ports(RA0_RA1_RA3_ANALOG);
0303: MOVLW 04
0304: BSF 03.5
0305: MOVWF 1F
.................... setup_adc(ADC_CLOCK_DIV_2);
0306: BCF 03.5
0307: MOVF 1F,W
0308: ANDLW 38
0309: IORLW 01
030A: MOVWF 1F
.................... Delay_ms(1000); // 1s
030B: MOVLW 04
030C: MOVWF 71
030D: MOVLW FA
030E: MOVWF 73
030F: CALL 0A8
0310: DECFSZ 71,F
0311: GOTO 30D
....................
.................... movement=R;
0312: MOVLW 01
0313: MOVWF 6D
.................... line=S;
0314: MOVLW 02
0315: MOVWF 6E
.................... dira=0;
0316: CLRF 6F
....................
.................... //cik_cak(); // toc se, abys nasel caru
.................... FL; FR; // vpred
0317: BSF 03.5
0318: BCF 06.6
0319: BCF 03.5
031A: BSF 06.6
031B: BSF 03.5
031C: BCF 06.7
031D: BCF 03.5
031E: BCF 06.7
031F: BSF 03.5
0320: BCF 06.4
0321: BCF 03.5
0322: BSF 06.4
0323: BSF 03.5
0324: BCF 06.5
0325: BCF 03.5
0326: BCF 06.5
....................
.................... // Sledovani cary
.................... while(true)
.................... {
.................... snimani:
.................... set_adc_channel(RSENSOR);
0327: MOVLW 08
0328: MOVWF 21
0329: MOVF 1F,W
032A: ANDLW C7
032B: IORWF 21,W
032C: MOVWF 1F
.................... Delay_us(2);
032D: NOP
032E: NOP
.................... if (TRESHOLD > read_adc()) // Cara pod pravym senzorem
032F: BSF 1F.2
0330: BTFSC 1F.2
0331: GOTO 330
0332: MOVF 1E,W
0333: SUBLW 31
0334: BTFSS 03.0
0335: GOTO 34A
.................... {
.................... dira=0; // nuluj pocitadlo diry, protoze jsme videli caru
0336: CLRF 6F
.................... line=R; // zaznamenej, kdes videl caru
0337: MOVLW 01
0338: MOVWF 6E
.................... FL;FR;
0339: BSF 03.5
033A: BCF 06.6
033B: BCF 03.5
033C: BSF 06.6
033D: BSF 03.5
033E: BCF 06.7
033F: BCF 03.5
0340: BCF 06.7
0341: BSF 03.5
0342: BCF 06.4
0343: BCF 03.5
0344: BSF 06.4
0345: BSF 03.5
0346: BCF 06.5
0347: BCF 03.5
0348: BCF 06.5
.................... goto snimani;
0349: GOTO 327
.................... }
....................
.................... set_adc_channel(LSENSOR);
034A: MOVLW 00
034B: MOVWF 21
034C: MOVF 1F,W
034D: ANDLW C7
034E: IORWF 21,W
034F: MOVWF 1F
.................... Delay_us(2);
0350: NOP
0351: NOP
.................... if (TRESHOLD > read_adc()) // Cara pod levym senzorem
0352: BSF 1F.2
0353: BTFSC 1F.2
0354: GOTO 353
0355: MOVF 1E,W
0356: SUBLW 31
0357: BTFSS 03.0
0358: GOTO 36C
.................... {
.................... dira=0; // nuluj pocitadlo diry, protoze jsme videli caru
0359: CLRF 6F
.................... line=L; // zaznamenej, kdes videl caru
035A: CLRF 6E
.................... FL;FR;
035B: BSF 03.5
035C: BCF 06.6
035D: BCF 03.5
035E: BSF 06.6
035F: BSF 03.5
0360: BCF 06.7
0361: BCF 03.5
0362: BCF 06.7
0363: BSF 03.5
0364: BCF 06.4
0365: BCF 03.5
0366: BSF 06.4
0367: BSF 03.5
0368: BCF 06.5
0369: BCF 03.5
036A: BCF 06.5
.................... goto snimani;
036B: GOTO 327
.................... }
....................
.................... // oba senzory mimo caru
.................... if (0==dira) // v prvnim cyklu po ztrate cary zacneme zahybat
036C: MOVF 6F,F
036D: BTFSS 03.2
036E: GOTO 3BF
.................... // v ostatnich cyklech nedelame nic (pro urychleni snimani)
.................... {
.................... STOPL;
036F: BSF 03.5
0370: BCF 06.6
0371: BCF 03.5
0372: BCF 06.6
0373: BSF 03.5
0374: BCF 06.7
0375: BCF 03.5
0376: BCF 06.7
.................... STOPR;
0377: BSF 03.5
0378: BCF 06.4
0379: BCF 03.5
037A: BCF 06.4
037B: BSF 03.5
037C: BCF 06.5
037D: BCF 03.5
037E: BCF 06.5
.................... BL;
037F: BSF 03.5
0380: BCF 06.7
0381: BCF 03.5
0382: BSF 06.7
0383: BSF 03.5
0384: BCF 06.6
0385: BCF 03.5
0386: BCF 06.6
.................... BR;
0387: BSF 03.5
0388: BCF 06.5
0389: BCF 03.5
038A: BSF 06.5
038B: BSF 03.5
038C: BCF 06.4
038D: BCF 03.5
038E: BCF 06.4
.................... Delay_ms(20);
038F: MOVLW 14
0390: MOVWF 73
0391: CALL 0A8
.................... STOPL;
0392: BSF 03.5
0393: BCF 06.6
0394: BCF 03.5
0395: BCF 06.6
0396: BSF 03.5
0397: BCF 06.7
0398: BCF 03.5
0399: BCF 06.7
.................... STOPR;
039A: BSF 03.5
039B: BCF 06.4
039C: BCF 03.5
039D: BCF 06.4
039E: BSF 03.5
039F: BCF 06.5
03A0: BCF 03.5
03A1: BCF 06.5
.................... Delay_ms(200);
03A2: MOVLW C8
03A3: MOVWF 73
03A4: CALL 0A8
.................... // kdyz nevidis caru, tak jed tam, kdes ji videl naposled
.................... if(line==L)
03A5: MOVF 6E,F
03A6: BTFSS 03.2
03A7: GOTO 3B1
.................... {
.................... // doleva
.................... // STOPL;
.................... FR;
03A8: BSF 03.5
03A9: BCF 06.4
03AA: BCF 03.5
03AB: BSF 06.4
03AC: BSF 03.5
03AD: BCF 06.5
03AE: BCF 03.5
03AF: BCF 06.5
.................... movement=L; // poznamenej kam jedes
03B0: CLRF 6D
.................... }
.................... if(line==R)
03B1: DECFSZ 6E,W
03B2: GOTO 3BD
.................... {
.................... // doprava
.................... // STOPR;
.................... FL;
03B3: BSF 03.5
03B4: BCF 06.6
03B5: BCF 03.5
03B6: BSF 06.6
03B7: BSF 03.5
03B8: BCF 06.7
03B9: BCF 03.5
03BA: BCF 06.7
.................... movement=R; // poznamenej kam jedes
03BB: MOVLW 01
03BC: MOVWF 6D
.................... }
.................... dira++; // zvets pocitadlo diry, aby to pristi cyklus tudy neslo
03BD: INCF 6F,F
.................... goto snimani; // co nejrychleji se vrat na snimani cary
03BE: GOTO 327
.................... }
....................
.................... /*if (MEZERA < dira++) // nejedeme uz moc dlouho bez cary??
.................... {
.................... dira=0;
.................... switch(movement) // kam se jelo ??
.................... {
.................... case L:
.................... BR; // couvej doprava
.................... Delay_ms(COUVEJ);
.................... movement=R;
.................... break;
.................... case R:
.................... BL; // couvej doleva
.................... Delay_ms(COUVEJ);
.................... movement=L;
.................... break;
.................... }
.................... STOP(); // konec couvani
.................... FL; FR; // rovne pres diru
.................... Delay_ms(PRES_DIRU);
.................... STOP();
.................... cik_cak(); // najdi caru
.................... FR; FL; // vpred
.................... } // dira*/
....................
.................... } // while(true)
03BF: GOTO 327
....................
.................... }
....................
03C0: SLEEP
.................... /*void objizdka()
.................... {
.................... BL; BR; // zacouvej
.................... Delay_ms(150);
.................... STOP();
....................
.................... cik_cak(); // vyrovnej se na caru
.................... cik_cak(); // radeji 3x, aby se vyrovnaly setrvacne sily
.................... cik_cak();
....................
.................... BL; FR; Delay_ms(220); // vlevo
.................... STOP();
.................... FL; FR; Delay_ms(650); // rovne
.................... STOP();
.................... FL; BR; Delay_ms(220); // vpravo
.................... STOP();
.................... FL; FR; Delay_ms(770); // rovne
.................... STOP();
.................... FL; BR; Delay_ms(210); // vpravo
.................... STOP();
.................... FL; FR;
.................... Delay_ms(200); // kousek rovne
.................... // rovne, dokud nenarazis na caru
.................... while(input(RSENSOR)); // pravej senzor, protoze cihla je vpravo
.................... STOP();
.................... BL; FR; // toc se doleva, dokud nenarazis na caru
.................... while(input(LSENSOR)); // levej senzor, protoze cara je urcite vlevo
.................... STOP();
.................... line=R; // caru predpokladame vpravo, kdybysme ji prejeli
.................... dira=0;
.................... FL; FR; // vpred
.................... }*/
....................