单片机源程序如下:
- #include<reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbit lcden=P2^2;
- sbit lcdrs=P2^0;
- sbit lcdrw=P2^1;
- sbit sd =P2^3;
- sbit bj =P2^7;
- uchar code table[]="Humidity: ";
- uchar code table1[]=" Normal ";
- uchar code table2[]="Humidity: ";
- uchar code table3[]=" Deviant ";
- uchar num; //延时程序
- void delay(uint z)
- {
- uint x,y;
- for(x=z;x>0;x--)
- for(y=110;y>0;y--)
- }
- void write_com(uchar com) 、、//写入地址
- {
- lcdrs=0;
- P0=com;
- delay(5);
- lcden=1;
- delay(5);
- lcden=0;
- }
- void write_date(uchar date) //写入数据
- {
- lcdrs=1;
- P0=date;
- delay(5);
- lcden=1;
- delay(5);
- lcden=0;
- }
- void init() //初始化程序
- {
- P0=0xff;
- lcdrw=0;
- lcden=0;
- write_com(0x80); //地址指针初始化
- write_com(0x38); //初始化液晶显示器
- write_com(0x0c); //控制光标
- write_com(0x06); //写一个字符后地址加一
- }
- void main()
- {
- init();
- sd=1;
- while(1);
- {
- if(sd==1) //正常情况显示
- {
- write_com(0x80+0x00); //lcd第一排写入地址
- for(num=0;num<15;num++)
- write_date(table[num]); //lcd第二排写入地址
- for(num=0;num<13;num++)
- write_date(table1[num]); //lcd第二排写入数据
- bj=1; //不报警
- }
-
- else if(sd==0) //不正常显示情况报警
- {
- write_com(0x80+0x00); //lcd第一排写入地址
- for(num=0;num<15;num++)
- write_date(table2[num]); //lcd第二排写入地址
- for(num=0;num<13;num++)
- write_date(table3[num]); //lcd第二排写入数据
- bj=0; //报警
- }
- }
- }
复制代码 |