TN9 STC89C521602液晶程序加报警 温度 调控.docx
《TN9 STC89C521602液晶程序加报警 温度 调控.docx》由会员分享,可在线阅读,更多相关《TN9 STC89C521602液晶程序加报警 温度 调控.docx(14页珍藏版)》请在冰豆网上搜索。
![TN9 STC89C521602液晶程序加报警 温度 调控.docx](https://file1.bdocx.com/fileroot1/2023-1/22/26672e0b-343b-4d42-a6af-4b87f9cee800/26672e0b-343b-4d42-a6af-4b87f9cee8001.gif)
TN9STC89C521602液晶程序加报警温度调控
#include
#defineucharunsignedchar
#defineuintunsignedint
ucharcodetable0[]="Welcometothe";
ucharcodetable1[]="TN9System";
ucharcodetable2[]="MuBiaoT:
00.0C";
ucharcodetable3[]="HuJingT:
00.0C";
ucharcodetable4[]="SystemSettings";
ucharcodetable5[]="BaoJingT:
000C";
ucharReadData[5];
floatTemp;
floatHJTemp,MBTemp;
uinti=25;
sbitdula=P2^6;
sbitwela=P2^7;
sbitbeep=P2^5;
sbitrs=P3^5;
sbitlcden=P3^4;
sbitTN_ACK=P1^3;//TN9触发
sbitTN_Clk=P1^4;//TN9时钟线
sbitTN_Data=P1^5;//TN9数据线
sbitK=P3^3;
sbitK1=P3^0;
sbitK2=P3^1;
sbitK3=P3^2;
sbitLR=P3^6;
sbitLG=P3^7;
sbitDOUT=P1^0;
voiddelay(uintz)
{
uintx,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
voidwrite_com(ucharcom)//LCD写命令
{
rs=0;
lcden=0;
P0=com;
delay
(1);
lcden=1;
delay
(1);
lcden=0;
}
voidwrite_date(uchardate)//LCD写数据
{
rs=1;
lcden=0;
P0=date;
delay
(1);
lcden=1;
delay
(1);
lcden=0;
}
voidInit_LCD()//屏幕初始化
{
ucharnum;
dula=0;
wela=0;
lcden=0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80);
write_com(0x01);
write_com(0x80);
for(num=0;num<16;num++)
{
write_date(table0[num]);
}
write_com(0x80+0x40);
for(num=0;num<16;num++)
{
write_date(table1[num]);
}
}
voidInit_T()//屏幕初始化
{
ucharnum;
lcden=0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80);
write_com(0x01);
write_com(0x80);
for(num=0;num<16;num++)
{
write_date(table2[num]);
}
write_com(0x80+0x40);
for(num=0;num<16;num++)
{
write_date(table3[num]);
}
}
voidInit_S()//屏幕初始化
{
ucharnum;
dula=0;
wela=0;
lcden=0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80);
write_com(0x01);
write_com(0x80);
for(num=0;num<16;num++)
{
write_date(table4[num]);
}
write_com(0x80+0x40);
for(num=0;num<16;num++)
{
write_date(table5[num]);
}
}
voidDisplay(floatMT,floatHT)//显示函数目标温度环境温度
{
uinttemp=0;
if(MT>220.0||MT<-33.0)
{
write_com(0x80+9);
write_date('');
write_date('E');
write_date('r');
write_date('r');
write_date('o');
write_date('r');
write_date('');
beep=0;delay(500);beep=1;
}
elseif(MT>=0)
{
if(MT<10)
{
temp=MT*10;
write_com(0x80+9);
write_date('');
write_date('');
write_date('0'+temp/10);
write_date('.');
write_date('0'+temp%10);
write_date(0xdf);
write_date('C');
if(MT>i)
{
beep=0;delay(30);beep=1;
}
}
elseif(MT<100)
{
temp=MT*10;
write_com(0x80+9);
write_date('');
write_date('0'+temp/100);
write_date('0'+temp/10%10);
write_date('.');
write_date('0'+temp%10);
write_date(0xdf);
write_date('C');
if(MT>i)
{
beep=0;delay(30);beep=1;
}
}
elseif(MT<=200)
{
temp=MT*10;
write_com(0x80+9);
write_date('0'+temp/1000);
write_date('0'+temp/100%10);
write_date('0'+temp/10%10);
write_date('.');
write_date('0'+temp%10);
write_date(0xdf);
write_date('C');
if(MT>i)
{
beep=0;delay(30);beep=1;
}
}
}
elseif(MT<0)
{
if(MT>-10)
{
temp=-10*MT;
write_com(0x80+9);
write_date('');
write_date('-');
write_date('0'+temp/10);
write_date('.');
write_date('0'+temp%10);
write_date(0xdf);
write_date('C');
}
elseif(MT>-100)
{
temp=-10*MT;
write_com(0x80+9);
write_date('-');
write_date('0'+temp/100);
write_date('0'+temp/10%10);
write_date('.');
write_date('0'+temp%10);
write_date(0xdf);
write_date('C');
}
}
if(HT>50.0||HT<-10.0)
{
write_com(0x80+0x40+9);
write_date('');
write_date('E');
write_date('r');
write_date('r');
write_date('o');
write_date('r');
write_date('');
beep=0;delay(200);beep=1;
}
elseif(HT>=0)
{
if(HT<10)
{
temp=10*HT;
write_com(0x80+0x40+9);
write_date('');
write_date('');
write_date('0'+temp/10);
write_date('.');
write_date('0'+temp%10);
write_date(0xdf);
write_date('C');
}
elseif(HT<100)
{
temp=10*HT;
write_com(0x80+0x40+9);
write_date('');
write_date('0'+temp/100);
write_date('0'+temp/10%10);
write_date('.');
write_date('0'+temp%10);
write_date(0xdf);
write_date('C');
}
}
elseif(HT<0)
{
if(HT>-10)
{
temp=-10*HT;
write_com(0x80+0x40+9);
write_date('');
write_date('-');
write_date('0'+temp/10);
write_date('.');
write_date('0'+temp%10);
write_date(0xdf);
write_date('C');
}
elseif(HT>-100)
{
temp=-10*HT;
write_com(0x80+0x40+9);
write_date('-');
write_date('0'+temp/100);
write_date('0'+temp/10%10);
write_date('.');
write_date('0'+temp%10);
write_date(0xdf);
write_date('C');
}
}
}
voidTN_IRACK_EN(void)//红外模块启动函数
{
TN_ACK=0;
}
voidTN_IRACK_UN(void)//红外模块关闭函数
{
TN_ACK=1;
}
voidTN_ReadData(ucharFlag)//读测得数据
{
uchari,j,k;
bitBitState=0;
for(k=0;k<7;k++)
{
for(j=0;j<5;j++)
{
for(i=0;i<8;i++)
{
while(TN_Clk);
BitState=TN_Data;
ReadData[j]=ReadData[j]<<1;
ReadData[j]=ReadData[j]|BitState;
while(!
TN_Clk);
}
}
if(ReadData[0]==Flag)
k=8;
}
TN_IRACK_UN();
}
voidTN_GetData(ucharX)//TN红外传感器目标数据测量子程序
{
TN_ReadData(X);
Temp=(ReadData[1]<<8)|ReadData[2];
Temp=(float)Temp/16.00-273.15;
}
voidCW(void)//测温
{
LR=~LR;
TN_IRACK_UN();//读取目标温度
TN_IRACK_EN();
TN_GetData(0x4c);
MBTemp=Temp;
TN_IRACK_UN();//读取环境温度
TN_IRACK_EN();
TN_GetData(0x66);
HJTemp=Temp;
Display(MBTemp,HJTemp);
if(DOUT==0)
{
delay(10);
if(DOUT==0)
{
beep=0;
delay(1000);
beep=1;
}
}
}
voidXS(uinti)//显示报警温度
{
if(i>0)
{
if(i<10)
{
write_com(0x80+0x40+10);
write_date('');
write_date('');
write_date('0'+i);
write_date(0xdf);
write_date('C');
write_date('');
}
elseif(i<100)
{
write_com(0x80+0x40+10);
write_date('');
write_date('0'+i/10);
write_date('0'+i%10);
write_date(0xdf);
write_date('C');
write_date('');
}
elseif(i>100)
{
write_com(0x80+0x40+10);
write_date('0'+i/100);
write_date('0'+i/10%10);
write_date('0'+i%10);
write_date(0xdf);
write_date('C');
write_date('');
}
}
}
voidTW(void)//设置报警温度值
{
while(K1==1)CW();
Init_S();
while
(1)
{
if(K2==0)
{
while(!
K2);
i++;
XS(i);
}
if(K3==0)
{
while(!
K3);
i--;
XS(i);
}
if(K==0)
{
Init_T();
while(K1==1)CW();
Init_S();
}
}
}
voidmain()
{
Init_LCD();
LG=0;
while(K==1);
Init_T();
TW();
}