յķ䲨źŷdzŴ·ڶԴյźŽзŴ·յƵʷҪźźƬжLM567ڲѹƵΪC3йءڷ͵ijƵΪ40kHzԪʹƵΪ40kHzֻӦƵʵźţƵźŵĸš
յźźŴŴŴźŽ첨ƵΪ40kHz8ŷ͵ƽжź͵ƬP3.3ˣƬ͵ƽֹͣʱĹյ·ͼ5.2ʾ
ͼ5.2 յ·
5.3 ʾ·
ʾ·ͼ5.3λLEDɶ̬ɨ·AT89C51P0̬ɨʱP2ڿLEDĵǰʾλʾͻʾСʾλС°k2ʱʾ¶ֵʱ5sָʾֵ
ͼ5.3 ʾ·
5.4 Դ·
Դ·ͼ5.4ʾΪƲõ9Vع磬ֱѹLM7805ѹ+5VȺֱ磬Ϊ·ĵԴLEDǵԴָʾƣͨ⡣
ͼ5.4 Դ·
5.5 λ·
AT89C51λһרõⲿRESETⲿͨһʹƬλνλǿƵƬϵͳָȷijʼ״̬ʹϵͳ´ӳʼ״̬ʼƲõǵƽʽϵ縴λ·Ϊʹеϵͳ˹Ԥǿϵͳиλ·ͼ5.4ʾ
ͼ5.4 λ·
6
6.1
֪CԳʵֽϸӵ㷨ԳнϸߵЧϸеʱ䣬ǵijнϸӵļ㣨ʱҪϸʱ䣨ʱԿƳɲCԺͻԻϱ̡
ΪƶʱҪȽϸߵIJȫɵƬڲĶʱɣȻ¶ȴĶдʱ侫ҪҲߣϸóCѱ㷺ӦãֱӽгҲ¶ȵȷȡıȫʹCԱ̣ʹõĹʽܷݵֺʵ֣ĵƪ
ģ黯Ʒӳжӳ¶Ȳӳӳʾӳɨ账ģɡ
ͼ6.1Ϊͼ
ϵͳϵϵͳʼɨ谴k1k1£ʼ¶ȣȻP1.0λʹʱT0ʼʱƳͬʱʹʱT1ʼʱCPUѭP3.3ţP3.3Ϊ͵ƽʱյزʹT1ֹͣ涨ʱļֵ
Ȼ¶Ⱥʹʱ룬¶ȲʩʹߣþʾӳLEDʾ롣
ⰴk2k2պϣ¶ʾӳLEDʾ¶ȣ¶ȲDzʱڲ¶ȣǵǰ¶ȣ5sָʾβ룻k2ûбպϣʾ㶨ʾһεIJҪһβҪk3¿ʼٰ°k1ִһβڲݣֻ3ڿʼ벢ʾ¶ȹõȡ
6.2 ӳ
6.2.1 ӳжӳ
ӳͨP1.0˿ڷҳźţƵԼ40kHzķΪ12sңͬʱѼT1мʱʱT1ڷʽ0
ж1ⷵسźţһյسźţųֵ͵ƽжϳжϺرռʱT1ֹͣʱɹ־ֵָ1ʱʱδźţʱT1жϽж1رգɹ־ֵָ0ʾ˴βɹ
T0жϷ£ sbit send=P1^0;
void timer0(void)interrupt 1 { send=!send; TH0=0x1f; TL0=0xf4; }
գⲿж1 void int1(void)interrupt 2 { if(TH1!=0x00&&TH0!=0x00)
{ b=1; TR1=0; TR0=0;
t=TH1*256+TL1;
t=t; TH0=0x1f; TL0=0xf4; TH1=0x00; TL1=0x00; } else { b=0; TR1=0; TR0=0;
TH0=0x1f; TL0=0xf4; TH1=0x00; TL1=0x00;
} }
6.2.2 ӳ
µҪDS18B20ֳ¶ֱԡһߡַʽ䣬DS18B20õ¶ֵ8λRAM11λ¶ֵλ5λΪλӦ¶ȼ㣺λS=0ʱֱӽλתΪʮƣS=1ʱȽ任Ϊԭ룬ټʮֵͼ6.2ΪDS18B20¶ȴ洢ʽ
bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
2 32 22 12 02 12 622 532 44 bit15 bit14 bit13 bit12 bit11 bit10 bit9 bit8
S
ͼ6.2 DS18B20¶ȴ洢ʽ
S S S S 2 2 2 ¶ʱS=1¶ʱS=0ֻҪλ¶ȾͿˡһֽC£
uchar readbyte(void) ֱӶһֽڳ { uchar i,k; } }
return(k); i=8; k=0; while(i--) {
tem_in=1; delay_us(1); tem_in=0; k=k>>1; tem_in=1; NOP;
if(tem_in)k |= 0x80; tem_inΪ1ʱλҲΪ1 delay_us(4);