Rev Author Line No. Line
1767 kaklik 1  
2 void onewire_reset()
3 {
1774 kaklik 4 output_low(ONE_WIRE_PIN);
5 delay_us(500);
6 output_float(ONE_WIRE_PIN);
7 delay_us(500);
8 output_float(ONE_WIRE_PIN);
1767 kaklik 9 }
10  
11  
12 void onewire_write(int data)
13 {
1774 kaklik 14 int count;
1767 kaklik 15  
1774 kaklik 16 for (count=0; count<8; ++count)
17 {
18 output_low(ONE_WIRE_PIN);
19 delay_us( 2 );
20 output_bit(ONE_WIRE_PIN, shift_right(&data,1,1));
1767 kaklik 21  
1774 kaklik 22 delay_us( 60 );
23 output_float(ONE_WIRE_PIN);
24 delay_us( 2 );
25 }
1767 kaklik 26 }
27  
28  
29 int onewire_read()
30 {
1774 kaklik 31 int count, data;
1767 kaklik 32  
1774 kaklik 33 for (count=0; count<8; ++count)
34 {
35 output_low(ONE_WIRE_PIN);
36 delay_us( 2 );
37 output_float(ONE_WIRE_PIN);
38 delay_us( 8 );
39 shift_right(&data,1,input(ONE_WIRE_PIN));
40 delay_us( 120 );
41 }
42 return( data );
1767 kaklik 43 }