Subversion Repositories svnkaklik

Rev

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

Rev Author Line No. Line
2 kaklik 1
#include "D:\@Kaklik\programy\PIC_C\robot\auto\main.h"
2
 
3
#DEFINE     CIDLO1L      PIN_B0
4
#DEFINE     CIDLO1R      PIN_B1
5
#DEFINE     CIDLO2L      PIN_B2
6
#DEFINE     CIDLO2R      PIN_B3
7
 
8
#DEFINE     RELE1       PIN_B5
9
#DEFINE     RELE2       PIN_B6
10
#DEFINE     MOTOR1      PIN_B4
11
#DEFINE     MOTOR2      PIN_A0
12
#DEFINE     MOTOR2a     PIN_A1
13
 
14
#DEFINE     LASER       PIN_A2
15
 
16
#DEFINE  L  0
17
#DEFINE  R  1
18
 
19
int cara;
20
int movement;
21
 
22
void left()
23
{
24
   output_high(RELE1);   
25
   output_high(RELE2);
26
   delay_ms(100);
27
   output_high(MOTOR1);
28
   output_high(MOTOR2);
29
   output_high(MOTOR2a);
30
}
31
 
32
void right()
33
{
34
   output_low(RELE1);      
35
   output_low(RELE2);
36
   delay_ms(100);
37
   output_high(MOTOR1);
38
   output_high(MOTOR2);
39
   output_high(MOTOR2a);
40
}
41
 
42
void rovne()
43
{
44
   output_low(RELE1);      // oba motory vpred
45
   output_high(RELE2);
46
   delay_ms(100);
47
   output_high(MOTOR1);
48
   output_high(MOTOR2);
49
   output_high(MOTOR2a);
50
}
51
 
52
void stop()
53
{
54
   output_low(MOTOR1);
55
   output_low(MOTOR2);
56
   output_low(MOTOR2a);
57
   delay_ms(100);
58
}
59
 
60
 
61
void main()
62
{
63
   cara=L;
64
   movement=R;
65
   output_low(RELE1);      // oba motory vpred
66
   output_high(RELE2);
67
   delay_ms(100);
68
   while (true)
69
   {
70
         if (!input(CIDLO1R)) cara=R; // cara vpravo
71
         if (!input(CIDLO1L)) cara=L; // cara vlevo
72
 
73
         if (!input(CIDLO1L) || !input(CIDLO1R))
74
         {
75
            stop();
76
            rovne();
77
            delay_ms(100);       
78
         };
79
 
80
         if (cara != movement)
81
         {
82
            switch(cara)
83
            {
84
              case L:
85
                 output_high(LASER);
86
                 stop();
87
                 left();
88
                 movement=L;
89
                break;
90
 
91
              case R:
92
                 output_low(LASER);
93
                 stop();
94
                 right();
95
                 movement=R;
96
                break;           
97
            }
98
         }
99
   }
100
}