【正文】
******************// void s_connectionreset() { uchar i。 D_date=1。 D_sck=0。 for(i=0。i9。i++) { D_sck=1。 D_sck=0。 } D_start()。 } //*************向DHT90寫命令******************//uchar wr_DHT(uchar d){ uchar i,error=0。 D_start()。 for(i=8。i0。i) { D_date=damp。0x80。 _nop_()。 D_sck=1。 _nop_()。 _nop_()。 D_sck=0。 d=1。 } D_date=1。 D_sck=1。 error=D_date。 _nop_()。 _nop_()。 D_sck=0。 D_date=1。 return error。} //************讀DHT90值***********************//int read_DHTdat(){ uchar i,val=0。 D_date=1。 for(i=0x80。i0。i/=2) { D_sck=1。 if(D_date) { val|=i。 } _nop_()。 _nop_()。 _nop_()。 D_sck=0。 } _nop_()。_nop_()。 D_date=0。 D_sck=1。 _nop_()。 _nop_()。 D_sck=0。 _nop_()。 _nop_()。 D_date=1。 return val。}//**********************************************//int qz(){ uint valH,valL,val。 valH=read_DHTdat()。 valL=read_DHTdat()。 val=valH8|valL。 return val。} //*********************報警*******************//void D_measur(){ float c1=。 float c2=+。 float c3=。 float d1=。 float d2=+。 T=d1+d2*zhT。 H=c1+c2*zhHc3*zhH*zhH。 if(T100)T=100。 if(H)H=。 if(T=){Led1=1。Speak=0。}else{Led1=0。} if(H=){Led2=1。Speak=0。}else{Led2=0。} if((H)amp。(T)){Speak=1。}} //************顯示DTH90值****************************// void DHT90_display(){ L23[9]=table[T/100]。 //顯示溫度百位 L23[10]=table[(T%100)/10]。 //顯示溫度十位 L23[11]=table[(T%100)%10]。 //顯示溫度個位 L23[13]=table[((T*10)%100)%10]。 //顯示溫度小數(shù)點后第一位 L24[9]=table[H/1000]。 //顯示濕度百位 L24[10]=table[(H%1000)/100]。 //顯示濕度十位 L24[11]=table[(H%100)/10]。 //顯示濕度個位 L24[13]=table[H%10]。 //顯示濕度小數(shù)點后第一位} //*****************************************************// void main(){ long k。 uchar jcT=0。 uchar jcH=0。 P3=0x00。IE=0X81。 IP=0X01。key_ flag =0。wendu_arlarm=0。shidu_arlarm=0。do{ if(key_ flag) { switch(key_ value){ case 1:wendu_arlarm++。 if(wendu_arlarm=40) wendu_max=35 。 break。 case 2:wendu_arlarm。 if(wendu_arlarm=10) wendu_min=20。 break。case 4:shidu_arlarm++。 if(shidu_arlarm=70) shidu_max=60 。 break。case 8:shidu_arlarm。 if(shidu_arlarm=30) shidu_min=40。 break。default。break。 } key_ flag =0。 }}while(TURE)。 Speak=1。 RST=0。 delay(10)。 RST=1。 delay(2)。 PSB=1。 LCD_init()。 wr_LCD(0x80)。 wr_LCDdat(0x02)。 sdxs()。 delay(2000)。 delay(50)。 s_connectionreset()。 D_start()。 wr_LCD(0x01)。 while(1) { jcH=wr_DHT(0x05)。 if(jcH==1) { jcH=wr_DHT(0x05)。 } for(k=0。k9000000。k++)if(D_date==0)break。 zhH=qz()。 delay(1000)。 jcT=wr_DHT(0x03)。 if(jcT==1) { jcT=wr_DHT(0x03)。 } for(k=0。k9000000。k++)if(D_date==0)break。 zhT=qz()。 delay(10)。 D_measur()。 delay(10)。 DHT90_display()。 process()。 delay(1000)。 s_connectionreset()。 }外文資料翻譯AT89S52 DescriptionThe AT89s52 is a lowpower, highperformance CMOS 8bit microputer with 8K bytes of Flash programmable and erasable read only memory(PEROM). The device is manufactured using Atmel’s highdensity nonvolatile memory technology and is patible with the industrystandard 80C51 and 80C52 instruction set and pinout. The onchip Flash allows the program memory to be reprogrammed insystem or by a conventional nonvolatile memory programmer. By bining a versatile 8bit CPU with Flash on a monolithic chip, the Atmel AT89s52 is a powerful microputer which provides a highlyflexible and costeffective solution to many embedded control applications.Pin Configurations: The AT89s52 provides the following standard features: 8K bytes of Flash, 256 bytes of RAM, 32 I/O lines, three 16bittimer/counters, a sixvector twolevel interrupt architecture, a fullduplex serial port, onchip oscillator, and clock circuitry. In addition, the AT89s52 is designed with static logic for operation down to zero frequency and supports two software selectable power saving modes. The Idle Mode stops the CPU while allowing the RAM, timer/counters, serial port, and interrupt system to continue functioning. The Powerdown mode saves the RAM contents but freezes the oscillator, disabling all other chip functions until the next hardware reset.Pin DescriptionVCC: Supply voltage.GND: Ground.Port 0: Port 0 is an 8bit open drain bidirectional I/O port. As an output port, each pin can sink eight TTL inputs. When 1s are written to port 0 pins, the pins can be used as highimpedance inputs. Port 0 can also be configured to be the multiplexed loworder address/data bus during accesses to external program and data memory. In this mode, P0 has internalpullups.Port 0 also receives the code bytes during Flash programming and outputs the code bytes during program verification. External pullups are required during program verification. Port 1: Port 1 is an 8bit bidirectional I/O port with internal pullups. The Port 1 output buffers can sink/source four TTL inputs. When 1s are written to Port 1 pins, they are pulled high by the internal pullups and can be used as inputs. As inputs, Port 1 pins that are externally being pulled low will source current ()because of the internal pullups. In addition, and can be configured to be the timer/counter 2 external count