Subversion Repositories svnkaklik

Rev

Rev 206 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 206 Rev 209
Line 1... Line 1...
1
// Program pro MiniSumo na R-Day 2006
1
// Program pro MiniSumo na R-Day 2006
2
//"$Id: cholerik.c 206 2007-03-21 10:02:02Z kakl $"
2
//"$Id: cholerik.c 209 2007-03-22 22:03:46Z kakl $"
3
 
3
 
4
#include "cholerik.h"
4
#include "cholerik.h"
5
 
5
 
6
// Konstanty
6
// Konstanty
7
#define TRESHOLD     0x250        // rozhodovaci uroven pro okraj areny
7
#define TRESHOLD     0x90        // rozhodovaci uroven pro okraj areny
8
//#define DEBUG1 1   // Diagnostika pohonu
8
//#define DEBUG1 1   // Diagnostika pohonu
9
 
9
 
10
//motory            //Napred vypnout potom zapnout!
10
//motory            //Napred vypnout potom zapnout!
11
#define FR         output_low(PIN_B5); output_high(PIN_B4)  // Vpred
11
#define FR         output_low(PIN_B5); output_high(PIN_B4)  // Vpred
12
#define FL         output_low(PIN_B7); output_high(PIN_B6)
12
#define FL         output_low(PIN_B7); output_high(PIN_B6)
Line 51... Line 51...
51
   if (((SIDE_L && stav) || (!SIDE_L && !stav))) {if (sl<255) sl++;} else {sl=0;};
51
   if (((SIDE_L && stav) || (!SIDE_L && !stav))) {if (sl<255) sl++;} else {sl=0;};
52
   if (((BACK && stav) || (!BACK && !stav))) {if (b<255) b++;} else {b=0;};
52
   if (((BACK && stav) || (!BACK && !stav))) {if (b<255) b++;} else {b=0;};
53
   if (((FRONT && stav) || (!FRONT && !stav))) {if (f<255) f++;} else {f=0;};
53
   if (((FRONT && stav) || (!FRONT && !stav))) {if (f<255) f++;} else {f=0;};
54
   majak++;
54
   majak++;
55
   stav = ((majak & 0b1) == 0b1);
55
   stav = ((majak & 0b1) == 0b1);
-
 
56
if (input(PIN_A3)) arena_r=TRUE; else arena_r=FALSE;
-
 
57
if (input(PIN_A2)) arena_l=TRUE; else arena_l=FALSE;
56
   if (stav)
58
   if (stav)
57
   {
59
   {
58
      if (read_adc(ADC_READ_ONLY) > TRESHOLD) arena_l=TRUE; else arena_l=FALSE;
60
//      if (read_adc(ADC_READ_ONLY) > TRESHOLD) arena_l=TRUE; else arena_l=FALSE;
59
      set_adc_channel(R); // prepnuti kanalu ADC, je treba min 10us na ustaleni
61
//      set_adc_channel(R); // prepnuti kanalu ADC, je treba min 10us na ustaleni
60
      delay_us(10);
62
//      delay_us(10);
61
      read_adc(ADC_START_ONLY);
63
//      read_adc(ADC_START_ONLY);
62
      set_pwm1_duty(27);      // 1:1
64
      set_pwm1_duty(27);      // 1:1
63
   }
65
   }
64
   else
66
   else
65
   {
67
   {
66
      if (read_adc(ADC_READ_ONLY) > TRESHOLD) arena_r=TRUE; else arena_r=FALSE;
68
//      if (read_adc(ADC_READ_ONLY) > TRESHOLD) arena_r=TRUE; else arena_r=FALSE;
67
      set_adc_channel(L); // prepnuti kanalu ADC, je treba min 10us na ustaleni
69
//      set_adc_channel(L); // prepnuti kanalu ADC, je treba min 10us na ustaleni
68
      delay_us(10);
70
//      delay_us(10);
69
      read_adc(ADC_START_ONLY);
71
//      read_adc(ADC_START_ONLY);
70
      set_pwm1_duty(55);      // 1:0
72
      set_pwm1_duty(55);      // 1:0
71
   };
73
   };
72
 
-
 
73
   if (GRAVITY) {if (g<255) g++;} else g=0;
74
   if (GRAVITY) {if (g<255) g++;} else g=0;
74
   if (g>3 && !diag) {FL; FR; while(TRUE);}; // kdyz nas preklopi, nedej se
75
   if (g>3 && !diag) {FL; FR; while(TRUE);}; // kdyz nas preklopi, nedej se
75
}
76
}
76
 
77
 
77
// Primitivni Pipani
78
// Primitivni Pipani
Line 117... Line 118...
117
      FL; FR; Delay_ms(1000); STOPL; STOPR; Delay_ms(1000);
118
      FL; FR; Delay_ms(1000); STOPL; STOPR; Delay_ms(1000);
118
      BL; BR; Delay_ms(1000); STOPL; STOPR; Delay_ms(1000);
119
      BL; BR; Delay_ms(1000); STOPL; STOPR; Delay_ms(1000);
119
   };
120
   };
120
#endif
121
#endif
121
 
122
 
-
 
123
//!!!!!!!!!!!!!!!
-
 
