Subversion Repositories svnkaklik

Rev

Go to most recent revision | Details | Last modification | View Log

Rev Author Line No. Line
135 kakl 1
#include "laser.h"
2
#include "16F88_Reg.H"
3
 
4
#define SERVO PIN_B5    // Vystup pro rizeni serva
5
#define LASER PIN_B4    // Vstup pro cteni laseru
6
 
7
// kroutitka
8
#define  CERVENA  0  // AN0
9
#define  CERNA    1  // AN1
10
//#define  ZELENA   3  // AN3
11
//#define  MODRA    4  // AN4
12
 
13
//#define OFFSET 100       // Predni kolecko vprostred pri care vprostred
14
//#define HYSTERESE 3      // Rozdil mezi behem tam a zpet
15
 
16
boolean edge;
17
int8 uhel;
18
 
19
#int_EXT
20
EXT_isr()
21
{
22
   int n, t1, t2, t;
23
 
24
   set_timer0(0);          // Vynulovani casovace pro 2ms
25
   output_high(SERVO);
26
   while(get_timer0()<(1000/256));    // Ceka 1ms
27
   for(n=uhel; n>0; n--) delay_us(3); // Sirka impulzu podle uhlu
28
   output_low(SERVO);
29
   while(get_timer0()<(3000/256)); // Ceka do 3ms, nez zacne scanovat
30
 
31
   set_timer0(0);          // Vynulovani casovace pro zjisteni polohy cary
32
   if(edge)                // Zrcatko prejizdelo tam nebo zpet?
33
   {
34
     edge=false;
35
     ext_int_edge(H_TO_L);    // Pristi inerrupt bude od opacne hrany
36
     INT0IF_1=0;              // Povoleni dalsiho preruseni
37
     enable_interrupts(INT_EXT);
38
     enable_interrupts(GLOBAL);
39
//     do
40
     {
41
       while(0==input(LASER));  // Ceka na detekci cary
42
//   output_high(SERVO);
43
       t1=get_timer0();         // Poznamena cas nabezne hrany
44
       while(1==input(LASER));  // Ceka az zkonci cara
45
//   output_low(SERVO);
46
       t2=get_timer0();         // Poznamena cas sestupne hrany
47
       t=t2-t1;
48
     } //while((t<5) || (t>7)); // Cara je detekovana, kdyz trva mezi xx ms
49
     if ((t>3) && (t<8)) uhel=(160-(read_adc()>>2))-t1;
50
     set_adc_channel(1);
51
   }
52
   else
53
   {
54
     edge=true;
55
     ext_int_edge(L_TO_H);
56
     INT0IF_1=0;              // Povoleni dalsiho preruseni
57
     enable_interrupts(INT_EXT);
58
     enable_interrupts(GLOBAL);
59
//     do
60
     {
61
       while(0==input(LASER));  // Ceka na detekci cary
62
       t1=get_timer0();         // Poznamena cas nabezne hrany
63
       while(1==input(LASER));  // Ceka az zkonci cara
64
       t2=get_timer0();         // Poznamena cas sestupne hrany
65
       t=t2-t1;
66
     } //while((t<5) || (t>7)); // Cara je detekovana, kdyz trva mezi xx ms
67
     if ((t>3) && (t<8)) uhel=((read_adc()>>2)+32)+t1;
68
     set_adc_channel(0);
69
   }
70
   while(true);
71
}
72
 
73
 
74
 
75
void main()
76
{
77
   setup_adc_ports(sAN0|sAN1|VSS_VDD); // AD pro kroutitka
78
   setup_adc(ADC_CLOCK_INTERNAL);
79
   setup_spi(FALSE);
80
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
81
   setup_timer_1(T1_DISABLED);
82
   setup_timer_2(T2_DISABLED,0,1);
83
   setup_comparator(NC_NC_NC_NC);
84
   setup_vref(FALSE);
85
   setup_oscillator(False);
86
 
87
   delay_ms(100);
88
   set_adc_channel(0);
89
   Delay_ms(1);
90
 
91
   ext_int_edge(L_TO_H);
92
   edge=true;
93
   uhel=((read_adc()>>2)+32)+30;;
94
   enable_interrupts(INT_EXT);
95
   enable_interrupts(GLOBAL);
96
}