| Line 1... |
Line -... |
| 1 |
#define ONE_WIRE_PIN PIN_A1 |
- |
|
| 2 |
|
1 |
|
| 3 |
void onewire_reset() |
2 |
void onewire_reset() |
| 4 |
|
- |
|
| 5 |
|
- |
|
| 6 |
|
- |
|
| 7 |
{ |
3 |
{ |
| 8 |
output_low(ONE_WIRE_PIN); |
4 |
output_low(ONE_WIRE_PIN); |
| 9 |
delay_us(500); |
5 |
delay_us(500); |
| 10 |
output_float(ONE_WIRE_PIN); |
6 |
output_float(ONE_WIRE_PIN); |
| 11 |
delay_us(500); |
7 |
delay_us(500); |
| 12 |
output_float(ONE_WIRE_PIN); |
8 |
output_float(ONE_WIRE_PIN); |
| 13 |
} |
9 |
} |
| 14 |
|
10 |
|
| 15 |
|
11 |
|
| 16 |
void onewire_write(int data) |
12 |
void onewire_write(int data) |
| 17 |
{ |
13 |
{ |
| 18 |
int count; |
14 |
int count; |
| 19 |
|
- |
|
| 20 |
for (count=0; count<8; ++count) |
- |
|
| 21 |
{ |
- |
|
| 22 |
output_low(ONE_WIRE_PIN); |
- |
|
| 23 |
delay_us( 2 ); |
- |
|
| 24 |
output_bit(ONE_WIRE_PIN, shift_right(&data,1,1)); |
- |
|
| 25 |
|
15 |
|
| - |
|
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)); |
| - |
|
21 |
|
| 26 |
delay_us( 60 ); |
22 |
delay_us( 60 ); |
| 27 |
output_float(ONE_WIRE_PIN); |
23 |
output_float(ONE_WIRE_PIN); |
| 28 |
delay_us( 2 ); |
24 |
delay_us( 2 ); |
| 29 |
} |
25 |
} |
| 30 |
} |
26 |
} |
| 31 |
|
27 |
|
| 32 |
|
28 |
|
| 33 |
int onewire_read() |
29 |
int onewire_read() |
| 34 |
{ |
30 |
{ |
| 35 |
int count, data; |
31 |
int count, data; |
| 36 |
|
- |
|
| 37 |
for (count=0; count<8; ++count) |
- |
|
| 38 |
{ |
- |
|
| 39 |
output_low(ONE_WIRE_PIN); |
- |
|
| 40 |
delay_us( 2 ); |
- |
|
| 41 |
output_float(ONE_WIRE_PIN); |
- |
|
| 42 |
delay_us( 8 ); |
- |
|
| 43 |
shift_right(&data,1,input(ONE_WIRE_PIN)); |
- |
|
| 44 |
delay_us( 120 ); |
- |
|
| 45 |
} |
- |
|
| 46 |
|
32 |
|
| - |
|
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 |
} |
| 47 |
return( data ); |
42 |
return( data ); |
| 48 |
} |
43 |
} |