forked from PuceBaboon/Share_the_Warmth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
d1w.jal
110 lines (97 loc) · 2.39 KB
/
d1w.jal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
-- ------------------------------------------------------
-- Title: one wire JAL library
--
-- Author: Vasile Surducan, Copyright (c) 2009..2010, all rights reserved.
--
-- Adapted-by: Jean Marchaudon, Joep Suijs
--
-- Compiler: >=2.4m
-- Revision: $Revision: 1.1 $
--
-- This file is part of jallib (http://jallib.googlecode.com)
-- Released under the ZLIB license (http://www.opensource.org/licenses/zlib-license.html)
--
-- Description: Library to interface with Dallas / Maxim one-wire-bus devices
-- --
-- Pin used for the 1-wire bus must be define these in your program
-- before including the library. E.g.:
-- alias owbus is pin_c1
-- alias owbus_out is pin_c1_direction
--
-- Sources:
--
-- Notes:
--
-- ------------------------------------------------------
procedure d1w_init() is
-- Prepare the bus
owbus = low
owbus_direction = input
end procedure
procedure _d1w_write_bit( bit in x ) is
owbus = low
owbus_direction = output
delay_10us( 1 )
if x == high then owbus_direction = input end if
delay_10us( 8 )
owbus_direction = input
delay_10us( 1 )
end procedure
procedure _d1w_read_bit( bit out x ) is
x = high
owbus = low
owbus_direction = output
delay_10us( 1 )
owbus_direction = input
delay_10us( 1 )
if owbus == low then x = low end if
delay_10us( 7 )
end procedure
procedure d1w_write_byte( byte in e ) is
var bit x at e : 0
for 8 loop
_d1w_write_bit( x )
e = e >> 1
end loop
-- power bus after byte is written
owbus = high
owbus_direction = output
end procedure
procedure d1w_read_byte( byte out c ) is
var bit x at c : 7
for 8 loop
c = c >> 1
_d1w_read_bit( x )
end loop
--% const byte opstr0[] = "Read byte: 0x";
--% print_string(sdev, opstr0);
--% print_byte_hex(sdev, c);
--% print_crlf(sdev);
-- power bus after byte is read
owbus = high
owbus_direction = output
end procedure
procedure d1w_reset() is
owbus = low
owbus_direction = output
delay_10us( 70 )
owbus_direction = input
delay_10us( 70 )
end procedure
function d1w_present() return bit is
var bit x = false
owbus = low
owbus_direction = output
delay_10us( 70 )
owbus_direction = input
delay_10us( 3 )
if owbus == low then
x = true
end if
delay_10us( 3 )
if owbus == low then
x = true
end if
delay_10us( 70 )
return x
end function