MOV R2,#250 ;主机发出延时500微秒的复位低脉冲
DJNZ R2,$
这里应该是600微秒....
你等待60us以后, JNB DQ,INIT1 判断DQ有没有被拉低.
后面JB DQ,INIT2 这是干嘛的??
底下你参考:ds18b20_init: ;[r0]
;in : NULL
;out: (22h)=00h: ds18b20 not found, (22h)=ffh: ds18b20 found
mov r0, #245
clr DQ
djnz r0, $ ;490us: master send reset pulse, pull down for 480us minimum
setb DQ
mov r0, #34
djnz r0, $ ;1+1+2*34=70us: ds18b20 wait 15us~60us and then transmits a presence pulse
mov c, DQ
mov r0, #205
djnz r0, $ ;70+2+1+2*205=483us: master rx 480us minimum
;setb DQ
jnc l01
mov 22h, #00h ;ds18b20 not found
ret
l01:mov 22h, #0ffh ;ds18b20 found
ret
#include
sbit p3_7=P3^7;
sbit p1_0=P1^0;
sbit p1_1=P1^1;
sbit p1_2=P1^2;
sbit p1_3=P1^3;
sbit p1_4=P1^4;
sbit p1_5=P1^5;
void delay(unsigned char tt)
{
for(;tt>0;tt--);
}
void init2()
{
p1_5=0;
delay(240);
}
void init1()
{
p1_4=0;
delay(120);
if(p3_7==1)
init2();
}
void main()
{
while(1)
{
p3_7=1;
p1_0=0;
delay(2);
p3_7=0;
delay(250);
p3_7=1;
p1_1=0;
delay(30);
p1_2=0;
if(p3_7==0)
init1();
else
p1_3=0;
}
}