www.pudn.com > wendu.zip > wen.c, change:2017-04-30,size:3454b


#include <reg51.h> 
#include <intrins.h>  
 
typedef unsigned char  U8;       
typedef signed   char  S8;     
typedef unsigned int   U16;     
typedef signed   int   S16;      
typedef unsigned long  U32;   
typedef signed   long  S32;     
typedef float          F32;      
typedef double         F64;      
 
#define uchar unsigned char 
#define uint unsigned int 
#define   Data_0_time    4 
 
sbit  LCDEN=P3^4; 
sbit  LCDRW=P3^6; 
sbit  LCDRS=P3^5; 
sbit  DATA=P1^7; 
 
U8  U8FLAG,k; 
U8  U8count,U8temp; 
U8  U8T_data_H,U8T_data_L,U8RH_data_H,U8RH_data_L,U8checkdata; 
U8  U8T_data_H_temp,U8T_data_L_temp,U8RH_data_H_temp,U8RH_data_L_temp,U8checkdata_temp; 
U8  U8comdata; 
U8  count, count_r=0; 
U16 U16temp1,U16temp2; 
U8 humity_shi;humity_ge;temp_shi,temp_ge; 
 
unsigned char code str1[]={"temperature:  "};  
unsigned char code str2[]={"humidity:     "};   
 
void LCD_delay(uint z) 
{ 
   uint x,y; 
   for(x=z;x>0;x--) 
     for(y=110;y>0;y--); 
} 
void wr_com(uchar com) 
{ 
   LCDRS=0; 
   LCDRW=0; 
   LCDEN=0; 
   P0=com; 
   LCD_delay(1); 
   LCDEN=1; 
   LCD_delay(1); 
   LCDEN=0; 
} 
void wr_data(uchar da) 
{ 
   LCDRS=1; 
   LCDRW=0; 
   LCDEN=0; 
   P0=da; 
   LCD_delay(1); 
   LCDEN=1; 
   LCD_delay(1); 
   LCDEN=0; 
   LCD_delay(1); 
} 
void lcd_init() 
{ 
   wr_com(0x38); 
   wr_com(0x06); 
   wr_com(0x01); 
   wr_com(0x0c); 
} 
void display(uchar *p) 
{ 
   while(*p!='\0') 
   { 
     wr_data(*p); 
	  p++; 
	  LCD_delay(1); 
   } 
 
 
} 
void init_play() 
{ 
   lcd_init(); 
   wr_com(0x80); 
   display(str1); 
   wr_com(0x80+0x40); 
   display(str2); 
} 
void Delay(U16 j) 
{      
     U8 i; 
	  for(;j>0;j--) 
	  { 	 
		  for(i=0;i<27;i++); 
	  } 
} 
void  Delay_10us(void) 
{ 
     U8 i; 
     i--; 
     i--; 
     i--; 
     i--; 
     i--; 
     i--; 
} 
void  COM(void) 
{ 
    U8 i; 
    for(i=0;i<8;i++)	    
	 { 
		U8FLAG=2;	 
	   while((!DATA)&&U8FLAG++); 
		Delay_10us(); 
	   Delay_10us(); 
		Delay_10us(); 
	  	U8temp=0; 
	   if(DATA)U8temp=1; 
		U8FLAG=2; 
		while((DATA)&&U8FLAG++); 
	   if(U8FLAG==1)break;   	  
		U8comdata<<=1; 
	   	U8comdata|=U8temp;       
	} 
} 
void RH(void) 
{   
   DATA=0; 
	Delay(180); 
	DATA=1; 
	Delay_10us(); 
	Delay_10us(); 
	Delay_10us(); 
	Delay_10us(); 
	DATA=1;	   
	if(!DATA)		 
	{ 
	   U8FLAG=2;	  
	   while((!DATA)&&U8FLAG++); 
	   U8FLAG=2; 
	   while((DATA)&&U8FLAG++); 
	   COM(); 
	   U8RH_data_H_temp=U8comdata; 
	   COM(); 
	   U8RH_data_L_temp=U8comdata; 
	   COM(); 
	   U8T_data_H_temp=U8comdata; 
	   COM(); 
	   U8T_data_L_temp=U8comdata; 
	   COM(); 
	   U8checkdata_temp=U8comdata; 
	   DATA=1;  
	   U8temp=(U8T_data_H_temp+U8T_data_L_temp+U8RH_data_H_temp+U8RH_data_L_temp); 
	   if(U8temp==U8checkdata_temp) 
	   { 
	   	  U8RH_data_H=U8RH_data_H_temp; 
	   	  U8RH_data_L=U8RH_data_L_temp; 
		     U8T_data_H=U8T_data_H_temp; 
	   	  U8T_data_L=U8T_data_L_temp; 
	   	  U8checkdata=U8checkdata_temp; 
	   } 
	} 
} 
 
void main() 
{ 
     init_play(); 
	  while(1) 
	  {   
	     RH(); 
        humity_shi=0x30+U8RH_data_H/10; 
        humity_ge=0x30+U8RH_data_H/10; 
        temp_shi=0x30+U8T_data_H/10; 
        temp_ge=0x30+U8T_data_L/10; 
          
        wr_com(0x80+0X0D); 
        wr_data(temp_shi); 
        wr_com(0x80+0X0e); 
        wr_data(temp_ge); 
         
        wr_com(0x80+0x40+0X0D); 
        wr_data(humity_shi); 
        wr_com(0x80+0x40+0X0e); 
        wr_data(humity_ge); 
         
        /*Delay(20000);*/ 
	  }	 
}