Subversion Repositories svnkaklik

Rev

Rev 152 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 152 Rev 153
Line 1... Line 1...
1
#include ".\camerus.h"
1
#include ".\camerus.h"
2
 
2
 
3
#USE FAST_IO (C)
3
#USE FAST_IO (C)
4
 
4
 
5
// kroutitka
5
// kroutitka
6
#define  CERVENA  1  // AN1
6
#define  CERVENA  3  // AN3/RA3
7
#define  CERNA    4  // AN4
7
#define  CERNA    2  // AN2/RA2
8
#define  ZELENA   3  // AN3
8
#define  ZELENA   1  // AN1/RA0
9
#define  MODRA    0  // AN0
9
#define  MODRA    0  // AN0/RA1
10
 
10
 
11
// I/O
11
// I/O
12
#define LED    PIN_C0
12
#define LED    PIN_C0
13
#define HREF   PIN_C5
13
#define HREF   PIN_C5
14
#define PIX    PIN_C6
14
#define PIX    PIN_C6
15
#define SERVO  PIN_B7
15
#define SERVO  PIN_B7
-
 
16
#define MOT_L  PIN_B5
-
 
17
#define MOT_R  PIN_B6
16
 
18
 
17
void main()
19
void main()
18
{
20
{
19
   int8 cas;
21
   int8 cas;
20
   int16 offset;
22
   int8 offset;
-
 
23
   int8 rr; // Rozumna rychlost
-
 
24
   int8 r1;
-
 
25
   int8 r2;
21
 
26
 
-
 
27
   int16 ble;
-
 
28
   
22
   setup_adc_ports(ALL_ANALOG);
29
   setup_adc_ports(ALL_ANALOG);
23
   setup_adc(ADC_CLOCK_INTERNAL);
30
   setup_adc(ADC_CLOCK_INTERNAL);
24
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
31
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
25
   setup_timer_1(T1_DISABLED);
32
   setup_timer_1(T1_DISABLED);
26
   setup_timer_2(T2_DIV_BY_16,255,1);
33
   setup_timer_2(T2_DIV_BY_16,255,1);
Line 29... Line 36...
29
   setup_comparator(NC_NC_NC_NC);
36
   setup_comparator(NC_NC_NC_NC);
30
   setup_vref(FALSE);
37
   setup_vref(FALSE);
31
 
38
 
32
   set_tris_c(0b11111000);
39
   set_tris_c(0b11111000);
33
 
40
 
-
 
41
   set_pwm1_duty(0);   // Zastav motory
-
 
42
   set_pwm2_duty(0);
-
 
43
   output_low(MOT_L);
-
 
44
   output_low(MOT_R);
-
 
45
 
34
   output_high(LED);
46
   output_high(LED);
35
 
47
 
36
   delay_ms(200);
48
   delay_ms(200);
37
 
49
 
38
   i2c_start();      // Reset
50
   i2c_start();      // Reset
Line 84... Line 96...
84
   i2c_write(0x1A);
96
   i2c_write(0x1A);
85
   i2c_write(45);
97
   i2c_write(45);
86
   i2c_stop();
98
   i2c_stop();
87
 
99
 
88
   output_low(LED);
100
   output_low(LED);
89
   delay_ms(100);
101
   delay_ms(200);
90
 
102
 
91
/*
103
/*
92
   i2c_start();      // BW + freeze AGC/AEC
104
   i2c_start();      // BW + freeze AGC/AEC
93
   i2c_write(0xC0);
105
   i2c_write(0xC0);
94
   i2c_write(0x28);
106
   i2c_write(0x28);
95
   i2c_write(0b01010001);
107
   i2c_write(0b01010001);
96
   i2c_stop();
108
   i2c_stop();
97
*/
109
*/
98
   output_high(LED);
110
   output_high(LED);
99
   delay_ms(100);
111
   delay_ms(200);
100
   output_low(LED);
112
   output_low(LED);
101
 
113
 
102
   cas=128;
114
   cas=128;
103
 
115
 
-
 
116
   ble=0;
-
 
117
   
104
   while(true)
118
   while(true)
105
   {
119
   {
106
      while(!input(HREF));
120
      while(!input(HREF));
107
//      delay_cycles(4);
121
//      delay_cycles(4);
108
      set_timer0(0);
122
      set_timer0(0);
Line 126... Line 140...
126
      delay_us(offset);
140
      delay_us(offset);
127
      delay_us(cas);
141
      delay_us(cas);
128
      delay_us(cas);
142
      delay_us(cas);
129
//      delay_us(cas);
143
//      delay_us(cas);
130
      output_low(SERVO);
144
      output_low(SERVO);
-
 
145
      
-
 
146
      ble++;
-
 
147
      set_adc_channel(ZELENA);
-
 
148
      Delay_ms(1);
-
 
149
      offset=read_adc();
-
 
150
      set_adc_channel(CERNA);
-
 
151
      Delay_ms(1);
-
 
152
      rr=read_adc();
-
 
153
      r1=cas>>1;
-
 
154
      r2=255-offset-(cas>>1);
-
 
155
      if (ble==99)
-
 
156
      {
131
      set_pwm1_duty(cas);
157
         set_pwm1_duty(rr);
-
 
158
         set_pwm2_duty(rr);      
-
 
159
      };
-
 
160
      if ((ble>100)&&(ble<60000))
-
 
161
      {      
-
 
162
         if (r1<=rr) set_pwm1_duty(r1);
-
 
163
         if (r2<=rr) set_pwm2_duty(r2);
-
 
164
      }
-
 
165
      else
-
 
166
      {
-
 
167
         set_pwm1_duty(0);
132
      set_pwm2_duty(255-cas);
168
         set_pwm2_duty(0);
-
 
169
      }
133
   };
170
   };
134
}
171
}