1/******************************************************************************* * File Name : AM2301.c * Author : ?Ϸ?ΰ * Date : 2012-4-23 * Description : ?¡?ʪ?ȼ?⣬????22.1184M ********************************************************************************/ /*-----------------include-----------------------------------------------------*/ #include #include #define uint unsigned int #define uchar unsigned char sbit out=P1^0; sbit rs=P3^7; sbit rw=P3^6; sbit lcden=P2^7; uint hum,temp;//????ʪ?ȣ??¶? uchar hum_h,hum_l,temp_h,temp_l,check;//?¡?ʪ?ȸ?8λ????8λ??У??λ uchar a,shi,ge,shifen,shi1,ge1,shifen1,cnt=0; void delayms(uint z) { uchar x,y; for(x=z;x>0;x--) for(y=220;y>0;y--); }//1ms void delayus(uint z) { uchar x,y; for(x=z;x>0;x--) for(y=3;y>0;y--); }//1us void write_com(uchar a) { rs=0; P0=a; delayms(5); lcden=1; delayms(5); lcden=0; }//Һ??дָ?? void write_dat(uchar b) { rs=1; P0=b; delayms(5); lcden=1; delayms(5); lcden=0; }//Һ??д???? void init_1602() { rw=0; lcden=0; write_com(0x38); write_com(0x0c);//????ʾ??????ʾ??? write_com(0x06);//????дһ???ַ???ַָ???1????????ʾ???ƶ? write_com(0x01);//??????ָ?롢??ʾ????0 }//Һ????ʼ?? void init_2301() { delayms(1000);//??ʱһ?ᣬ?ܿ????ȶ????? out=0; delayus(600);//??????ʱ500΢?룬???Ϳ?ʼ?ź? out=1; delayus(40);//?ͷ????ߣ???ʱ30΢?? while(!out);//???͵ȴ? while(out);//???ߵȴ??????????????? } uchar read_byte() { uchar n,byte=0,dat; for(n=0;n<8;n++) { while(!out); delayus(40);//??????28us