Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

Rev Author Line No. Line
6 kaklik 1
// Prijimac
2
#include "main.h"
3
#include "..\..\common.h"
4
 
5
#DEFINE  PRIJIMAC       PIN_A3      // pin na ktery je pripojen prijimac
6
#DEFINE  SERVO_X        PIN_A2      // piny na ktere jsou pripojena serva
7
#DEFINE  SERVO_Y        PIN_B0
8
#DEFINE  DILEK          20           // jeden krok serva v mikrosekundach
9
 
10
#bit  T0IF = 0xB.2   // int. flag od Timer0
11
 
12
static int8   x = 16;     // poloha serv
13
static int8   y = 16;
14
int8  trim_x = 2;
15
int8  trim_y = 2;
16
 
17
boolean flag;      // priznak, ze doslo k preruseni prijmu ovladanim serv
18
 
19
#int_TIMER0
20
TIMER0_isr()
21
{
22
   int8 n;
23
 
24
   flag = true;   // doslo k preruseni prijmu
25
//   x = 15;
26
//   y = 15;
27
 
28
   output_high(SERVO_X);   // uvodni impuls 1ms
29
   delay_ms(1);
30
   for (n=trim_x; n>0; n--);
31
   for (n=x; n>0; n--) Delay_us(DILEK);
32
   output_low(SERVO_X);
33
 
34
   output_high(SERVO_Y);
35
   delay_ms(1);
36
   for (n=trim_y; n>0; n--);
37
   for (n=y; n>0; n--) Delay_us(DILEK);
38
   output_low(SERVO_Y);
39
}
40
 
41
// output_high(PIN_B1);   // debug pin
42
 
43
void main()
44
{
45
   int i;
46
   int8 osa, data, check, suma;
47
 
48
   setup_counters(RTCC_INTERNAL,RTCC_DIV_64);   // Preruseni po 16,3ms
49
   enable_interrupts(INT_TIMER0);
50
   enable_interrupts(global);
51
 
52
loop:
53
   flag = false;
54
 
55
   // Cekej na uvodni ticho
56
   for (i=SYNC; i>0; i--)
57
   {
58
      delay_us(IMPULS/4);
59
      if (flag) goto loop;
60
      if (!input(PRIJIMAC)) i=SYNC;
61
   }
62
 
63
   // Cekej na startovaci 1
64
   while (input(PRIJIMAC)) if (flag) goto loop;
65
 
66
   if (flag) goto loop;
67
 
68
   // Posun na cteni prvniho datoveho bitu
69
   delay_us(2*IMPULS+2*IMPULS/3);
70
 
71
   // Cteme bity
72
   for (i=8; i>0; i--)
73
   {
74
      data <<= 1;
75
      if (input(PRIJIMAC)) data |= 1;
76
      if (flag) goto loop;
77
output_high(PIN_B1);   // debug pin
78
      delay_us(2*IMPULS+15);
79
output_low(PIN_B1);   // debug pin
80
   }
81
 
82
   // Cteme checksum
83
   check = 0;
84
   for (i=4; i>0; i--)
85
   {
86
      check <<= 1;
87
      if (input(PRIJIMAC)) check |= 1;
88
      if (flag) goto loop;
89
output_high(PIN_B1);   // debug pin
90
      delay_us(2*IMPULS+15);
91
output_low(PIN_B1);   // debug pin
92
   }
93
 
94
   swap(data);          // kontrola kontrolniho souctu
95
   suma = data & 0xF;   
96
   swap(data);
97
   suma += data & 0xF;
98
   suma++;
99
   suma &= 0xF;
100
   if (suma != check) goto loop;
101
 
102
   osa = data >> 5;  // extrahuj z ramce cislo osy a hodnotu
103
   data &= 0x1F;
104
   switch(osa)
105
   {
106
      case OSA_X:
107
         x=data;
108
        break;
109
      case OSA_y:
110
         y=data;
111
        break;
112
   }
113
 
114
   goto loop;
115
}