|
设计一个具有温度实时显示的温度检测系统:
1.液晶屏LCD显示当前温度和设定温度;
2.每1s采样温度,LCD更新显示值;
3.温度测量精度: 0.1"C;
4.通过按键设定温度的上、下限,超过所设定的阈值,声光报警。
但是我通过程序后液晶屏和灯无反应
程序如下
1602.h
#include<reg51.h>
#include<intrins.h>
sbit RS=P3^6;
sbit RW=P3^5;
sbit E=P3^3;
void lcd_w_cmd(unsigned char com);
void lcd_w_dat(unsigned char dat);
unsigned char lcd_r_start();
void int1();
void delay(unsigned char t);
void delay1();
void delay(unsigned char t)
{
unsigned char j,i;
for(i=0;i<t;i++)
for(j=0;j>50;j++);
}
void delay1()
{
_nop_();
_nop_();
_nop_();
}
void int1()
{
lcd_w_cmd(0x38);
lcd_w_cmd(0x0C);
lcd_w_cmd(0x01);
lcd_w_cmd(0x06);
}
unsigned char lcd_r_start()
{
unsigned char s;
RW=1;
delay1();
RS=0;
delay1();
E=1;
delay1();
s=P0;
delay1();
E=0;
delay1();
RW=0;
delay1();
return(s);
}
void lcd_w_cmd(unsigned char com)
{
unsigned char i;
do{
i=lcd_r_start();
i=i&0x80;
delay(2);
}
while(i!=0);
RW=0;
delay1();
RS=0;
delay1();
E=1;
delay1();
P0=com;
delay1();
E=0;
delay1();
RW=1;
delay(25);
}
void lcd_w_dat(unsigned char dat)
{
unsigned char i;
do{
i=lcd_r_start();
i=i&0x80;
delay(2);
}
while(i!=0);
RW=0;
delay1();
RS=1;
delay1();
E=1;
delay1();
P0=dat;
delay1();
E=0;
delay1();
RW=1;
delay(25);
}
18b20.h
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit DQ=P2^7;
uint temp,t;
uchar data disdata[5];
void delay_18B20(unsigned int i)
{
while(i--);
}
void delay1ms(unsigned int ms)
{
unsigned int i,j;
for(i=0;i<ms;i++)
for(j=0;j<100;j++);
}
//DS18B20初始化
void Init_DS18B20(void)
{
unsigned char x=0;
DQ=1;
delay_18B20(80);
DQ=0;
delay_18B20(800);
DQ=1;
delay_18B20(140);
x=DQ;
delay_18B20(200);
}
unsigned char ReadOneChar(void)
{
uchar i=0;
uchar dat=0;
for(i=8;i>0;i--)
{
DQ=0;
dat>>=1;
DQ=1;
if(DQ)
dat|=0x80;
delay_18B20(40);
}
return(dat);
}
void WriteOneChar(uchar dat)
{
unsigned char i;
for(i=8;i>0;i--)
{
DQ=0;
DQ=dat&0x01;
delay_18B20(50);
DQ=1;
dat>>=1;
}
}
unsigned int ReadTemp(void)
{
unsigned char a=0;
unsigned char b=0;
unsigned int temp_value=0;
Init_DS18B20();
WriteOneChar(0xCC);
WriteOneChar(0x44);
delay_18B20(100);
Init_DS18B20();
WriteOneChar(0xCC);
WriteOneChar(0xBE);
delay_18B20(100);
a=ReadOneChar();
b=ReadOneChar();
temp_value=b<<8;
temp_value|=a;
return temp_value;
}
void writete()
{
uchar tflag;
while(1)
{
temp=ReadTemp();
if(temp<0x7ff)
{
tflag=0;
}
else
{
tflag=1;
temp=(~temp)+1;
}
t=temp*0.625;
}
}
main.c(123456.c)
#include<reg51.h>
#include<1602.h>
#include<18b20.h>
#define uchar unsigned char
sbit key_c=P2^3; //切换
sbit key_jia=P2^4; //增加
sbit key_jian=P2^5; //减少
sbit led1=P2^1; //绿灯
sbit led2=P2^0; //红灯
sbit BEEP=P2^2; //蜂鸣器
void key();
uchar th=30,tl=20;
uchar num=0;
unsigned char we[]={"T: "};
unsigned char table[]={"H: L: "};
void display_lcd1();
void display_lcd(unsigned char th,tl);
void display_lcd1()
{
unsigned char k;
we[2]=t/1000+0x30;
we[3]=t%1000/100+0x30;
we[4]=t%1000%100/10+0x30;
we[5]='.';
we[6]=t%1000%100%10+0x30;
lcd_w_cmd(0x80);
delay(2);
for(k=0;k<9;k++)
{
lcd_w_dat(we[k]);
delay(2);
}
}
void display_lcd(unsigned char th,tl)
{
unsigned char i;
table[2]=th/10+0x30;
table[3]=th%10+0x30;
table[9]=tl/10+0x30;
table[10]=tl%10+0x30;
lcd_w_cmd(0xc0);
delay(2);
for(i=0;i<15;i++)
{
lcd_w_dat(table[i]);
delay(2);
}
}
void main()
{
while(1)
{
display_lcd(th,tl);
display_lcd1();
}
led1=0;
led2=1;
BEEP=1;
if(temp>th*10||temp<tl*10)
{
led1=1;
led2=~led2;
BEEP=~BEEP;
}
else
{
led1=0;
led2=1;
BEEP=1;
}
}
void key()
{
if(!key_c)
{
delay(5);
if(!key_c)
{
num++;
while(key_c==0);
if(num==2)
{
num=0;
}
}
}
if(!key_jia && num==0)
{
delay(5);
if(!key_jia && num==0)
{
th++;
while(key_jia);
lcd_w_cmd(0x80);
}
}
else if(!key_jian && num==0)
{
delay(5);
if(!key_jian && num==0)
{
th--;
while(key_jian);
lcd_w_cmd(0x80);
}
}
if(!key_jia && num==0)
{
delay(5);
if(!key_jia && num==0)
{
tl++;
while(key_jia);
lcd_w_cmd(0x80);
}
}
else if(!key_jian && num==0)
{
delay(5);
if(!key_jian && num==0)
{
tl--;
while(key_jian);
lcd_w_cmd(0x80);
}
}
}
报出的警告
linking...
*** WARNING L16: UNCALLED SEGMENT, IGNORED FOR OVERLAY PROCESS
SEGMENT: ?PR?INT1?123456
*** WARNING L16: UNCALLED SEGMENT, IGNORED FOR OVERLAY PROCESS
SEGMENT: ?PR?_DELAY1MS?123456
*** WARNING L16: UNCALLED SEGMENT, IGNORED FOR OVERLAY PROCESS
SEGMENT: ?PR?WRITETE?123456
*** WARNING L16: UNCALLED SEGMENT, IGNORED FOR OVERLAY PROCESS
SEGMENT: ?PR?KEY?123456
Program Size: data=45.0 xdata=0 code=1562
|
|