#include
- #include
- #define ADCPORT XBYTE[0x1eff]
- #define uchar unsigned char
- #define uint unsigned int
- //void delay(uint i){while(i--);}
- ***it k1=P3^0; ***it k2=P3^1;
- ***it k3=P3^2; ***it k4=P3^3;
- ***it EOC=P3^4;
- ***it RS=P2^3; //1=数据;0=命令
- ***it RW=P2^4; //1=读;0=写
- ***it E=P2^5; //1=使能;0=禁止
- #define Dat1602 P1 /** 数据端口 **/
- ***it BF=Dat1602^7; /** 忙信号线 **/
- uint s=0,min=0,c=0,tc=250,co=20,q=0,j;
- /** LCM忙检测 **/
- bit busy1602(){
- bit busy=0; //暂存标志
- Dat1602=0xff; //口线置1,防止干扰
- RS=0; RW=1; //置“命令、读”模式
- E=1; E=1; //使能,写两次做短延时
- busy=BF;E=0; //暂存标志,关闭使能
- return busy; //返回忙信号,1=忙
- }
- /** 写命令 参数:comDat为要发送的命令 **/
- void WriteComm(uchar comDat){
- while (busy1602()); //忙,则等待
- RS=0;RW=0; //置“命令、写”模式
- Dat1602=comDat;E=1;E=0; //送出命令,并使之有效
- }
- /** 写数据 参数:dat为要发送的数据 **/
- void WriteData(uchar dat){
- while (busy1602()); //忙,则等待
- RS=1;RW=0; //置“数据、写”模式
- Dat1602=dat;E=1;E=0; //送出数据,并使之有效
- }
- /** 初始化 **/
- void Init1602(){
- WriteComm(0x38);//8位,两行,5*7点阵
- WriteComm(0x0c);//显示开,光标关
- WriteComm(0x06);//默认,光标右移
- WriteComm(1); //清显示
- }
- /** 显示字符串 **/
- void showString(uchar row,uchar col,uchar code *s){
- uchar i=0;
- row%=2;col%=40; //防止越界
- WriteComm(0x80+row*0x40+col);//光标定位
- for(;col<40&&s[i]!=0;i++,col++){WriteData(s[i]);}
- }
- void ADC()
- {
- ADCPORT=0x1e;
- while(!EOC);
- P0=ADCPORT;
- j=P0;
- }
- void main()
- {
-
- TMOD=0x01;
- EA=ET0=1;
- TR0=1;
- Init1602();
- showString(0,0,"time:12:0");
- showString(1,0,"T:");
- showString(1,6,"C");
- showString(1,8,"Co2:");
- showString(1,14,"%");
-
- while(1)
- {
-
- tc=j*500./200;
- WriteComm(0x80+9); //光标定位
- WriteData(min/100+'0'); //时间显示
- WriteData(':');
- WriteData(s/10%10+'0');
- WriteData(s%10+'0');
- WriteComm(0xc0+2); //温度设定
- WriteData(tc/100+'0');
- WriteData(tc/10%10+'0');
- WriteData('.');
- WriteData(tc%10+'0');
- WriteComm(0xc0+12);
- WriteData(co/10%10+'0'); //二氧化碳浓度设定
- WriteData(co%10+'0');
-
- while(q==1)
- {
- WriteComm(0xc0+5);
- WriteComm(0x0f);
- if(k1==0)
- {
- while(k1==0);
- tc+=5;
- break;
- }
- if(k2==0)
- {
- while(k2==0);
- tc-=5;
- break;
- }
-
- }
- while(q==2)
- {
- WriteComm(0xc0+13);
- WriteComm(0x0f);
- if(k1==0)
- {
- while(k1==0);
- co++;
- break;
- }
- if(k2==0)
- {
- while(k2==0);
- co--;
- break;
- }
-
- }
- }
-
- }
- void time0() interrupt 1
- {
- TH0=0xfc;
- TL0=0x17;
- ADC();
- if(++c==1000)
- {
- c=0;
- s++;
- if(s>59)
- {
- s=0;
- min++;
- }
- }
- if(k3==0)
- {
- while(k3==0);
- q=(q+1)%3;
- }
- if(k4==0)
- {
- while(k4==0);
- q=0;
- }
- }
复制代码
#include
#include
#define ADCPORT XBYTE[0x1eff]
#define uchar unsigned char
#define uint unsigned int
//void delay(uint i){while(i--);}
***it k1=P3^0; ***it k2=P3^1;
***it k3=P3^2; ***it k4=P3^3;
***it EOC=P3^4;
***it RS=P2^3; //1=数据;0=命令
***it RW=P2^4; //1=读;0=写
***it E=P2^5; //1=使能;0=禁止
#define Dat1602 P1 /** 数据端口 **/
***it BF=Dat1602^7; /** 忙信号线 **/
uint s=0,min=0,c=0,tc=250,co=20,q=0,j;
/** LCM忙检测 **/
bit busy1602(){
bit busy=0; //暂存标志
Dat1602=0xff; //口线置1,防止干扰
RS=0; RW=1; //置“命令、读”模式
E=1; E=1; //使能,写两次做短延时
busy=BF;E=0; //暂存标志,关闭使能
return busy; //返回忙信号,1=忙
}
/** 写命令 参数:comDat为要发送的命令 **/
void WriteComm(uchar comDat){
while (busy1602()); //忙,则等待
RS=0;RW=0; //置“命令、写”模式
Dat1602=comDat;E=1;E=0; //送出命令,并使之有效
}
/** 写数据 参数:dat为要发送的数据 **/
void WriteData(uchar dat){
while (busy1602()); //忙,则等待
RS=1;RW=0; //置“数据、写”模式
Dat1602=dat;E=1;E=0; //送出数据,并使之有效
}
/** 初始化 **/
void Init1602(){
WriteComm(0x38);//8位,两行,5*7点阵
WriteComm(0x0c);//显示开,光标关
WriteComm(0x06);//默认,光标右移
WriteComm(1); //清显示
}
/** 显示字符串 **/
void showString(uchar row,uchar col,uchar code *s){
uchar i=0;
row%=2;col%=40; //防止越界
WriteComm(0x80+row*0x40+col);//光标定位
for(;col<40&&s!=0;i++,col++){WriteData(s);}
}
void ADC()
{
ADCPORT=0x1e;
while(!EOC);
P0=ADCPORT;
j=P0;
}
void main()
{
TMOD=0x01;
EA=ET0=1;
TR0=1;
Init1602();
showString(0,0,"Time:12:0");
showString(1,0,"T:");
showString(1,6,"C");
showString(1,8,"Co2:");
showString(1,14,"%");
while(1)
{
tc=j*500./200;
WriteComm(0x80+9); //光标定位
WriteData(min/100+'0'); //时间显示
WriteData(':');
WriteData(s/10%10+'0');
WriteData(s%10+'0');
WriteComm(0xc0+2); //温度设定
WriteData(tc/100+'0');
WriteData(tc/10%10+'0');
WriteData('.');
WriteData(tc%10+'0');
WriteComm(0xc0+12);
WriteData(co/10%10+'0'); //二氧化碳浓度设定
WriteData(co%10+'0');
while(q==1)
{
WriteComm(0xc0+5);
WriteComm(0x0f);
if(k1==0)
{
while(k1==0);
tc+=5;
break;
}
if(k2==0)
{
while(k2==0);
tc-=5;
break;
}
}
while(q==2)
{
WriteComm(0xc0+13);
WriteComm(0x0f);
if(k1==0)
{
while(k1==0);
co++;
break;
}
if(k2==0)
{
while(k2==0);
co--;
break;
}
}
}
}
void time0() interrupt 1
{
TH0=0xfc;
TL0=0x17;
ADC();
if(++c==1000)
{
c=0;
s++;
if(s>59)
{
s=0;
min++;
}
}
if(k3==0)
{
while(k3==0);
q=(q+1)%3;
}
if(k4==0)
{
while(k4==0);
q=0;
}
}
0
已退回1积分
|
|
|
|