DS2438Word文件下载.docx
《DS2438Word文件下载.docx》由会员分享,可在线阅读,更多相关《DS2438Word文件下载.docx(25页珍藏版)》请在冰豆网上搜索。
Pause
for
exactly
'
tick'
number
of
ticks
=
0.25us
void
tickDelay(uint16
tick)
Implementation
is
platform
specific
{
while(tick--)
_nop_();
}
values
int
A,B,C,D,E,F,G,H,I,J;
MK
4
//-----------------------------------------------------------------------------
Set
the
1-Wire
timing
to
standard'
(standard=1)
or
overdrive'
(standard=0).
//
SetSpeed(int
standard)
Standard
Speed
A
6
*
MK;
//6us
B
64
//64us
C
60
//60
D
10
//10
E
9
//9
F
55
//55
G
2;
//0
H
480
//480
I
70
//70
J
410
//410
/*
1.5
7.5
2.5
0.75
7
8.5
40
*/
send
databyte'
port'
outp(unsigned
port,
databyte)
//设置为输出
IO0DIR
|=
port;
//输出一个bit
if(databyte)
IO0SET
else
IO0CLR
read
byte
from
inp(unsigned
port)
i;
//设置为输入
&
~port;
//读出一个bit
i
(IO0PIN
port)>
>
MOVE;
return
Generate
a
reset,
1
if
no
presence
detect
was
found,
0
otherwise.
(NOTE:
Does
not
handle
alarm
DS2404/DS1994)
OWTouchReset(void)
uint32
result;
tickDelay(G);
outp(PORTADDRESS,0x00);
Drives
DQ
low
tickDelay(H);
outp(PORTADDRESS,0x01);
Releases
bus
tickDelay(I);
result
inp(PORTADDRESS);
Sample
pulse
slave
tickDelay(J);
Complete
reset
sequence
recovery
if(result)
return
1;
//失败
0;
//成功
Return
sample
result
Send
write
bit.
Provide
10us
recovery
time.
OWWriteBit(int
bit)
(bit)
Write
1'
bit
tickDelay(A);
tickDelay(B);
time
slot
and
0'
tickDelay(C);
tickDelay(D);
Read
bit
bus
it.
OWReadBit(void)
tickDelay(E);
inp(PORTADDRESS)
0x01;
value
tickDelay(F);
data
byte
OWWriteByte(uint8
data)
uint8
loop,i;
Loop
each
in
byte,
LS-bit
first
(loop
loop
8;
loop++)
//OWWriteBit(data
0x01);
data&
(i)
outp(PORTADDRESS,0);
outp(PORTADDRESS,1);
}
shift
next
data
data>
it
OWReadByte(void)
loop,
result=0,i;
get
it
ready
(inp(PORTADDRESS)