Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

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