Subversion Repositories svnkaklik

Rev

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

Rev Author Line No. Line
6 kaklik 1
// Modul pro komunikaci s Mysi
2
 
3
void send(byte command)
4
{
5
   int n;
6
   int parity=0;
7
 
8
   //Request-to-send
9
//   output_float(DATA);
10
   output_low(CLK);
11
   delay_us(100);
12
   // start bit
13
   output_low(DATA);
14
   delay_us(20);
15
   while(!input(CLK));
16
   // 8 bitu
17
   for(n=0; n<8; n++)
18
   {
19
      while(input(CLK));
20
      output_bit(DATA, command & 1);
21
      parity += command & 1;
22
      command>>=1;
23
      while(!input(CLK));
24
   };
25
   // parita
26
   while(input(CLK));
27
   output_bit(DATA, ~parity & 1);
28
   while(!input(CLK));
29
   // stop bit
30
   while(input(CLK));
31
   output_bit(DATA, 1);
32
   while(!input(CLK));
33
   output_float(DATA);
34
}
35
 
36
 
37
int8 read_byte(int8 const poradi)
38
{
39
int8 bajt;
40
int8 i;
41
 
42
   // cekani na komunikacni klid
43
   for (i=0; i<poradi; i++)
44
   {
45
      if (!input(CLK) || !input(DATA)) i=0;
46
   };
47
 
48
   // cekani na startbit
49
   while(input(CLK) || input(DATA));
50
   while(!input(CLK));
51
 
52
   bajt = 0;
53
   for(i=0; i<8; i++)
54
   {
55
      while(input(CLK));   // ceka na nulu hodin
56
 
57
      bajt >>= 1;
58
      bajt |= input(DATA) << 7;
59
 
60
      while(!input(CLK));  // ceka na jednicku hodin
61
   };
62
   return (bajt);
63
}
64
 
65
 
66
/*void read_all_byte(int8*st,*nd,*rd)           // precte 3 bajty
67
{
68
int8 i;
69
 
70
//   *st=read_byte(1st);
71
 
72
   // cekani na startbit
73
   while(input(CLK) || input(DATA));
74
   while(!input(CLK));
75
   *nd = 0;
76
   for(i=0; i<8; i++)
77
   {
78
      while(input(CLK));   // ceka na nulu hodin
79
 
80
      *nd |= input(DATA) << 7;
81
      *nd >>= 1;
82
 
83
      while(!input(CLK));  // ceka na jednicku hodin
84
   };
85
 
86
   // cekani na startbit
87
   while(input(CLK) || input(DATA));
88
   while(!input(CLK));
89
   *rd = 0;
90
   for(i=0; i<8; i++)
91
   {
92
      while(input(CLK));   // ceka na nulu hodin
93
 
94
      *rd |= input(DATA) << 7;
95
      *rd >>= 1;
96
 
97
      while(!input(CLK));  // ceka na jednicku hodin
98
   };
99
}*/