124
/*
122
   if (GRAVITY) {
125
while(true)
-
 
126
{
-
 
127
      set_adc_channel(R); // prepnuti kanalu ADC, je treba min 10us na ustaleni
123
   diag=TRUE;
128
      delay_us(10);
124
   enable_interrupts(INT_TIMER0);
129
      read_adc(ADC_START_ONLY);
125
   enable_interrupts(GLOBAL);
130
      delay_ms(1);
126
   while (true)         // Diagnostika cidel
131
      delay_ms(read_adc(ADC_READ_ONLY));
-
 
132
      beep(1000,200);
-
 
133
}
-
 
134
*/
-
 
135
   if (GRAVITY)
127
   {
136
   {
-
 
137
      diag=TRUE;
-
 
138
      enable_interrupts(INT_TIMER0);
-
 
139
      enable_interrupts(GLOBAL);
-
 
140
      while (true)         // Diagnostika cidel
-
 
141
      {
128
      if (g>100) beep(800,100);
142
         if (g>100) beep(800,100);
129
      Delay_ms(50);
143
         Delay_ms(50);
130
      if (arena_l) beep(1000,200);
144
         if (arena_l) {beep(1000,200); delay_ms(10);beep(1000,200);};
131
      Delay_ms(50);
145
         Delay_ms(50);
132
      if (arena_r) beep(2000,300);
146
         if (arena_r) {beep(2000,300); delay_ms(10);beep(2000,300);};
133
      Delay_ms(50);
147
         Delay_ms(50);
-
 
148
 
134
      if (sr>10) beep(3000,400);
149
         if (sr>10) beep(3000,400);
135
      Delay_ms(50);
150
         Delay_ms(50);
136
      if (f>10) beep(4000,500);
151
         if (f>10) beep(4000,500);
137
      Delay_ms(50);
152
         Delay_ms(50);
138
      if (sl>10) beep(5000,500);
153
         if (sl>10) beep(5000,500);
139
      Delay_ms(50);
154
         Delay_ms(50);
140
      if (b>10) beep(6000,600);
155
         if (b>10) beep(6000,600);
141
      Delay_ms(50);
156
         Delay_ms(50);
-
 
157
      }
142
   }};
158
   };
143
}
159
}
144
 
160
 
145
void main()
161
void main()
146
{
162
{
147
   unsigned int16 n; // for FOR
163
   unsigned int16 n; // for FOR
148
 
164
 
149
   STOPL; STOPR;     // zastavi motory
165
   STOPL; STOPR;     // zastavi motory
150
 
166
 
151
   setup_oscillator(OSC_8MHZ|OSC_INTRC);     // CPU clock 8MHz
167
   setup_oscillator(OSC_8MHZ|OSC_INTRC);     // CPU clock 8MHz
152
   setup_adc_ports(sAN2|sAN3|VSS_VDD);   // prevodniky na cidla na okraj areny
168
//   setup_adc_ports(sAN2|sAN3|VSS_VDD);   // prevodniky na cidla na okraj areny
153
   setup_adc(ADC_CLOCK_INTERNAL);
169
//   setup_adc(ADC_CLOCK_INTERNAL);
-
 
170
//!!!!!!!!!!!!!!!!!!
-
 
171
   setup_adc_ports(NO_ANALOGS);   // prevodniky na cidla na okraj areny
-
 
172
   setup_adc(ADC_OFF);
154
   setup_spi(FALSE);
173
   setup_spi(FALSE);
155
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_4);  // Casovac pro SW PWM a cteni cidel
174
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_4);  // Casovac pro SW PWM a cteni cidel 
156
   setup_timer_1(T1_DISABLED);
175
   setup_timer_1(T1_DISABLED);
157
   setup_timer_2(T2_DIV_BY_1,54,1); // Casovac pro PWM pro IR sensory cca 36kHz
176
   setup_timer_2(T2_DIV_BY_1,54,1); // Casovac pro PWM pro IR sensory cca 36kHz
158
   setup_ccp1(CCP_PWM);    // HW PWM ON
177
   setup_ccp1(CCP_PWM);    // HW PWM ON
159
   set_pwm1_duty(27);      // 1:1
178
   set_pwm1_duty(27);      // 1:1
160
   setup_comparator(NC_NC_NC_NC);
179
   setup_comparator(NC_NC_NC_NC);
Line 168... Line 187...
168
   diagnostika();
187
   diagnostika();
169
 
188
 
170
   enable_interrupts(INT_TIMER0);
189
   enable_interrupts(INT_TIMER0);
171
   enable_interrupts(GLOBAL);
190
   enable_interrupts(GLOBAL);
172
/*---------------------------------------------------------------------------*/
191
/*---------------------------------------------------------------------------*/
173
   for (n=1;n<=3;n++)   // 5s do zacatku souboje
192
   for (n=1;n<=5;n++)   // 5s do zacatku souboje
174
   {
193
   {
175
      Delay_ms(990);
194
      Delay_ms(720);
176
      Beep(1000,200);
195
      Beep(1000,200);
177
   }
196
   }
178
   Delay_ms(300);
-
 
179
 
197
 
180
   while(true)       // hlavni smycka
198
   while(true)       // hlavni smycka
181
   {
199
   {
182
LOOP:
200
LOOP:
183
 
201