Subversion Repositories svnkaklik

Compare Revisions

No changes between revisions

Ignore whitespace Rev 1 → Rev 2

/roboti/istrobot/3Orbis/bak/04 posledni RTOS/cidla/cidla.BAK
0,0 → 1,146
#include ".\cidla.h"
//#include <stdlib.h>
 
#use rs232(baud=110,parity=N,xmit=PIN_B1,rcv=PIN_B0,bits=8,restart_wdt)
 
#define IRRX PIN_B0
 
#define TRESHOLD_MAX 60 // rozhodovaci uroven pro cidla cerna/bila
#define TRESHOLD_MIN 40
 
unsigned int8 radius; // co cidla vidi
unsigned int8 last_radius; // rozsah
unsigned int8 last_cidla; // co cidla videla minule
unsigned int8 shure; // citac doby, po kterou musi byt detekovana cihla
 
//tuning
/*#define PULZACE 3 // urcuje rychlost pulzovani pomoci PWM
 
//Vystup PWM je na PIN_B3
////////////////////////////////////////////////////////////////////////////////
void pulzovani() // postupne rozsvecuje a zhasina podsvetleni
{
unsigned int8 i,n;
for(n=0;n<=3;n++)
{
for(i=0;i<255;i++) {set_pwm1_duty(i); Delay_ms(PULZACE);} // rozsvecovani
for(i=255;i>0;i--) {set_pwm1_duty(i); Delay_ms(PULZACE);} // zhasinani
}
}
*/
////////////////////////////////////////////////////////////////////////////////
void main()
{
int8 cidla;
unsigned int8 a;
unsigned int8 n;
 
setup_adc_ports(sAN0|sAN1|sAN2|sAN3|sAN4|sAN5|sAN6|VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL);
setup_spi(SPI_SLAVE|SPI_H_TO_L|SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
 
last_radius=0b00001000; // minimalni rozsah snimani od stredu
last_cidla=0b00001000;
 
shure=0;
while(true)
{
set_adc_channel(0);
cidla=0;
Delay_us(10);
a=read_adc();
 
set_adc_channel(1);
if(a<TRESHOLD_MAX) //hystereze cidel
{
if(a>TRESHOLD_MIN)
{
cidla |= (last_cidla & 0b00000001);
}
else cidla |= 0b00000001;
}
 
a=read_adc();
 
set_adc_channel(2);
if(a<TRESHOLD_MAX)
{
if(a>TRESHOLD_MIN)
{
cidla |= (last_cidla & 0b00000010);
}
else cidla |= 0b00000010;
}
 
a=read_adc();
 
set_adc_channel(3);
if(a<TRESHOLD_MAX)
{
if(a>TRESHOLD_MIN)
{
cidla |= (last_cidla & 0b00000100);
}
else cidla |= 0b00000100;
}
 
a=read_adc();
 
set_adc_channel(4);
if(a<TRESHOLD_MAX)
{
if(a>TRESHOLD_MIN)
{
cidla |= (last_cidla & 0b00001000);
}
else cidla |= 0b00001000;
}
a=read_adc();
 
set_adc_channel(5);
 
if(a<TRESHOLD_MAX)
{
if(a>TRESHOLD_MIN)
{
cidla |= (last_cidla & 0b00010000);
}
else cidla |= 0b00010000;
}
a=read_adc();
 
set_adc_channel(6);
if(a<TRESHOLD_MAX)
{
if(a>TRESHOLD_MIN)
{
cidla |= (last_cidla & 0b00100000);
}
else cidla |= 0b00100000;
}
a=read_adc();
 
if(a<TRESHOLD_MAX)
{
if(a>TRESHOLD_MIN)
{
cidla |=(last_cidla & 0b01000000);
}
else cidla |= 0b01000000;
}
 
last_cidla=cidla;
 
if (!input(IRRX)) {if (shure<255) shure++;} else {shure=0;};
if (shure>100) cidla|=0b10000000;
 
cidla=~cidla;
spi_write(cidla);
}
}
/roboti/istrobot/3Orbis/bak/04 posledni RTOS/cidla/cidla.HEX
0,0 → 1,39
:1000000000308A000428000084011F30830560301E
:1000100083168F0086108312861483161F129F1278
:100020001B0880399B0007309C001F129F121B0881
:1000300080397F389B001F1383121F179F17831669
:100040009F1383121F14941283160611861406162A
:100050003530831294004030831694000108C7396C
:1000600008388100831290010030F80092000030BF
:100070008316920007309C00050864000230F700E8
:10008000F70B4028000000001C0883120D13831694
:100090009D0108308312A100A200A3010030F800E6
:1000A0001F08C73978049F00A40164000230F700DC
:1000B000F70B5828000000001F151F195D281E08A7
:1000C000A5000830F8001F08C73978049F002508EC
:1000D0003B3C031C74282508283C0318732822087D
:1000E0000139A404742824141F151F1975281E082B
:1000F000A5001030F8001F08C73978049F002508B4
:100100003B3C031C8C282508283C03188B2822081C
:100110000239A4048C28A4141F151F198D281E0849
:10012000A5001830F8001F08C73978049F0025087B
:100130003B3C031CA4282508283C0318A3282208BC
:100140000439A404A42824151F151F19A5281E0866
:10015000A5002030F8001F08C73978049F00250843
:100160003B3C031CBC282508283C0318BB2822085C
:100170000839A404BC28A4151F151F19BD281E0882
:10018000A5002830F8001F08C73978049F0025080B
:100190003B3C031CD4282508283C0318D3282208FC
:1001A0001039A404D42824161F151F19D5281E0899
:1001B000A5003030F8001F08C73978049F002508D3
:1001C0003B3C031CEC282508283C0318EB2822089C
:1001D0002039A404EC28A4161F151F19ED281E08A9
:1001E000A50025083B3C031CFE282508283C0318D5
:1001F000FD2822084039A404FE2824172408A20060
:1002000083160614831206180A29230F08290929C0
:10021000A30A0B29A30123080A3C031CA417A40961
:1002200024089300831614181729831212298312A5
:040230004E286300F1
:04400E00383FFC3FFC
:00000001FF
;PIC16F88
/roboti/istrobot/3Orbis/bak/04 posledni RTOS/cidla/cidla.LST
0,0 → 1,454
CCS PCM C Compiler, Version 3.245, 27853 15-IV-06 16:26
 
Filename: D:\KAKLIK\programy\PIC_C\roboti\istrobot\3Orbis\cidla\cidla.lst
 
ROM used: 282 words (7%)
Largest free fragment is 2048
RAM used: 12 (7%) at main() level
12 (7%) worst case
Stack: 0 locations
 
*
0000: MOVLW 00
0001: MOVWF 0A
0002: GOTO 004
0003: NOP
.................... #include ".\cidla.h"
.................... #include <16F88.h>
.................... //////// Standard Header file for the PIC16F88 device ////////////////
.................... #device PIC16F88
.................... #list
....................
.................... #device adc=8
.................... #fuses NOWDT,INTRC_IO, NOPUT, MCLR, NOBROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG, NOPROTECT, NOFCMEN, NOIESO
.................... #use delay(clock=4000000,RESTART_WDT)
....................
....................
.................... //#include <stdlib.h>
....................
.................... #use rs232(baud=110,parity=N,xmit=PIN_B1,rcv=PIN_B0,bits=8,restart_wdt)
....................
.................... #define IRRX PIN_B0
....................
.................... #define TRESHOLD_MAX 60 // rozhodovaci uroven pro cidla cerna/bila
.................... #define TRESHOLD_MIN 40
.................... #define CIHLA 10 // doba, po kterou musi byt detekovana cihla
....................
.................... unsigned int8 radius; // co cidla vidi
.................... unsigned int8 last_radius; // rozsah
.................... unsigned int8 last_cidla; // co cidla videla minule
.................... unsigned int8 shure; // citac doby, po kterou musi byt detekovana cihla
....................
.................... //tuning
.................... /*#define PULZACE 3 // urcuje rychlost pulzovani pomoci PWM
....................
.................... //Vystup PWM je na PIN_B3
.................... ////////////////////////////////////////////////////////////////////////////////
.................... void pulzovani() // postupne rozsvecuje a zhasina podsvetleni
.................... {
.................... unsigned int8 i,n;
.................... for(n=0;n<=3;n++)
.................... {
.................... for(i=0;i<255;i++) {set_pwm1_duty(i); Delay_ms(PULZACE);} // rozsvecovani
.................... for(i=255;i>0;i--) {set_pwm1_duty(i); Delay_ms(PULZACE);} // zhasinani
.................... }
.................... }
.................... */
.................... ////////////////////////////////////////////////////////////////////////////////
.................... void main()
.................... {
0004: CLRF 04
0005: MOVLW 1F
0006: ANDWF 03,F
0007: MOVLW 60
0008: BSF 03.5
0009: MOVWF 0F
000A: BCF 06.1
000B: BCF 03.5
000C: BSF 06.1
000D: BSF 03.5
000E: BCF 1F.4
000F: BCF 1F.5
0010: MOVF 1B,W
0011: ANDLW 80
0012: MOVWF 1B
0013: MOVLW 07
0014: MOVWF 1C
.................... int8 cidla;
.................... unsigned int8 a;
.................... unsigned int8 n;
....................
.................... setup_adc_ports(sAN0|sAN1|sAN2|sAN3|sAN4|sAN5|sAN6|VSS_VDD);
0015: BCF 1F.4
0016: BCF 1F.5
0017: MOVF 1B,W
0018: ANDLW 80
0019: IORLW 7F
001A: MOVWF 1B
.................... setup_adc(ADC_CLOCK_INTERNAL);
001B: BCF 1F.6
001C: BCF 03.5
001D: BSF 1F.6
001E: BSF 1F.7
001F: BSF 03.5
0020: BCF 1F.7
0021: BCF 03.5
0022: BSF 1F.0
.................... setup_spi(SPI_SLAVE|SPI_H_TO_L|SPI_SS_DISABLED);
0023: BCF 14.5
0024: BSF 03.5
0025: BCF 06.2
0026: BSF 06.1
0027: BSF 06.4
0028: MOVLW 35
0029: BCF 03.5
002A: MOVWF 14
002B: MOVLW 40
002C: BSF 03.5
002D: MOVWF 14
.................... setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
002E: MOVF 01,W
002F: ANDLW C7
0030: IORLW 08
0031: MOVWF 01
.................... setup_timer_1(T1_DISABLED);
0032: BCF 03.5
0033: CLRF 10
.................... setup_timer_2(T2_DISABLED,0,1);
0034: MOVLW 00
0035: MOVWF 78
0036: MOVWF 12
0037: MOVLW 00
0038: BSF 03.5
0039: MOVWF 12
.................... setup_comparator(NC_NC_NC_NC);
003A: MOVLW 07
003B: MOVWF 1C
003C: MOVF 05,W
003D: CLRWDT
003E: MOVLW 02
003F: MOVWF 77
0040: DECFSZ 77,F
0041: GOTO 040
0042: NOP
0043: NOP
0044: MOVF 1C,W
0045: BCF 03.5
0046: BCF 0D.6
.................... setup_vref(FALSE);
0047: BSF 03.5
0048: CLRF 1D
....................
.................... last_radius=0b00001000; // minimalni rozsah snimani od stredu
0049: MOVLW 08
004A: BCF 03.5
004B: MOVWF 21
.................... last_cidla=0b00001000;
004C: MOVWF 22
....................
.................... shure=0;
004D: CLRF 23
....................
.................... while(true)
.................... {
.................... set_adc_channel(0);
004E: MOVLW 00
004F: MOVWF 78
0050: MOVF 1F,W
0051: ANDLW C7
0052: IORWF 78,W
0053: MOVWF 1F
.................... cidla=0;
0054: CLRF 24
.................... Delay_us(10);
0055: CLRWDT
0056: MOVLW 02
0057: MOVWF 77
0058: DECFSZ 77,F
0059: GOTO 058
005A: NOP
005B: NOP
.................... a=read_adc();
005C: BSF 1F.2
005D: BTFSC 1F.2
005E: GOTO 05D
005F: MOVF 1E,W
0060: MOVWF 25
....................
.................... set_adc_channel(1);
0061: MOVLW 08
0062: MOVWF 78
0063: MOVF 1F,W
0064: ANDLW C7
0065: IORWF 78,W
0066: MOVWF 1F
.................... if(a<TRESHOLD_MAX) //hystereze cidel
0067: MOVF 25,W
0068: SUBLW 3B
0069: BTFSS 03.0
006A: GOTO 074
.................... {
.................... if(a>TRESHOLD_MIN)
006B: MOVF 25,W
006C: SUBLW 28
006D: BTFSC 03.0
006E: GOTO 073
.................... {
.................... cidla |= (last_cidla & 0b00000001);
006F: MOVF 22,W
0070: ANDLW 01
0071: IORWF 24,F
.................... }
.................... else cidla |= 0b00000001;
0072: GOTO 074
0073: BSF 24.0
.................... }
....................
.................... a=read_adc();
0074: BSF 1F.2
0075: BTFSC 1F.2
0076: GOTO 075
0077: MOVF 1E,W
0078: MOVWF 25
....................
.................... set_adc_channel(2);
0079: MOVLW 10
007A: MOVWF 78
007B: MOVF 1F,W
007C: ANDLW C7
007D: IORWF 78,W
007E: MOVWF 1F
.................... if(a<TRESHOLD_MAX)
007F: MOVF 25,W
0080: SUBLW 3B
0081: BTFSS 03.0
0082: GOTO 08C
.................... {
.................... if(a>TRESHOLD_MIN)
0083: MOVF 25,W
0084: SUBLW 28
0085: BTFSC 03.0
0086: GOTO 08B
.................... {
.................... cidla |= (last_cidla & 0b00000010);
0087: MOVF 22,W
0088: ANDLW 02
0089: IORWF 24,F
.................... }
.................... else cidla |= 0b00000010;
008A: GOTO 08C
008B: BSF 24.1
.................... }
....................
.................... a=read_adc();
008C: BSF 1F.2
008D: BTFSC 1F.2
008E: GOTO 08D
008F: MOVF 1E,W
0090: MOVWF 25
....................
.................... set_adc_channel(3);
0091: MOVLW 18
0092: MOVWF 78
0093: MOVF 1F,W
0094: ANDLW C7
0095: IORWF 78,W
0096: MOVWF 1F
.................... if(a<TRESHOLD_MAX)
0097: MOVF 25,W
0098: SUBLW 3B
0099: BTFSS 03.0
009A: GOTO 0A4
.................... {
.................... if(a>TRESHOLD_MIN)
009B: MOVF 25,W
009C: SUBLW 28
009D: BTFSC 03.0
009E: GOTO 0A3
.................... {
.................... cidla |= (last_cidla & 0b00000100);
009F: MOVF 22,W
00A0: ANDLW 04
00A1: IORWF 24,F
.................... }
.................... else cidla |= 0b00000100;
00A2: GOTO 0A4
00A3: BSF 24.2
.................... }
....................
.................... a=read_adc();
00A4: BSF 1F.2
00A5: BTFSC 1F.2
00A6: GOTO 0A5
00A7: MOVF 1E,W
00A8: MOVWF 25
....................
.................... set_adc_channel(4);
00A9: MOVLW 20
00AA: MOVWF 78
00AB: MOVF 1F,W
00AC: ANDLW C7
00AD: IORWF 78,W
00AE: MOVWF 1F
.................... if(a<TRESHOLD_MAX)
00AF: MOVF 25,W
00B0: SUBLW 3B
00B1: BTFSS 03.0
00B2: GOTO 0BC
.................... {
.................... if(a>TRESHOLD_MIN)
00B3: MOVF 25,W
00B4: SUBLW 28
00B5: BTFSC 03.0
00B6: GOTO 0BB
.................... {
.................... cidla |= (last_cidla & 0b00001000);
00B7: MOVF 22,W
00B8: ANDLW 08
00B9: IORWF 24,F
.................... }
.................... else cidla |= 0b00001000;
00BA: GOTO 0BC
00BB: BSF 24.3
.................... }
.................... a=read_adc();
00BC: BSF 1F.2
00BD: BTFSC 1F.2
00BE: GOTO 0BD
00BF: MOVF 1E,W
00C0: MOVWF 25
....................
.................... set_adc_channel(5);
00C1: MOVLW 28
00C2: MOVWF 78
00C3: MOVF 1F,W
00C4: ANDLW C7
00C5: IORWF 78,W
00C6: MOVWF 1F
....................
.................... if(a<TRESHOLD_MAX)
00C7: MOVF 25,W
00C8: SUBLW 3B
00C9: BTFSS 03.0
00CA: GOTO 0D4
.................... {
.................... if(a>TRESHOLD_MIN)
00CB: MOVF 25,W
00CC: SUBLW 28
00CD: BTFSC 03.0
00CE: GOTO 0D3
.................... {
.................... cidla |= (last_cidla & 0b00010000);
00CF: MOVF 22,W
00D0: ANDLW 10
00D1: IORWF 24,F
.................... }
.................... else cidla |= 0b00010000;
00D2: GOTO 0D4
00D3: BSF 24.4
.................... }
.................... a=read_adc();
00D4: BSF 1F.2
00D5: BTFSC 1F.2
00D6: GOTO 0D5
00D7: MOVF 1E,W
00D8: MOVWF 25
....................
.................... set_adc_channel(6);
00D9: MOVLW 30
00DA: MOVWF 78
00DB: MOVF 1F,W
00DC: ANDLW C7
00DD: IORWF 78,W
00DE: MOVWF 1F
.................... if(a<TRESHOLD_MAX)
00DF: MOVF 25,W
00E0: SUBLW 3B
00E1: BTFSS 03.0
00E2: GOTO 0EC
.................... {
.................... if(a>TRESHOLD_MIN)
00E3: MOVF 25,W
00E4: SUBLW 28
00E5: BTFSC 03.0
00E6: GOTO 0EB
.................... {
.................... cidla |= (last_cidla & 0b00100000);
00E7: MOVF 22,W
00E8: ANDLW 20
00E9: IORWF 24,F
.................... }
.................... else cidla |= 0b00100000;
00EA: GOTO 0EC
00EB: BSF 24.5
.................... }
.................... a=read_adc();
00EC: BSF 1F.2
00ED: BTFSC 1F.2
00EE: GOTO 0ED
00EF: MOVF 1E,W
00F0: MOVWF 25
....................
.................... if(a<TRESHOLD_MAX)
00F1: MOVF 25,W
00F2: SUBLW 3B
00F3: BTFSS 03.0
00F4: GOTO 0FE
.................... {
.................... if(a>TRESHOLD_MIN)
00F5: MOVF 25,W
00F6: SUBLW 28
00F7: BTFSC 03.0
00F8: GOTO 0FD
.................... {
.................... cidla |=(last_cidla & 0b01000000);
00F9: MOVF 22,W
00FA: ANDLW 40
00FB: IORWF 24,F
.................... }
.................... else cidla |= 0b01000000;
00FC: GOTO 0FE
00FD: BSF 24.6
.................... }
....................
.................... last_cidla=cidla;
00FE: MOVF 24,W
00FF: MOVWF 22
....................
.................... if (!input(IRRX)) {if (shure<255) shure++;} else {shure=0;};
0100: BSF 03.5
0101: BSF 06.0
0102: BCF 03.5
0103: BTFSC 06.0
0104: GOTO 10A
0105: INCFSZ 23,W
0106: GOTO 108
0107: GOTO 109
0108: INCF 23,F
0109: GOTO 10B
010A: CLRF 23
.................... if (shure>CIHLA) cidla|=0b10000000;
010B: MOVF 23,W
010C: SUBLW 0A
010D: BTFSS 03.0
010E: BSF 24.7
....................
.................... cidla=~cidla;
010F: COMF 24,F
.................... spi_write(cidla);
0110: MOVF 24,W
0111: MOVWF 13
0112: BSF 03.5
0113: BTFSC 14.0
0114: GOTO 117
0115: BCF 03.5
0116: GOTO 112
.................... }
0117: BCF 03.5
0118: GOTO 04E
.................... }
0119: SLEEP
 
Configuration Fuses:
Word 1: 3F38 NOWDT NOPUT MCLR NOBROWNOUT NOLVP NOCPD NOWRT NODEBUG CCPB0 NOPROTECT INTRC_IO
Word 2: 3FFC NOFCMEN NOIESO
/roboti/istrobot/3Orbis/bak/04 posledni RTOS/cidla/cidla.PJT
0,0 → 1,44
[PROJECT]
Target=cidla.HEX
Development_Mode=
Processor=0x688F
ToolSuite=CCS
 
[Directories]
Include=C:\Program Files\PICC\devices\;C:\Program Files\PICC\dr
Library=
LinkerScript=
 
[Target Data]
FileList=D:\KAKLIK\programy\PIC_C\roboti\istrobot\3Orbis\cidla\cidla.c
BuildTool=C-COMPILER
OptionString=+FM
AdditionalOptionString=
BuildRequired=1
 
[cidla.c]
Type=4
Path=
FileList=
BuildTool=
OptionString=
AdditionalOptionString=
 
[mru-list]
1=cidla.c
 
[Windows]
0=0000 cidla.c 0 0 796 451 3 0
 
[Opened Files]
1=D:\KAKLIK\programy\PIC_C\roboti\istrobot\3Orbis\cidla\cidla.c
2=C:\Program Files\PICC\devices\16F88.h
3=C:\Program Files\PICC\drivers\stdlib.h
4=C:\Program Files\PICC\drivers\stddef.h
5=C:\Program Files\PICC\drivers\string.h
6=C:\Program Files\PICC\drivers\ctype.h
7=D:\KAKLIK\programy\PIC_C\roboti\istrobot\3Orbis\cidla\cidla.h
8=
[Units]
Count=1
1=D:\KAKLIK\programy\PIC_C\roboti\istrobot\3Orbis\cidla\cidla.c (main)
/roboti/istrobot/3Orbis/bak/04 posledni RTOS/cidla/cidla.SYM
0,0 → 1,45
015-016 CCP_1
015 CCP_1_LOW
016 CCP_1_HIGH
020 radius
021 last_radius
022 last_cidla
023 shure
024 main.cidla
025 main.a
026 main.n
077 @SCRATCH
078 @SCRATCH
078 _RETURN_
079 @SCRATCH
07A @SCRATCH
07B @SCRATCH
09C.6 C1OUT
09C.7 C2OUT
 
0004 main
0004 @cinit
 
Project Files:
D:\KAKLIK\programy\PIC_C\roboti\istrobot\3Orbis\cidla\cidla.c
D:\KAKLIK\programy\PIC_C\roboti\istrobot\3Orbis\cidla\cidla.h
C:\Program Files\PICC\devices\16F88.h
 
Units:
D:\KAKLIK\programy\PIC_C\roboti\istrobot\3Orbis\cidla\cidla.c (main)
 
Compiler Settings:
Processor: PIC16F88
Pointer Size: 8
ADC Range: 0-255
Opt Level: 9
Short,Int,Long: 1,8,16
 
Output Files:
Errors: D:\KAKLIK\programy\PIC_C\roboti\istrobot\3Orbis\cidla\cidla.err
INHX8: D:\KAKLIK\programy\PIC_C\roboti\istrobot\3Orbis\cidla\cidla.hex
Symbols: D:\KAKLIK\programy\PIC_C\roboti\istrobot\3Orbis\cidla\cidla.sym
List: D:\KAKLIK\programy\PIC_C\roboti\istrobot\3Orbis\cidla\cidla.lst
Debug/COFF: D:\KAKLIK\programy\PIC_C\roboti\istrobot\3Orbis\cidla\cidla.cof
Call Tree: D:\KAKLIK\programy\PIC_C\roboti\istrobot\3Orbis\cidla\cidla.tre
Statistics: D:\KAKLIK\programy\PIC_C\roboti\istrobot\3Orbis\cidla\cidla.sta
/roboti/istrobot/3Orbis/bak/04 posledni RTOS/cidla/cidla.c
0,0 → 1,147
#include ".\cidla.h"
//#include <stdlib.h>
 
#use rs232(baud=110,parity=N,xmit=PIN_B1,rcv=PIN_B0,bits=8,restart_wdt)
 
#define IRRX PIN_B0
 
#define TRESHOLD_MAX 60 // rozhodovaci uroven pro cidla cerna/bila
#define TRESHOLD_MIN 40
#define CIHLA 10 // doba, po kterou musi byt detekovana cihla
 
unsigned int8 radius; // co cidla vidi
unsigned int8 last_radius; // rozsah
unsigned int8 last_cidla; // co cidla videla minule
unsigned int8 shure; // citac doby, po kterou musi byt detekovana cihla
 
//tuning
/*#define PULZACE 3 // urcuje rychlost pulzovani pomoci PWM
 
//Vystup PWM je na PIN_B3
////////////////////////////////////////////////////////////////////////////////
void pulzovani() // postupne rozsvecuje a zhasina podsvetleni
{
unsigned int8 i,n;
for(n=0;n<=3;n++)
{
for(i=0;i<255;i++) {set_pwm1_duty(i); Delay_ms(PULZACE);} // rozsvecovani
for(i=255;i>0;i--) {set_pwm1_duty(i); Delay_ms(PULZACE);} // zhasinani
}
}
*/
////////////////////////////////////////////////////////////////////////////////
void main()
{
int8 cidla;
unsigned int8 a;
unsigned int8 n;
 
setup_adc_ports(sAN0|sAN1|sAN2|sAN3|sAN4|sAN5|sAN6|VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL);
setup_spi(SPI_SLAVE|SPI_H_TO_L|SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
 
last_radius=0b00001000; // minimalni rozsah snimani od stredu
last_cidla=0b00001000;
 
shure=0;
while(true)
{
set_adc_channel(0);
cidla=0;
Delay_us(10);
a=read_adc();
 
set_adc_channel(1);
if(a<TRESHOLD_MAX) //hystereze cidel
{
if(a>TRESHOLD_MIN)
{
cidla |= (last_cidla & 0b00000001);
}
else cidla |= 0b00000001;
}
 
a=read_adc();
 
set_adc_channel(2);
if(a<TRESHOLD_MAX)
{
if(a>TRESHOLD_MIN)
{
cidla |= (last_cidla & 0b00000010);
}
else cidla |= 0b00000010;
}
 
a=read_adc();
 
set_adc_channel(3);
if(a<TRESHOLD_MAX)
{
if(a>TRESHOLD_MIN)
{
cidla |= (last_cidla & 0b00000100);
}
else cidla |= 0b00000100;
}
 
a=read_adc();
 
set_adc_channel(4);
if(a<TRESHOLD_MAX)
{
if(a>TRESHOLD_MIN)
{
cidla |= (last_cidla & 0b00001000);
}
else cidla |= 0b00001000;
}
a=read_adc();
 
set_adc_channel(5);
 
if(a<TRESHOLD_MAX)
{
if(a>TRESHOLD_MIN)
{
cidla |= (last_cidla & 0b00010000);
}
else cidla |= 0b00010000;
}
a=read_adc();
 
set_adc_channel(6);
if(a<TRESHOLD_MAX)
{
if(a>TRESHOLD_MIN)
{
cidla |= (last_cidla & 0b00100000);
}
else cidla |= 0b00100000;
}
a=read_adc();
 
if(a<TRESHOLD_MAX)
{
if(a>TRESHOLD_MIN)
{
cidla |=(last_cidla & 0b01000000);
}
else cidla |= 0b01000000;
}
 
last_cidla=cidla;
 
if (!input(IRRX)) {if (shure<255) shure++;} else {shure=0;};
if (shure>CIHLA) cidla|=0b10000000;
 
cidla=~cidla;
spi_write(cidla);
}
}
/roboti/istrobot/3Orbis/bak/04 posledni RTOS/cidla/cidla.cof
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/roboti/istrobot/3Orbis/bak/04 posledni RTOS/cidla/cidla.err
0,0 → 1,2
No Errors
0 Errors, 0 Warnings.
/roboti/istrobot/3Orbis/bak/04 posledni RTOS/cidla/cidla.h
0,0 → 1,5
#include <16F88.h>
#device adc=8
#fuses NOWDT,INTRC_IO, NOPUT, MCLR, NOBROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG, NOPROTECT, NOFCMEN, NOIESO
#use delay(clock=4000000,RESTART_WDT)
 
/roboti/istrobot/3Orbis/bak/04 posledni RTOS/cidla/cidla.sta
0,0 → 1,28
 
ROM used: 282 (7%)
282 (7%) including unused fragments
 
1 Average locations per line
3 Average locations per statement
 
RAM used: 12 (7%) at main() level
12 (7%) worst case
 
Lines Stmts % Files
----- ----- --- -----
148 83 100 D:\KAKLIK\programy\PIC_C\roboti\istrobot\3Orbis\cidla\cidla.c
6 0 0 D:\KAKLIK\programy\PIC_C\roboti\istrobot\3Orbis\cidla\cidla.h
279 0 0 C:\Program Files\PICC\devices\16F88.h
----- -----
866 166 Total
 
Page ROM % RAM Functions:
---- --- --- --- ----------
0 278 99 3 main
 
Segment Used Free
--------- ---- ----
00000-00003 4 0
00004-007FF 278 1766
00800-00FFF 0 2048
 
/roboti/istrobot/3Orbis/bak/04 posledni RTOS/cidla/cidla.tre
0,0 → 1,3
ÀÄcidla
ÀÄmain 0/278 Ram=3
ÀÄ??0??
/roboti/istrobot/3Orbis/bak/04 posledni RTOS/cidla/macro.ini
--- main/main.BAK (nonexistent)
+++ main/main.BAK (revision 2)
@@ -0,0 +1,268 @@
+#include ".\main.h"
+
+#use rtos (timer=2, minor_cycle=2ms)
+
+#define STRED 128 // sredni poloha zadniho kolecka
+#define BEAR1 12 // 3 stupne zataceni
+#define BEAR2 34
+#define BEAR3 70
+#define SPEEDMAX 120 // maximalni rychlost
+
+#define L 1
+#define S 2
+#define R 0
+
+// servo
+#define SERVO PIN_A2
+
+// IR
+#define IRTX PIN_B2
+
+//motory
+#define FR output_low(PIN_A7); output_high(PIN_A6) // Vpred
+#define FL output_low(PIN_A1); output_high(PIN_A0)
+#define BR output_low(PIN_A6); output_high(PIN_A7) // Vzad
+#define BL output_low(PIN_A0); output_high(PIN_A1)
+#define STOPR output_low(PIN_A6);output_low(PIN_A7)
+#define STOPL output_low(PIN_A0);output_low(PIN_A1)
+
+//HID
+#define LED1 PIN_B1 //oranzova
+#define LED2 PIN_B2 //zluta
+
+#define STROBE PIN_B0
+//#define SW1 PIN_A2 // Motory On/off
+
+unsigned int8 sensors; // pomocna promenna pro cteni cidel na caru
+unsigned int8 line; // na ktere strane byla detekovana cara
+//unsigned int8 dira; // pocita dobu po kterou je ztracena cara
+unsigned int8 uhel; // urcuje aktualni uhel zataceni
+//unsigned int8 speed; // maximalni povolena rychlost
+unsigned int8 rovinka; // pocitadlo na zjisteni rovinky
+
+signed int16 Lmotor; // promene, ktere urcuji velikost vykonu na levem
+signed int16 Rmotor; // a pravem motoru
+
+// makro pro PWM
+#define GO(motor, direction, power) if(get_timer0()<=power) \
+{direction##motor;} else {stop##motor;}
+
+////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////
+/*
+void diagnostika()
+{
+ if(input(SW1))STOPR;STOPL;While(TRUE);
+// if(LSENSOR==true) output_high(LED2); else output_low(LED2);
+// if(RSENSOR==true) output_high(LED1); else output_low(LED1);
+}
+*/
+////////////////////////////////////////////////////////////////////////////////
+#task (rate=18ms,max=2ms)
+void zatoc() // ridi servo ktere otaci kolem
+{
+ unsigned int8 n;
+
+ output_high(SERVO);
+ delay_us(1100);
+ for(n=uhel; n>0; n--);
+ output_low(SERVO);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void diag() // ridi servo ktere otaci kolem
+{
+ unsigned int8 n;
+
+ output_high(SERVO);
+ delay_us(1100);
+ for(n=uhel; n>0; n--);
+ output_low(SERVO);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+short int IRcheck() // potvrdi detekci cihly
+{
+ output_high(IRTX); // vypne vysilac IR
+
+ output_low(STROBE);
+ sensors = spi_read(0); // cteni senzoru
+ output_high(STROBE);
+
+ if(true==bit_test(sensors,7)) // otestuje, jestli je stale detekovan IR signal
+ {
+ output_low(IRTX); // zapne vysilac IR
+
+ output_low(STROBE);
+ sensors = spi_read(0); // cteni senzoru
+ output_high(STROBE);
+
+ if(false==bit_test(sensors,7)) // otestuje, jestli je detekovana cihla
+ {
+ output_high(IRTX); // vypne vysilac IR
+
+ output_low(STROBE);
+ sensors = spi_read(0); // cteni senzoru
+ output_high(STROBE);
+
+ if(bit_test(sensors,7)) return 1; //
+
+ else return 0; // vrat 0 kdyz je ruseni
+ }
+ else return 0; // vrat 0 kdyz to nebyla cihla
+ }
+ else return 0; // vrat 0 kdyz je detekovano ruseni
+}
+////////////////////////////////////////////////////////////////////////////////
+/*
+#task (rate=4ms, max=20us)
+void rychlost()
+{
+ if(speed<255) speed++;
+}
+*/
+////////////////////////////////////////////////////////////////////////////////
+#task (rate=2ms, max=1ms)
+void rizeni()
+{
+ unsigned int16 n;
+ unsigned int8 i;
+
+ GO(L,F,Lmotor);GO(R,F,Rmotor); // zapni motory
+
+ delay_us(500);
+
+ output_low(STROBE);
+ sensors = spi_read(0); // cteni senzoru
+ sensors=~sensors;
+ output_high(STROBE);
+
+ i=0; // havarijni kod
+ for (n=0; n<=6; n++)
+ {
+ if(bit_test(sensors,n)) i++;
+ }
+ if (i>3) rtos_terminate(); // zastavi, kdyz je cerno pod vice nez tremi cidly
+
+
+ if(bit_test(sensors,3)) //...|...//
+ {
+ uhel=STRED;
+ Lmotor=SPEEDMAX;
+ Rmotor=SPEEDMAX;
+ line=S;
+ if (rovinka<255) rovinka++;
+ return;
+ }
+
+ if(bit_test(sensors,0)) //|......// // z duvodu zkraceni doby reakce se cidla nevyhodnocuji poporade ale od krajnich k prostrednimu
+ {
+ uhel=STRED-BEAR3;
+ Lmotor=0;
+ Rmotor=SPEEDMAX;
+ line=L;
+ return;
+ }
+
+ if(bit_test(sensors,6)) //......|//
+ {
+ uhel=STRED+BEAR3;
+ Rmotor=0;
+ Lmotor=SPEEDMAX;
+ line=R;
+ return;
+
+ }
+
+ if(bit_test(sensors,1)) //.|.....//
+ {
+ uhel=STRED-BEAR2;
+ Lmotor=SPEEDMAX-50;
+ Rmotor=SPEEDMAX;
+ line=S;
+ return;
+ }
+
+ if(bit_test(sensors,5)) //.....|.//
+ {
+ uhel=STRED+BEAR2;
+ Rmotor=SPEEDMAX-50;
+ Lmotor=SPEEDMAX;
+ line=S;
+ return;
+ }
+
+ if (bit_test(sensors,2)) //..|....//
+ {
+ uhel=STRED-BEAR1;
+ Lmotor=SPEEDMAX;
+ Rmotor=SPEEDMAX;
+ line=S;
+ if (rovinka<255) rovinka++;
+ return;
+ }
+
+ if (bit_test(sensors,4)) //....|..//
+ {
+ uhel=STRED+BEAR1;
+ Rmotor=SPEEDMAX;
+ Lmotor=SPEEDMAX;
+ line=S;
+ if (rovinka<255) rovinka++;
+ return;
+ }
+
+ if ((L==line) || (R==line)) // Brzdeni pri vyjeti z trate
+ {
+ if (rovinka>250)
+ {
+ BL; BR;
+ for(n=1; n<(60); n++) {rtos_yield(); delay_us(500);};
+ };
+ rovinka=0;
+ }
+
+ if(bit_test(sensors,7)) // zjisti jestli neni cihla
+ {
+ rtos_terminate();
+ }
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+void main()
+{
+ unsigned int16 i;
+ unsigned int8 last;
+
+ setup_adc_ports(NO_ANALOGS);
+ setup_adc(ADC_CLOCK_INTERNAL);
+ setup_spi(SPI_MASTER|SPI_H_TO_L|SPI_XMIT_L_TO_H|SPI_CLK_DIV_4);
+ setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
+ setup_timer_1(T1_DISABLED);
+ setup_oscillator(OSC_8MHZ|OSC_INTRC);
+
+ STOPR; STOPL; // zastav motory
+ Lmotor=0;Rmotor=0;
+
+ uhel=STRED; // nastav zadni kolecko na stred
+ rovinka=0;
+
+ output_low(IRTX); // zapni IR vysilac
+
+ for(i=0;i<100;i++) // pockej, nez se zadni kolecko vystredi
+ {
+ diag();
+ delay_ms(16);
+ }
+// diagnostika();
+
+ while(true)
+ {
+ rtos_run();
+ STOPR;
+ STOPL;
+ while(true);
+ }
+}
/roboti/istrobot/3Orbis/bak/04 posledni RTOS/main/main.HEX
0,0 → 1,78
:1000000000308A00822900000A108A100A11820733
:1000100029340034303400343D30840000080319A2
:1000200023280230F800BF30F7006400F70B1528D2
:10003000F80B13289630F700F70B1C28000000007F
:100040006400800B112800340830C202031C3328DE
:10005000423084000310800C000803193328312833
:100060006400800B302800348316051183120515B7
:1000700064000130BD000C206330C200242023083E
:10008000BC00BC0803194628BC034128831605118F
:10009000831205113430AE000030AF008A11342ACB
:1000A00000340108801F5728A61F5F285928A61B67
:1000B0006828A608031D5F282502031C68288316EC
:1000C000851083128510831605108312051470287D
:1000D0008316051083120510831685108312851070
:1000E0000108801F7628A81F7E287828A81B87284B
:1000F000A808031D7E282702031C87288316851362
:100100008312851383160513831205178F28831610
:100110000513831205138316851383128513640058
:100120000230C100F730C2002420C10B9228831690
:100130000610831206101308930183161418A228C0
:1001400083129D2883121308A100A10983160610AB
:1001500083120614C001BF01BE01BF08031DC428DD
:100160003E08063C031CC4282108F7003E08F8009E
:100170000319BE280310F70CF80BBA287718C00A29
:10018000BE0A0319BF0AAD284008033C031C412ADC
:10019000A11DD8288030A300A6017830A500A801B1
:1001A000A7000230A200240FD628D728A40A63296A
:1001B000211CE4283A30A300A601A501A80178304B
:1001C000A7000130A2006329211FEF28C630A30039
:1001D000A801A701A6017830A500A2016329A11CEE
:1001E000FC285E30A300A6014630A500A8017830A7
:1001F000A7000230A2006329A11E0929A230A30092
:10020000A8014630A700A6017830A5000230A20060
:100210006329211D19297430A300A6017830A50097
:10022000A801A7000230A200240F17291829A40A48
:100230006329211E29298C30A300A8017830A7004A
:10024000A601A5000230A200240F27292829A40A0C
:100250006329220B2C292F29A208031D60292408B9
:10026000FA3C03185F2983160510831205108316C4
:1002700085108312851483160513831205138316C4
:10028000851383128517BF010130BE00BF08031D0F
:100290005F293E083B3C031C5F295330B500013009
:1002A000B6008A11342A64000230C100F730C2005F
:1002B0002420C10B5629BE0A0319BF0A4629A401EE
:1002C000A11F6329412A5130B5000030B6008A11C0
:1002D000342A003483160511831205156400013099
:1002E000BD000C206330C20024202308BA00BA08E5
:1002F00003197C29BA037729831605118312051186
:100300008A11D42984011F308305703083168F0031
:100310001F129F121B0880399B0007309C001F1280
:100320009F121B0880399B001F1383121F179F17F2
:1003300083169F1383121F149412831606118614BA
:1003400006123030831294000030831694000108A6
:10035000C7390838810083129001723083168F00EC
:1003600005138312051383168513831285138316D1
:100370000510831205108316851083128510A601BF
:10038000A501A801A7018030A300A40183160611CE
:1003900083120611B801B701B808031DDB2937081D
:1003A000633C031CDB296A291030BD000C20B70A0E
:1003B0000319B80ACC29A901AB010930AA00AD0183
:1003C000AC013430AE000030AF00B001B2010130FA
:1003D000B100B401B3015130B5000030B600A00146
:1003E0000030F80006389200FA308316920083122B
:1003F0008C100030F80006389200FA308316920014
:1004000083128C100310200DF7000420F900013036
:1004100077070420FA00790884000008F900840AAC
:100420000008F700840A0008F800840A800A00081F
:10043000FA00031D1E2A840A800A8403840A000825
:100440007802031D362A77087A02031D362A8403B0
:100450008001840A8001840AF91B362A840A000874
:100460008A0084030008820083120313A00A02306A
:100470002002031D022AA0018C1C402A8316002A98
:100480003C2AFF30A0008316051383120513831640
:1004900085138312851383160510831205108316A6
:0C04A000851083128510532ADB296300AD
:04400E00383FFC3FFC
:00000001FF
;PIC16F88
/roboti/istrobot/3Orbis/bak/04 posledni RTOS/main/main.LST
0,0 → 1,899
CCS PCM C Compiler, Version 3.245, 27853 15-IV-06 16:28
 
Filename: D:\KAKLIK\programy\PIC_C\roboti\istrobot\3Orbis\main.lst
 
ROM used: 598 words (15%)
Largest free fragment is 2048
RAM used: 31 (18%) at main() level
40 (23%) worst case
Stack: 4 worst case (2 in main + 2 for interrupts)
 
*
0000: MOVLW 00
0001: MOVWF 0A
0002: GOTO 182
0003: NOP
.................... #include ".\main.h"
.................... #include <16F88.h>
.................... //////// Standard Header file for the PIC16F88 device ////////////////
.................... #device PIC16F88
.................... #list
....................
.................... #device adc=8
....................
.................... #FUSES NOWDT //No Watch Dog Timer
.................... #FUSES INTRC_IO
.................... #FUSES NOPUT //No Power Up Timer
.................... #FUSES MCLR //Master Clear pin enabled
.................... #FUSES NOBROWNOUT //Reset when brownout detected
.................... #FUSES NOLVP //Low Voltage Programming on B3(PIC16) or B5(PIC18)
.................... #FUSES NOCPD //No EE protection
.................... #FUSES NOWRT //Program memory not write protected
.................... #FUSES NODEBUG //No Debug mode for ICD
.................... #FUSES NOPROTECT //Code not protected from reading
.................... #FUSES NOFCMEN //Fail-safe clock monitor enabled
.................... #FUSES NOIESO //Internal External Switch Over mode enabled
....................
.................... #use delay(clock=8000000,RESTART_WDT)
000C: MOVLW 3D
000D: MOVWF 04
000E: MOVF 00,W
000F: BTFSC 03.2
0010: GOTO 023
0011: MOVLW 02
0012: MOVWF 78
0013: MOVLW BF
0014: MOVWF 77
0015: CLRWDT
0016: DECFSZ 77,F
0017: GOTO 015
0018: DECFSZ 78,F
0019: GOTO 013
001A: MOVLW 96
001B: MOVWF 77
001C: DECFSZ 77,F
001D: GOTO 01C
001E: NOP
001F: NOP
0020: CLRWDT
0021: DECFSZ 00,F
0022: GOTO 011
0023: RETLW 00
0024: MOVLW 08
0025: SUBWF 42,F
0026: BTFSS 03.0
0027: GOTO 033
0028: MOVLW 42
0029: MOVWF 04
002A: BCF 03.0
002B: RRF 00,F
002C: MOVF 00,W
002D: BTFSC 03.2
002E: GOTO 033
002F: GOTO 031
0030: CLRWDT
0031: DECFSZ 00,F
0032: GOTO 030
0033: RETLW 00
....................
....................
....................
.................... #use rtos (timer=2, minor_cycle=2ms)
....................
.................... #define STRED 128 // sredni poloha zadniho kolecka
.................... #define BEAR1 12 // 3 stupne zataceni
.................... #define BEAR2 34
.................... #define BEAR3 70
.................... #define SPEEDMAX 120 // maximalni rychlost
....................
.................... #define L 1
.................... #define S 2
.................... #define R 0
....................
.................... // servo
.................... #define SERVO PIN_A2
....................
.................... // IR
.................... #define IRTX PIN_B2
....................
.................... //motory
.................... #define FR output_low(PIN_A7); output_high(PIN_A6) // Vpred
.................... #define FL output_low(PIN_A1); output_high(PIN_A0)
.................... #define BR output_low(PIN_A6); output_high(PIN_A7) // Vzad
.................... #define BL output_low(PIN_A0); output_high(PIN_A1)
.................... #define STOPR output_low(PIN_A6);output_low(PIN_A7)
.................... #define STOPL output_low(PIN_A0);output_low(PIN_A1)
....................
.................... //HID
.................... #define LED1 PIN_B1 //oranzova
.................... #define LED2 PIN_B2 //zluta
....................
.................... #define STROBE PIN_B0
.................... //#define SW1 PIN_A2 // Motory On/off
....................
.................... unsigned int8 sensors; // pomocna promenna pro cteni cidel na caru
.................... unsigned int8 line; // na ktere strane byla detekovana cara
.................... //unsigned int8 dira; // pocita dobu po kterou je ztracena cara
.................... unsigned int8 uhel; // urcuje aktualni uhel zataceni
.................... //unsigned int8 speed; // maximalni povolena rychlost
.................... unsigned int8 rovinka; // pocitadlo na zjisteni rovinky
....................
.................... signed int16 Lmotor; // promene, ktere urcuji velikost vykonu na levem
.................... signed int16 Rmotor; // a pravem motoru
....................
.................... // makro pro PWM
.................... #define GO(motor, direction, power) if(get_timer0()<=power) \
.................... {direction##motor;} else {stop##motor;}
....................
.................... ////////////////////////////////////////////////////////////////////////////////
.................... ////////////////////////////////////////////////////////////////////////////////
.................... /*
.................... void diagnostika()
.................... {
.................... if(input(SW1))STOPR;STOPL;While(TRUE);
.................... // if(LSENSOR==true) output_high(LED2); else output_low(LED2);
.................... // if(RSENSOR==true) output_high(LED1); else output_low(LED1);
.................... }
.................... */
.................... ////////////////////////////////////////////////////////////////////////////////
.................... #task (rate=18ms,max=2ms)
.................... void zatoc() // ridi servo ktere otaci kolem
.................... {
.................... unsigned int8 n;
....................
.................... output_high(SERVO);
0034: BSF 03.5
0035: BCF 05.2
0036: BCF 03.5
0037: BSF 05.2
.................... delay_us(1100);
0038: CLRWDT
0039: MOVLW 01
003A: MOVWF 3D
003B: CALL 00C
003C: MOVLW 63
003D: MOVWF 42
003E: CALL 024
.................... for(n=uhel; n>0; n--);
003F: MOVF 23,W
0040: MOVWF 3C
0041: MOVF 3C,F
0042: BTFSC 03.2
0043: GOTO 046
0044: DECF 3C,F
0045: GOTO 041
.................... output_low(SERVO);
0046: BSF 03.5
0047: BCF 05.2
0048: BCF 03.5
0049: BCF 05.2
.................... }
004A: MOVLW 34
004B: MOVWF 2E
004C: MOVLW 00
004D: MOVWF 2F
004E: BCF 0A.3
004F: GOTO 234
0050: RETLW 00
....................
.................... ////////////////////////////////////////////////////////////////////////////////
.................... void diag() // ridi servo ktere otaci kolem
.................... {
.................... unsigned int8 n;
....................
.................... output_high(SERVO);
*
016A: BSF 03.5
016B: BCF 05.2
016C: BCF 03.5
016D: BSF 05.2
.................... delay_us(1100);
016E: CLRWDT
016F: MOVLW 01
0170: MOVWF 3D
0171: CALL 00C
0172: MOVLW 63
0173: MOVWF 42
0174: CALL 024
.................... for(n=uhel; n>0; n--);
0175: MOVF 23,W
0176: MOVWF 3A
0177: MOVF 3A,F
0178: BTFSC 03.2
0179: GOTO 17C
017A: DECF 3A,F
017B: GOTO 177
.................... output_low(SERVO);
017C: BSF 03.5
017D: BCF 05.2
017E: BCF 03.5
017F: BCF 05.2
.................... }
0180: BCF 0A.3
0181: GOTO 1D4 (RETURN)
....................
.................... ////////////////////////////////////////////////////////////////////////////////
.................... short int IRcheck() // potvrdi detekci cihly
.................... {
.................... output_high(IRTX); // vypne vysilac IR
....................
.................... output_low(STROBE);
.................... sensors = spi_read(0); // cteni senzoru
.................... output_high(STROBE);
....................
.................... if(true==bit_test(sensors,7)) // otestuje, jestli je stale detekovan IR signal
.................... {
.................... output_low(IRTX); // zapne vysilac IR
....................
.................... output_low(STROBE);
.................... sensors = spi_read(0); // cteni senzoru
.................... output_high(STROBE);
....................
.................... if(false==bit_test(sensors,7)) // otestuje, jestli je detekovana cihla
.................... {
.................... output_high(IRTX); // vypne vysilac IR
....................
.................... output_low(STROBE);
.................... sensors = spi_read(0); // cteni senzoru
.................... output_high(STROBE);
....................
.................... if(bit_test(sensors,7)) return 1; //
....................
.................... else return 0; // vrat 0 kdyz je ruseni
.................... }
.................... else return 0; // vrat 0 kdyz to nebyla cihla
.................... }
.................... else return 0; // vrat 0 kdyz je detekovano ruseni
.................... }
.................... ////////////////////////////////////////////////////////////////////////////////
.................... /*
.................... #task (rate=4ms, max=20us)
.................... void rychlost()
.................... {
.................... if(speed<255) speed++;
.................... }
.................... */
.................... ////////////////////////////////////////////////////////////////////////////////
.................... #task (rate=2ms, max=1ms)
.................... void rizeni()
.................... {
.................... unsigned int16 n;
.................... unsigned int8 i;
....................
.................... GO(L,F,Lmotor);GO(R,F,Rmotor); // zapni motory
*
0051: MOVF 01,W
0052: BTFSS 00.7
0053: GOTO 057
0054: BTFSS 26.7
0055: GOTO 05F
0056: GOTO 059
0057: BTFSC 26.7
0058: GOTO 068
0059: MOVF 26,F
005A: BTFSS 03.2
005B: GOTO 05F
005C: SUBWF 25,W
005D: BTFSS 03.0
005E: GOTO 068
005F: BSF 03.5
0060: BCF 05.1
0061: BCF 03.5
0062: BCF 05.1
0063: BSF 03.5
0064: BCF 05.0
0065: BCF 03.5
0066: BSF 05.0
0067: GOTO 070
0068: BSF 03.5
0069: BCF 05.0
006A: BCF 03.5
006B: BCF 05.0
006C: BSF 03.5
006D: BCF 05.1
006E: BCF 03.5
006F: BCF 05.1
0070: MOVF 01,W
0071: BTFSS 00.7
0072: GOTO 076
0073: BTFSS 28.7
0074: GOTO 07E
0075: GOTO 078
0076: BTFSC 28.7
0077: GOTO 087
0078: MOVF 28,F
0079: BTFSS 03.2
007A: GOTO 07E
007B: SUBWF 27,W
007C: BTFSS 03.0
007D: GOTO 087
007E: BSF 03.5
007F: BCF 05.7
0080: BCF 03.5
0081: BCF 05.7
0082: BSF 03.5
0083: BCF 05.6
0084: BCF 03.5
0085: BSF 05.6
0086: GOTO 08F
0087: BSF 03.5
0088: BCF 05.6
0089: BCF 03.5
008A: BCF 05.6
008B: BSF 03.5
008C: BCF 05.7
008D: BCF 03.5
008E: BCF 05.7
....................
.................... delay_us(500);
008F: CLRWDT
0090: MOVLW 02
0091: MOVWF 41
0092: MOVLW F7
0093: MOVWF 42
0094: CALL 024
0095: DECFSZ 41,F
0096: GOTO 092
....................
.................... output_low(STROBE);
0097: BSF 03.5
0098: BCF 06.0
0099: BCF 03.5
009A: BCF 06.0
.................... sensors = spi_read(0); // cteni senzoru
009B: MOVF 13,W
009C: CLRF 13
009D: BSF 03.5
009E: BTFSC 14.0
009F: GOTO 0A2
00A0: BCF 03.5
00A1: GOTO 09D
00A2: BCF 03.5
00A3: MOVF 13,W
00A4: MOVWF 21
.................... sensors=~sensors;
00A5: COMF 21,F
.................... output_high(STROBE);
00A6: BSF 03.5
00A7: BCF 06.0
00A8: BCF 03.5
00A9: BSF 06.0
....................
.................... i=0; // havarijni kod
00AA: CLRF 40
.................... for (n=0; n<=6; n++)
00AB: CLRF 3F
00AC: CLRF 3E
00AD: MOVF 3F,F
00AE: BTFSS 03.2
00AF: GOTO 0C4
00B0: MOVF 3E,W
00B1: SUBLW 06
00B2: BTFSS 03.0
00B3: GOTO 0C4
.................... {
.................... if(bit_test(sensors,n)) i++;
00B4: MOVF 21,W
00B5: MOVWF 77
00B6: MOVF 3E,W
00B7: MOVWF 78
00B8: BTFSC 03.2
00B9: GOTO 0BE
00BA: BCF 03.0
00BB: RRF 77,F
00BC: DECFSZ 78,F
00BD: GOTO 0BA
00BE: BTFSC 77.0
00BF: INCF 40,F
.................... }
00C0: INCF 3E,F
00C1: BTFSC 03.2
00C2: INCF 3F,F
00C3: GOTO 0AD
.................... if (i>3) rtos_terminate(); // zastavi, kdyz je cerno pod vice nez tremi cidly
00C4: MOVF 40,W
00C5: SUBLW 03
00C6: BTFSS 03.0
00C7: GOTO 241
....................
....................
.................... if(bit_test(sensors,3)) //...|...//
00C8: BTFSS 21.3
00C9: GOTO 0D8
.................... {
.................... uhel=STRED;
00CA: MOVLW 80
00CB: MOVWF 23
.................... Lmotor=SPEEDMAX;
00CC: CLRF 26
00CD: MOVLW 78
00CE: MOVWF 25
.................... Rmotor=SPEEDMAX;
00CF: CLRF 28
00D0: MOVWF 27
.................... line=S;
00D1: MOVLW 02
00D2: MOVWF 22
.................... if (rovinka<255) rovinka++;
00D3: INCFSZ 24,W
00D4: GOTO 0D6
00D5: GOTO 0D7
00D6: INCF 24,F
.................... return;
00D7: GOTO 163
.................... }
....................
.................... if(bit_test(sensors,0)) //|......// // z duvodu zkraceni doby reakce se cidla nevyhodnocuji poporade ale od krajnich k prostrednimu
00D8: BTFSS 21.0
00D9: GOTO 0E4
.................... {
.................... uhel=STRED-BEAR3;
00DA: MOVLW 3A
00DB: MOVWF 23
.................... Lmotor=0;
00DC: CLRF 26
00DD: CLRF 25
.................... Rmotor=SPEEDMAX;
00DE: CLRF 28
00DF: MOVLW 78
00E0: MOVWF 27
.................... line=L;
00E1: MOVLW 01
00E2: MOVWF 22
.................... return;
00E3: GOTO 163
.................... }
....................
.................... if(bit_test(sensors,6)) //......|//
00E4: BTFSS 21.6
00E5: GOTO 0EF
.................... {
.................... uhel=STRED+BEAR3;
00E6: MOVLW C6
00E7: MOVWF 23
.................... Rmotor=0;
00E8: CLRF 28
00E9: CLRF 27
.................... Lmotor=SPEEDMAX;
00EA: CLRF 26
00EB: MOVLW 78
00EC: MOVWF 25
.................... line=R;
00ED: CLRF 22
.................... return;
00EE: GOTO 163
....................
.................... }
....................
.................... if(bit_test(sensors,1)) //.|.....//
00EF: BTFSS 21.1
00F0: GOTO 0FC
.................... {
.................... uhel=STRED-BEAR2;
00F1: MOVLW 5E
00F2: MOVWF 23
.................... Lmotor=SPEEDMAX-50;
00F3: CLRF 26
00F4: MOVLW 46
00F5: MOVWF 25
.................... Rmotor=SPEEDMAX;
00F6: CLRF 28
00F7: MOVLW 78
00F8: MOVWF 27
.................... line=S;
00F9: MOVLW 02
00FA: MOVWF 22
.................... return;
00FB: GOTO 163
.................... }
....................
.................... if(bit_test(sensors,5)) //.....|.//
00FC: BTFSS 21.5
00FD: GOTO 109
.................... {
.................... uhel=STRED+BEAR2;
00FE: MOVLW A2
00FF: MOVWF 23
.................... Rmotor=SPEEDMAX-50;
0100: CLRF 28
0101: MOVLW 46
0102: MOVWF 27
.................... Lmotor=SPEEDMAX;
0103: CLRF 26
0104: MOVLW 78
0105: MOVWF 25
.................... line=S;
0106: MOVLW 02
0107: MOVWF 22
.................... return;
0108: GOTO 163
.................... }
....................
.................... if (bit_test(sensors,2)) //..|....//
0109: BTFSS 21.2
010A: GOTO 119
.................... {
.................... uhel=STRED-BEAR1;
010B: MOVLW 74
010C: MOVWF 23
.................... Lmotor=SPEEDMAX;
010D: CLRF 26
010E: MOVLW 78
010F: MOVWF 25
.................... Rmotor=SPEEDMAX;
0110: CLRF 28
0111: MOVWF 27
.................... line=S;
0112: MOVLW 02
0113: MOVWF 22
.................... if (rovinka<255) rovinka++;
0114: INCFSZ 24,W
0115: GOTO 117
0116: GOTO 118
0117: INCF 24,F
.................... return;
0118: GOTO 163
.................... }
....................
.................... if (bit_test(sensors,4)) //....|..//
0119: BTFSS 21.4
011A: GOTO 129
.................... {
.................... uhel=STRED+BEAR1;
011B: MOVLW 8C
011C: MOVWF 23
.................... Rmotor=SPEEDMAX;
011D: CLRF 28
011E: MOVLW 78
011F: MOVWF 27
.................... Lmotor=SPEEDMAX;
0120: CLRF 26
0121: MOVWF 25
.................... line=S;
0122: MOVLW 02
0123: MOVWF 22
.................... if (rovinka<255) rovinka++;
0124: INCFSZ 24,W
0125: GOTO 127
0126: GOTO 128
0127: INCF 24,F
.................... return;
0128: GOTO 163
.................... }
....................
.................... if ((L==line) || (R==line)) // Brzdeni pri vyjeti z trate
0129: DECFSZ 22,W
012A: GOTO 12C
012B: GOTO 12F
012C: MOVF 22,F
012D: BTFSS 03.2
012E: GOTO 160
.................... {
.................... if (rovinka>250)
012F: MOVF 24,W
0130: SUBLW FA
0131: BTFSC 03.0
0132: GOTO 15F
.................... {
.................... BL; BR;
0133: BSF 03.5
0134: BCF 05.0
0135: BCF 03.5
0136: BCF 05.0
0137: BSF 03.5
0138: BCF 05.1
0139: BCF 03.5
013A: BSF 05.1
013B: BSF 03.5
013C: BCF 05.6
013D: BCF 03.5
013E: BCF 05.6
013F: BSF 03.5
0140: BCF 05.7
0141: BCF 03.5
0142: BSF 05.7
.................... for(n=1; n<(60); n++) {rtos_yield(); delay_us(500);};
0143: CLRF 3F
0144: MOVLW 01
0145: MOVWF 3E
0146: MOVF 3F,F
0147: BTFSS 03.2
0148: GOTO 15F
0149: MOVF 3E,W
014A: SUBLW 3B
014B: BTFSS 03.0
014C: GOTO 15F
014D: MOVLW 53
014E: MOVWF 35
014F: MOVLW 01
0150: MOVWF 36
0151: BCF 0A.3
0152: GOTO 234
0153: CLRWDT
0154: MOVLW 02
0155: MOVWF 41
0156: MOVLW F7
0157: MOVWF 42
0158: CALL 024
0159: DECFSZ 41,F
015A: GOTO 156
015B: INCF 3E,F
015C: BTFSC 03.2
015D: INCF 3F,F
015E: GOTO 146
.................... };
.................... rovinka=0;
015F: CLRF 24
.................... }
....................
.................... if(bit_test(sensors,7)) // zjisti jestli neni cihla
0160: BTFSS 21.7
0161: GOTO 163
.................... {
.................... rtos_terminate();
0162: GOTO 241
.................... }
.................... }
0163: MOVLW 51
0164: MOVWF 35
0165: MOVLW 00
0166: MOVWF 36
0167: BCF 0A.3
0168: GOTO 234
0169: RETLW 00
....................
....................
....................
.................... ////////////////////////////////////////////////////////////////////////////////
.................... void main()
.................... {
*
0182: CLRF 04
0183: MOVLW 1F
0184: ANDWF 03,F
0185: MOVLW 70
0186: BSF 03.5
0187: MOVWF 0F
0188: BCF 1F.4
0189: BCF 1F.5
018A: MOVF 1B,W
018B: ANDLW 80
018C: MOVWF 1B
018D: MOVLW 07
018E: MOVWF 1C
.................... unsigned int16 i;
.................... unsigned int8 last;
....................
.................... setup_adc_ports(NO_ANALOGS);
018F: BCF 1F.4
0190: BCF 1F.5
0191: MOVF 1B,W
0192: ANDLW 80
0193: MOVWF 1B
.................... setup_adc(ADC_CLOCK_INTERNAL);
0194: BCF 1F.6
0195: BCF 03.5
0196: BSF 1F.6
0197: BSF 1F.7
0198: BSF 03.5
0199: BCF 1F.7
019A: BCF 03.5
019B: BSF 1F.0
.................... setup_spi(SPI_MASTER|SPI_H_TO_L|SPI_XMIT_L_TO_H|SPI_CLK_DIV_4);
019C: BCF 14.5
019D: BSF 03.5
019E: BCF 06.2
019F: BSF 06.1
01A0: BCF 06.4
01A1: MOVLW 30
01A2: BCF 03.5
01A3: MOVWF 14
01A4: MOVLW 00
01A5: BSF 03.5
01A6: MOVWF 14
.................... setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
01A7: MOVF 01,W
01A8: ANDLW C7
01A9: IORLW 08
01AA: MOVWF 01
.................... setup_timer_1(T1_DISABLED);
01AB: BCF 03.5
01AC: CLRF 10
.................... setup_oscillator(OSC_8MHZ|OSC_INTRC);
01AD: MOVLW 72
01AE: BSF 03.5
01AF: MOVWF 0F
....................
.................... STOPR; STOPL; // zastav motory
01B0: BCF 05.6
01B1: BCF 03.5
01B2: BCF 05.6
01B3: BSF 03.5
01B4: BCF 05.7
01B5: BCF 03.5
01B6: BCF 05.7
01B7: BSF 03.5
01B8: BCF 05.0
01B9: BCF 03.5
01BA: BCF 05.0
01BB: BSF 03.5
01BC: BCF 05.1
01BD: BCF 03.5
01BE: BCF 05.1
.................... Lmotor=0;Rmotor=0;
01BF: CLRF 26
01C0: CLRF 25
01C1: CLRF 28
01C2: CLRF 27
....................
.................... uhel=STRED; // nastav zadni kolecko na stred
01C3: MOVLW 80
01C4: MOVWF 23
.................... rovinka=0;
01C5: CLRF 24
....................
.................... output_low(IRTX); // zapni IR vysilac
01C6: BSF 03.5
01C7: BCF 06.2
01C8: BCF 03.5
01C9: BCF 06.2
....................
.................... for(i=0;i<100;i++) // pockej, nez se zadni kolecko vystredi
01CA: CLRF 38
01CB: CLRF 37
01CC: MOVF 38,F
01CD: BTFSS 03.2
01CE: GOTO 1DB
01CF: MOVF 37,W
01D0: SUBLW 63
01D1: BTFSS 03.0
01D2: GOTO 1DB
.................... {
.................... diag();
01D3: GOTO 16A
.................... delay_ms(16);
01D4: MOVLW 10
01D5: MOVWF 3D
01D6: CALL 00C
.................... }
01D7: INCF 37,F
01D8: BTFSC 03.2
01D9: INCF 38,F
01DA: GOTO 1CC
.................... // diagnostika();
....................
.................... while(true)
.................... {
.................... rtos_run();
01DB: CLRF 29
01DC: CLRF 2B
01DD: MOVLW 09
01DE: MOVWF 2A
01DF: CLRF 2D
01E0: CLRF 2C
01E1: MOVLW 34
01E2: MOVWF 2E
01E3: MOVLW 00
01E4: MOVWF 2F
01E5: CLRF 30
01E6: CLRF 32
01E7: MOVLW 01
01E8: MOVWF 31
01E9: CLRF 34
01EA: CLRF 33
01EB: MOVLW 51
01EC: MOVWF 35
01ED: MOVLW 00
01EE: MOVWF 36
01EF: CLRF 20
01F0: MOVLW 00
01F1: MOVWF 78
01F2: IORLW 06
01F3: MOVWF 12
01F4: MOVLW FA
01F5: BSF 03.5
01F6: MOVWF 12
01F7: BCF 03.5
01F8: BCF 0C.1
01F9: MOVLW 00
01FA: MOVWF 78
01FB: IORLW 06
01FC: MOVWF 12
01FD: MOVLW FA
01FE: BSF 03.5
01FF: MOVWF 12
0200: BCF 03.5
0201: BCF 0C.1
0202: BCF 03.0
0203: RLF 20,W
0204: MOVWF 77
0205: CALL 004
0206: MOVWF 79
0207: MOVLW 01
0208: ADDWF 77,W
0209: CALL 004
020A: MOVWF 7A
020B: MOVF 79,W
020C: MOVWF 04
020D: MOVF 00,W
020E: MOVWF 79
020F: INCF 04,F
0210: MOVF 00,W
0211: MOVWF 77
0212: INCF 04,F
0213: MOVF 00,W
0214: MOVWF 78
0215: INCF 04,F
0216: INCF 00,F
0217: MOVF 00,W
0218: MOVWF 7A
0219: BTFSS 03.2
021A: GOTO 21E
021B: INCF 04,F
021C: INCF 00,F
021D: DECF 04,F
021E: INCF 04,F
021F: MOVF 00,W
0220: SUBWF 78,W
0221: BTFSS 03.2
0222: GOTO 236
0223: MOVF 77,W
0224: SUBWF 7A,W
0225: BTFSS 03.2
0226: GOTO 236
0227: DECF 04,F
0228: CLRF 00
0229: INCF 04,F
022A: CLRF 00
022B: INCF 04,F
022C: BTFSC 79.7
022D: GOTO 236
022E: INCF 04,F
022F: MOVF 00,W
0230: MOVWF 0A
0231: DECF 04,F
0232: MOVF 00,W
0233: MOVWF 02
0234: BCF 03.5
0235: BCF 03.6
0236: INCF 20,F
0237: MOVLW 02
0238: SUBWF 20,W
0239: BTFSS 03.2
023A: GOTO 202
023B: CLRF 20
023C: BTFSS 0C.1
023D: GOTO 240
023E: BSF 03.5
023F: GOTO 200
0240: GOTO 23C
0241: MOVLW FF
0242: MOVWF 20
.................... STOPR;
0243: BSF 03.5
0244: BCF 05.6
0245: BCF 03.5
0246: BCF 05.6
0247: BSF 03.5
0248: BCF 05.7
0249: BCF 03.5
024A: BCF 05.7
.................... STOPL;
024B: BSF 03.5
024C: BCF 05.0
024D: BCF 03.5
024E: BCF 05.0
024F: BSF 03.5
0250: BCF 05.1
0251: BCF 03.5
0252: BCF 05.1
.................... while(true);
0253: GOTO 253
.................... }
0254: GOTO 1DB
.................... }
0255: SLEEP
 
Configuration Fuses:
Word 1: 3F38 NOWDT NOPUT MCLR NOBROWNOUT NOLVP NOCPD NOWRT NODEBUG CCPB0 NOPROTECT INTRC_IO
Word 2: 3FFC NOFCMEN NOIESO
/roboti/istrobot/3Orbis/bak/04 posledni RTOS/main/main.PJT
0,0 → 1,41
[PROJECT]
Target=main.HEX
Development_Mode=
Processor=0x688F
ToolSuite=CCS
 
[Directories]
Include=C:\Program Files\PICC\devices\;C:\Program Files\PICC\dr
Library=
LinkerScript=
 
[Target Data]
FileList=D:\KAKLIK\programy\PIC_C\roboti\istrobot\3Orbis\main.c
BuildTool=C-COMPILER
OptionString=+FM
AdditionalOptionString=
BuildRequired=1
 
[main.c]
Type=4
Path=
FileList=
BuildTool=
OptionString=
AdditionalOptionString=
 
[mru-list]
1=main.c
 
[Windows]
0=0000 main.c 0 0 796 451 3 0
 
[Opened Files]
1=D:\KAKLIK\programy\PIC_C\roboti\istrobot\3Orbis\main.c
2=C:\Program Files\PICC\devices\16F88.h
3=D:\KAKLIK\programy\PIC_C\roboti\istrobot\3Orbis\main.h
4=
5=
[Units]
Count=1
1=D:\KAKLIK\programy\PIC_C\roboti\istrobot\3Orbis\main.c (main)
/roboti/istrobot/3Orbis/bak/04 posledni RTOS/main/main.SYM
0,0 → 1,83
015 CCP_1_LOW
015-016 CCP_1
016 CCP_1_HIGH
020 @CURRENT_TASK
021 sensors
022 line
023 uhel
024 rovinka
025-026 Lmotor
027-028 Rmotor
029-02F @TASKINFO1_2_2_0_0
030-036 @TASKINFO2_2_2_0_0
037-038 main.i
039 main.last
03A diag.n
03C zatoc.n
03D @delay_ms1.P1
03E-03F rizeni.n
040 rizeni.i
041 rizeni.@SCRATCH
042 @delay_us1.P1
077 @SCRATCH
078 @SCRATCH
078 _RETURN_
079 @SCRATCH
07A @SCRATCH
07B @SCRATCH
09C.6 C1OUT
09C.7 C2OUT
 
000C @delay_ms1
0024 @delay_us1
0034 zatoc
016A diag
0051 rizeni
0182 main
0004 @const10176
0182 @cinit
 
Project Files:
D:\KAKLIK\programy\PIC_C\roboti\istrobot\3Orbis\main.c
D:\KAKLIK\programy\PIC_C\roboti\istrobot\3Orbis\main.h
C:\Program Files\PICC\devices\16F88.h
 
Units:
D:\KAKLIK\programy\PIC_C\roboti\istrobot\3Orbis\main.c (main)
 
Compiler Settings:
Processor: PIC16F88
Pointer Size: 8
ADC Range: 0-255
Opt Level: 9
Short,Int,Long: 1,8,16
 
Task Schedule:
2, ms zatoc
1, ms rizeni
Sync to next 2, ms
1, ms rizeni
Sync to next 2, ms
1, ms rizeni
Sync to next 2, ms
1, ms rizeni
Sync to next 2, ms
1, ms rizeni
Sync to next 2, ms
1, ms rizeni
Sync to next 2, ms
1, ms rizeni
Sync to next 2, ms
1, ms rizeni
Sync to next 2, ms
1, ms rizeni
Sync to next 2, ms
 
Output Files:
Errors: D:\KAKLIK\programy\PIC_C\roboti\istrobot\3Orbis\main.err
INHX8: D:\KAKLIK\programy\PIC_C\roboti\istrobot\3Orbis\main.hex
Symbols: D:\KAKLIK\programy\PIC_C\roboti\istrobot\3Orbis\main.sym
List: D:\KAKLIK\programy\PIC_C\roboti\istrobot\3Orbis\main.lst
Debug/COFF: D:\KAKLIK\programy\PIC_C\roboti\istrobot\3Orbis\main.cof
Call Tree: D:\KAKLIK\programy\PIC_C\roboti\istrobot\3Orbis\main.tre
Statistics: D:\KAKLIK\programy\PIC_C\roboti\istrobot\3Orbis\main.sta
/roboti/istrobot/3Orbis/bak/04 posledni RTOS/main/main.c
0,0 → 1,275
#include ".\main.h"
 
#use rtos (timer=2, minor_cycle=2ms)
 
#define STRED 128 // sredni poloha zadniho kolecka
#define BEAR1 12 // 3 stupne zataceni
#define BEAR2 34
#define BEAR3 70
#define SPEEDMAX 120 // maximalni rychlost
 
#define L 1
#define S 2
#define R 0
 
// servo
#define SERVO PIN_A2
 
// IR
#define IRTX PIN_B2
 
//motory
#define FR output_low(PIN_A7); output_high(PIN_A6) // Vpred
#define FL output_low(PIN_A1); output_high(PIN_A0)
#define BR output_low(PIN_A6); output_high(PIN_A7) // Vzad
#define BL output_low(PIN_A0); output_high(PIN_A1)
#define STOPR output_low(PIN_A6);output_low(PIN_A7)
#define STOPL output_low(PIN_A0);output_low(PIN_A1)
 
//HID
#define LED1 PIN_B1 //oranzova
#define LED2 PIN_B2 //zluta
 
#define STROBE PIN_B0
//#define SW1 PIN_A2 // Motory On/off
 
unsigned int8 sensors; // pomocna promenna pro cteni cidel na caru
unsigned int8 line; // na ktere strane byla detekovana cara
//unsigned int8 dira; // pocita dobu po kterou je ztracena cara
unsigned int8 uhel; // urcuje aktualni uhel zataceni
//unsigned int8 speed; // maximalni povolena rychlost
unsigned int8 rovinka; // pocitadlo na zjisteni rovinky
 
signed int16 Lmotor; // promene, ktere urcuji velikost vykonu na levem
signed int16 Rmotor; // a pravem motoru
 
// makro pro PWM
#define GO(motor, direction, power) if(get_timer0()<=power) \
{direction##motor;} else {stop##motor;}
 
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/*
void diagnostika()
{
if(input(SW1))STOPR;STOPL;While(TRUE);
// if(LSENSOR==true) output_high(LED2); else output_low(LED2);
// if(RSENSOR==true) output_high(LED1); else output_low(LED1);
}
*/
////////////////////////////////////////////////////////////////////////////////
#task (rate=18ms,max=2ms)
void zatoc() // ridi servo ktere otaci kolem
{
unsigned int8 n;
 
output_high(SERVO);
delay_us(1100);
for(n=uhel; n>0; n--);
output_low(SERVO);
}
 
////////////////////////////////////////////////////////////////////////////////
void diag() // ridi servo ktere otaci kolem
{
unsigned int8 n;
 
output_high(SERVO);
delay_us(1100);
for(n=uhel; n>0; n--);
output_low(SERVO);
}
 
////////////////////////////////////////////////////////////////////////////////
short int IRcheck() // potvrdi detekci cihly
{
output_high(IRTX); // vypne vysilac IR
 
output_low(STROBE);
sensors = spi_read(0); // cteni senzoru
output_high(STROBE);
 
if(true==bit_test(sensors,7)) // otestuje, jestli je stale detekovan IR signal
{
output_low(IRTX); // zapne vysilac IR
 
output_low(STROBE);
sensors = spi_read(0); // cteni senzoru
output_high(STROBE);
 
if(false==bit_test(sensors,7)) // otestuje, jestli je detekovana cihla
{
output_high(IRTX); // vypne vysilac IR
 
output_low(STROBE);
sensors = spi_read(0); // cteni senzoru
output_high(STROBE);
 
if(bit_test(sensors,7)) return 1; //
 
else return 0; // vrat 0 kdyz je ruseni
}
else return 0; // vrat 0 kdyz to nebyla cihla
}
else return 0; // vrat 0 kdyz je detekovano ruseni
}
////////////////////////////////////////////////////////////////////////////////
void ojizdka()
{
}
////////////////////////////////////////////////////////////////////////////////
/*
#task (rate=4ms, max=20us)
void rychlost()
{
if(speed<255) speed++;
}
*/
////////////////////////////////////////////////////////////////////////////////
#task (rate=2ms, max=1ms)
void rizeni()
{
unsigned int16 n;
unsigned int8 i;
 
GO(L,F,Lmotor);GO(R,F,Rmotor); // zapni motory
 
delay_us(500);
 
output_low(STROBE);
sensors = spi_read(0); // cteni senzoru
sensors=~sensors;
output_high(STROBE);
i=0; // havarijni kod
for (n=0; n<=6; n++)
{
if(bit_test(sensors,n)) i++;
}
if (i>3) rtos_terminate(); // zastavi, kdyz je cerno pod vice nez tremi cidly
 
if(bit_test(sensors,3)) //...|...//
{
uhel=STRED;
Lmotor=SPEEDMAX;
Rmotor=SPEEDMAX;
line=S;
if (rovinka<255) rovinka++;
return;
}
 
if(bit_test(sensors,0)) //|......// // z duvodu zkraceni doby reakce se cidla nevyhodnocuji poporade ale od krajnich k prostrednimu
{
uhel=STRED-BEAR3;
Lmotor=0;
Rmotor=SPEEDMAX;
line=L;
return;
}
 
if(bit_test(sensors,6)) //......|//
{
uhel=STRED+BEAR3;
Rmotor=0;
Lmotor=SPEEDMAX;
line=R;
return;
 
}
 
if(bit_test(sensors,1)) //.|.....//
{
uhel=STRED-BEAR2;
Lmotor=SPEEDMAX-50;
Rmotor=SPEEDMAX;
line=S;
return;
}
 
if(bit_test(sensors,5)) //.....|.//
{
uhel=STRED+BEAR2;
Rmotor=SPEEDMAX-50;
Lmotor=SPEEDMAX;
line=S;
return;
}
 
if (bit_test(sensors,2)) //..|....//
{
uhel=STRED-BEAR1;
Lmotor=SPEEDMAX;
Rmotor=SPEEDMAX;
line=S;
if (rovinka<255) rovinka++;
return;
}
 
if (bit_test(sensors,4)) //....|..//
{
uhel=STRED+BEAR1;
Rmotor=SPEEDMAX;
Lmotor=SPEEDMAX;
line=S;
if (rovinka<255) rovinka++;
return;
}
 
if ((L==line) || (R==line)) // Brzdeni pri vyjeti z trate
{
if (rovinka>250)
{
BL; BR;
for(n=1; n<(60); n++) {rtos_yield(); delay_us(500);};
};
rovinka=0;
}
if(bit_test(sensors,7)) // zjisti jestli neni cihla
{
rtos_terminate();
}
}
 
 
 
////////////////////////////////////////////////////////////////////////////////
void main()
{
unsigned int16 i;
unsigned int8 last;
 
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_CLOCK_INTERNAL);
setup_spi(SPI_MASTER|SPI_H_TO_L|SPI_XMIT_L_TO_H|SPI_CLK_DIV_4);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_oscillator(OSC_8MHZ|OSC_INTRC);
 
STOPR; STOPL; // zastav motory
Lmotor=0;Rmotor=0;
 
uhel=STRED; // nastav zadni kolecko na stred
rovinka=0;
 
output_low(IRTX); // zapni IR vysilac
 
for(i=0;i<100;i++) // pockej, nez se zadni kolecko vystredi
{
diag();
delay_ms(16);
}
// diagnostika();
 
while(true)
{
rtos_run();
STOPR;
STOPL;
If(IRcheck()) objizdka();
while(true);
}
}
/roboti/istrobot/3Orbis/bak/04 posledni RTOS/main/main.cof
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/roboti/istrobot/3Orbis/bak/04 posledni RTOS/main/main.err
0,0 → 1,2
No Errors
0 Errors, 0 Warnings.
/roboti/istrobot/3Orbis/bak/04 posledni RTOS/main/main.h
0,0 → 1,18
#include <16F88.h>
#device adc=8
 
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO
#FUSES NOPUT //No Power Up Timer
#FUSES MCLR //Master Clear pin enabled
#FUSES NOBROWNOUT //Reset when brownout detected
#FUSES NOLVP //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOFCMEN //Fail-safe clock monitor enabled
#FUSES NOIESO //Internal External Switch Over mode enabled
 
#use delay(clock=8000000,RESTART_WDT)
 
/roboti/istrobot/3Orbis/bak/04 posledni RTOS/main/main.sta
0,0 → 1,34
 
ROM used: 598 (15%)
598 (15%) including unused fragments
 
1 Average locations per line
4 Average locations per statement
 
RAM used: 31 (18%) at main() level
40 (23%) worst case
 
Lines Stmts % Files
----- ----- --- -----
269 160 100 D:\KAKLIK\programy\PIC_C\roboti\istrobot\3Orbis\main.c
19 0 0 D:\KAKLIK\programy\PIC_C\roboti\istrobot\3Orbis\main.h
279 0 0 C:\Program Files\PICC\devices\16F88.h
----- -----
1134 320 Total
 
Page ROM % RAM Functions:
---- --- --- --- ----------
0 24 4 1 @delay_ms1
0 16 3 1 @delay_us1
0 29 5 1 zatoc
0 24 4 1 diag
0 281 47 4 rizeni
0 212 35 3 main
0 8 1 0 @const10176
 
Segment Used Free
--------- ---- ----
00000-00003 4 0
00004-007FF 594 1450
00800-00FFF 0 2048
 
/roboti/istrobot/3Orbis/bak/04 posledni RTOS/main/main.tre
0,0 → 1,15
ÀÄmain
ÃÄmain 0/212 Ram=3
³ ÃÄ??0??
³ ÃÄdiag 0/24 Ram=1
³ ³ ÃÄ@delay_ms1 0/24 Ram=1
³ ³ ÀÄ@delay_us1 0/16 Ram=1
³ ÃÄ@delay_ms1 0/24 Ram=1
³ ÃÄ@const10176 0/8 Ram=0
³ ÀÄ@const10176 0/8 Ram=0
ÃÄzatoc 0/29 Ram=1
³ ÃÄ@delay_ms1 0/24 Ram=1
³ ÀÄ@delay_us1 0/16 Ram=1
ÀÄrizeni 0/281 Ram=4
ÃÄ@delay_us1 0/16 Ram=1
ÀÄ@delay_us1 0/16 Ram=1