Subversion Repositories svnkaklik

Rev

Rev 410 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 410 Rev 659
1
 
1
 
2
#DEFINE  CLK         250
2
#DEFINE  CLK         250
3
#DEFINE  WORD1       0b111010101000
3
#DEFINE  WORD1       0b111010101000
4
#DEFINE  WORD2       0b111010110000
4
#DEFINE  WORD2       0b111010110000
5
#DEFINE  WORD3       0b111011001000
5
#DEFINE  WORD3       0b111011001000
6
#DEFINE  WORD4       0b111011010000
6
#DEFINE  WORD4       0b111011010000
7
 
7
 
8
void send_bit(bit)
8
void send_bit(bit)
9
{
9
{
10
   output_bit(DIN,bit);
10
   output_bit(DIN,bit);
11
   output_high(SCLK);
11
   output_high(SCLK);
12
   Delay_us(CLK);
12
   Delay_us(CLK);
13
   output_low(SCLK);
13
   output_low(SCLK);
14
}
14
}
15
int1 read_bit()
15
int1 read_bit()
16
{
16
{
17
   output_high(SCLK);
17
   output_high(SCLK);
18
   Delay_us(CLK);
18
   Delay_us(CLK);
19
   output_low(SCLK);
19
   output_low(SCLK);
20
   if (input(DOUT)) return true;
20
   if (input(DOUT)) return true;
21
   if (!input(DOUT)) return false;
21
   if (!input(DOUT)) return false;
22
}
22
}
23
 
23
 
24
void read_byte(*byte_r)
24
void read_byte(*byte_r)
25
{
25
{
26
int i;
26
int i;
27
 
27
 
28
   for(i=0;i>=7;i++)
28
   for(i=0;i>=7;i++)
29
   {
29
   {
30
   *byte_r = read_bit();
30
   *byte_r = read_bit();
31
   *byte_r << 1;
31
   *byte_r << 1;
32
   }
32
   }
33
}
33
}
34
 
34
 
35
void send_command(command,width)
35
void send_command(command,width)
36
{
36
{
37
int i;
37
int i;
38
   for (i=width;i>=0;i--)
38
   for (i=width;i>=0;i--)
39
   {
39
   {
40
     send_bit(bit_test(command,0));
40
     send_bit(bit_test(command,0));
41
     command >>1;
41
     command >>1;
42
   }   
42
   }   
43
}
43
}
44
 
44
 
45
void bar_reset()
45
void bar_reset()
46
{
46
{
47
int8 i;
47
int8 i;
48
 
48
 
49
   for(i=0;i>=20;i++) send_bit(Bit_test(i,0));
49
   for(i=0;i>=20;i++) send_bit(Bit_test(i,0));
50
}
50
}
51
 
51
 
52
int16 bar_con_pre()
52
int16 bar_con_pre()
53
{
53
{
54
int16 word;
54
int16 word;
55
   
55
   
56
   send_command(0b1111010000,9);
56
   send_command(0b1111010000,9);
57
 
57
 
58
   Delay_ms(10);
58
   Delay_ms(10);
59
 
59
 
60
   While(input(DOUT)) Delay_us(100);
60
   While(input(DOUT)) Delay_us(100);
61
 
61
 
62
   read_byte(&word);
62
   read_byte(&word);
63
   word << 8;
63
   word << 8;
64
   read_byte(&word);
64
   read_byte(&word);
65
 
65
 
66
   return word;
66
   return word;
67
}
67
}
68
 
68
 
69
int16 bar_con_term()
69
int16 bar_con_term()
70
{
70
{
71
int16 word;
71
int16 word;
72
 
72
 
73
   send_command(0b1111001000,9);
73
   send_command(0b1111001000,9);
74
 
74
 
75
   Delay_ms(10);
75
   Delay_ms(10);
76
 
76
 
77
   While(input(DOUT)) Delay_us(100);
77
   While(input(DOUT)) Delay_us(100);
78
 
78
 
79
   read_byte(&word);
79
   read_byte(&word);
80
   word << 8;
80
   word << 8;
81
   read_byte(&word);
81
   read_byte(&word);
82
 
82
 
83
   return word;   
83
   return word;   
84
}
84
}
85
 
85
 
86
int16 bar_read_cal(command)
86
int16 bar_read_cal(command)
87
{
87
{
88
int16 word;
88
int16 word;
89
 
89
 
90
   send_command(command,11);
90
   send_command(command,11);
91
 
91
 
92
   Delay_ms(10);
92
   Delay_ms(10);
93
 
93
 
94
   While(input(DOUT)) Delay_us(100);
94
   While(input(DOUT)) Delay_us(100);
95
 
95
 
96
   read_byte(&word);
96
   read_byte(&word);
97
   word << 8;
97
   word << 8;
98
   read_byte(&word);
98
   read_byte(&word);
99
 
99
 
100
   return word;   
100
   return word;   
101
}
101
}
102
 
102
 
103
 
103
 
104
 
104
 
105
 
105
 
106
 
106
 
107
 
107