Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

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