什么什么仿真不出来啊。。。温度什么都没有
时间:10-02
整理:3721RD
点击:
//=========================================/
#include<reg51.h>
#include<intrins.h>
#include<string.h>
//---------------------------------------------------------
#define PORT P2
#define NEGATIVE 10
#define POSITIVE 11
#define Y 0XFF
#define N 0x00
#define LOW 0X00
#define HI 0x01
//读端口数据-----------------------------------------------
#define POWERON ((P1&(1<<0))>>0) //p1.0
#define POWEROFF ((P1&(1<<1))>>1) //p1.1
#define MODEL ((P1&(1<<2))>>2) //p1.2
#define ADD ((P1&(1<<3))>>3) //P1.3
#define DEC ((P1&(1<<4))>>4) //P1.4
#define OK ((P1&(1<<5))>>5) //P1.5
//写端口数据------------------------------------------------
sbit HOT =P3^0;
sbit workingled =P3^1;
sbit timerled =P3^2;
sbit baowenled =P3^3;
sbit baotangled =P3^4;
sbit zhufanled =P3^5;
sbit RS =P0^0;
sbit RW =P0^1;
sbit EN =P0^2;
sbit DQ =P1^7;
//------------------------------------------------------
unsigned char code shuzidaima[]=
{0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x2d,0x2b};
unsigned char temp_lowbyte_unprocess;
unsigned char temp_hibyte_unprocess;
unsigned char temp_xiao;
unsigned char temp_ge;
unsigned char temp_shi;
unsigned char temp_bai;
unsigned char temp_fuhao;
//-------------------------------------------------------
unsigned char poweron=N;
unsigned char model=0;
unsigned char dest_temp=0;
unsigned char now_temp=255;
signed int min_num=0;
unsigned char timersetting_state=0;
unsigned char timing_state=N;
unsigned int loop=0;
unsigned char loop1=0;
unsigned char loop2=0;
unsigned int loop3=0;
/*=======子程序=======*/
//----------------------------------------------------------------
//函数名:delay()
//-----------------------------------------------------------------
void delay()
{
unsigned int i;
for(i=0;i<=800;i++)
{;}
}
//----------------------------------------------------------------
//----------------------------------------------------------------
//函数名:lcd_wcomd()
//-----------------------------------------------------------------
void lcd_wcomd(unsigned char command)
{
RS=0;
RW=0;
PORT=command;
delay();
EN=1;
_nop_();
EN=0;
delay();
}
//----------------------------------------------------------------
//函数名:lcd_wdata()
//-----------------------------------------------------------------
void lcd_wdata(unsigned char dat)
{
RS=1;
RW=0;
PORT=dat;
delay();
EN=1;
_nop_();
EN=0;
delay();
}
//----------------------------------------------------------------
//函数名:lcd_ini()
//-----------------------------------------------------------------
void lcd_ini()
{
lcd_wcomd(0x01);
lcd_wcomd(0x06);
lcd_wcomd(0x0c);
lcd_wcomd(0x38);
}
//----------------------------------------------------------------
//函数名:printchar()
//-----------------------------------------------------------------
void printchar(unsigned char zifu[])
{
unsigned char j,k;
k=strlen(zifu);
for(j=0;j<=k-1;j++)
{
lcd_wdata(zifu[j]);
}
}
//----------------------------------------------------------------
//函数名:display_num()
//-----------------------------------------------------------------
void display_num(unsigned char shuzi_in)
{
lcd_wdata(shuzidaima[shuzi_in]);
}
//----------------------------------------------------------------
//函数名:display_1602()
//-----------------------------------------------------------------
void display_1602()
{
lcd_wcomd(0x80+0x00);
printchar("Model:");
lcd_wcomd(0x80+0x07);
if(timersetting_state>=1)
{
printchar("TimerSet ");
}
else
{
if(model==0)
{
printchar("-- -- ");
}
if(model==1)
{
printchar("KeepWarm");
}
if(model==2)
{
printchar("PotSoup ");
}
if(model==3)
{
printchar("CookRice");
}
}
}
//----------------------------------------------------------------
//函数名:delay1()
//-----------------------------------------------------------------
void delay1(unsigned int n)
{
for(n;n>0;n--)
{;}
}
//----------------------------------------------------------------
//函数名:rest_1820()
//-----------------------------------------------------------------
void rest_1820()
{
DQ=0;
DQ=1;
delay1(77);
}
//----------------------------------------------------------------
//函数名:write_18b20(unsigned char xiecan)
//-----------------------------------------------------------------
void write_18b20(unsigned char xiecan)
{
unsigned char xie_i;
for(xie_i=1;xie_i<=8;xie_i++)
{
DQ=0;
delay1(1);
_nop_();_nop_();
_nop_();_nop_();
_nop_();_nop_();
_nop_();
_nop_();DQ=1;
DQ=0x01&xiecan;
delay1(6);
_nop_();_nop_();
_nop_();_nop_();
_nop_();_nop_();
DQ=1;
_nop_();_nop_();_nop_();
_nop_();_nop_();
xiecan=xiecan>>1;
}
}
//----------------------------------------------------------------
//函数名:read_18b20()
//-----------------------------------------------------------------
unsigned char read_18b20()
{
unsigned char du_i;
unsigned char outdata_1820=0x00;
unsigned char tmp_du=0x00;
for(du_i=1;du_i<=8;du_i++)
{
DQ=1;
DQ=0;
_nop_();
_nop_();
DQ=1;
_nop_();
tmp_du=P1&0x80;
tmp_du=tmp_du<<0;
outdata_1820=outdata_1820|tmp_du;
delay1(8);
if(du_i==8)break;
outdata_1820=outdata_1820>>1;
}
return(outdata_1820);
}
//----------------------------------------------------------------
//函数名: readtemp_conver()
//-----------------------------------------------------------------
void readtemp_conver()
{
rest_1820();
write_18b20(0xcc);
write_18b20(0x44);
}
//----------------------------------------------------------------
//函数名: readtemp_readdata()
//-----------------------------------------------------------------
void readtemp_readdata()
{
rest_1820();
write_18b20(0xcc);
write_18b20(0xbe);
temp_lowbyte_unprocess=read_18b20();
temp_hibyte_unprocess=read_18b20();
}
//---------------------------------
//函数名: chazhi()
//-----------------------------------
unsigned char chazhi(unsigned char h_data)
{
if(h_data<=0x05)
{
if(h_data==0x00)return(0);
if(h_data==0x01)return(1);
if(h_data==0x02)return(2);
if(h_data==0x03)return(3);
if(h_data==0x04)return(4);
if(h_data==0x05)return(5);
}
else if(h_data<=0x0a)
{
if(h_data==0x06)return(6);
if(h_data==0x07)return(7);
if(h_data==0x08)return(8);
if(h_data==0x09)return(9);
if(h_data==0x0a)return(10);
}
else
{
if(h_data==0x0b)return(11);
if(h_data==0x0c)return(12);
if(h_data==0x0d)return(13);
if(h_data==0x0e)return(14);
if(h_data==0x0f)return(15);
else return(0);
}
}
//----------------------------------------------------------------
//函数名:readtemp_process()
//-----------------------------------------------------------------
unsigned int readtemp_process()
{
unsigned char hex_canshu;
unsigned int dec_jieguo;
unsigned char hex_gao,hex_di;
hex_di=hex_canshu&0x0f;
hex_gao=hex_canshu>>4;
hex_di=chazhi(hex_di);
hex_gao=chazhi(hex_gao);
dec_jieguo=hex_gao*16+hex_di;
return(dec_jieguo);
}
//---------------
//函数名:Init_DS18B20()
//------------------
void Init_DS18B20(void)
{
unsigned char x=0;
DQ = 1; //DQ复位
delay1(8); //稍做延时
DQ = 0; //单片机将DQ拉低
delay1(80); //精确延时 大于 480us
DQ = 1; //拉高总线
delay1(4);
x=DQ; //稍做延时后 如果x=0则初始化成功 x=1则初始化失败
delay1(20);
}
//----------------------------------------------------------------
//函数名:key()
//-----------------------------------------------------------------
void key()
{
if(POWERON==LOW)
{
poweron=Y;
workingled=0;
model=0;
}
if(POWEROFF==LOW)
{
poweron=N;
workingled=1;
model=0;
}
if(poweron==Y)
{
if(model>1&&now_temp>dest_temp)
{
model=1;
}
if(MODEL==LOW&&loop>3)
{
model++;
if(model==4)
{
model=1;
}
loop=0;
}
if(ADD==LOW&&timersetting_state>=1&&loop>3)
{
if(timersetting_state==1)
{
min_num=min_num+60;
if(min_num>720)
{
min_num=0;
}
}
if(timersetting_state==2)
{
min_num=min_num+1;
if(min_num>720)
{
min_num=0;
}
}
loop=0;
}
if(DEC==LOW&&timersetting_state>=1&&loop>3)
{
if(timersetting_state==1)
{
min_num=min_num-60;
if(min_num<=0)
{
min_num=0;
}
}
if(timersetting_state==2)
{
min_num=min_num-1;
if(min_num<=0)
{
min_num=0;
}
}
loop=0;
}
if(OK==LOW&&loop>3)
{
timersetting_state++;
if(timersetting_state>=3)
{
timersetting_state=0;
timing_state=Y;
}
loop=0;
}
}
}
//----------------------------------------------------------------
//函数名:model_process()
//-----------------------------------------------------------------
void model_process()
{
switch(model)
{
case 1:
timerled=1;
baowenled=0;
baotangled=1;
zhufanled=1;
dest_temp=65;
break;
case 2:
timerled=1;
baowenled=1;
baotangled=0;
zhufanled=1;
dest_temp=98;
break;
case 3:
timerled=1;
baowenled=1;
baotangled=1;
zhufanled=0;
dest_temp=110;
break;
default:
timerled=1;
baowenled=1;
baotangled=1;
zhufanled=1;
dest_temp=0;
}
}
//----------------------------------------------------------------
//函数名:hot_ctrl()
//-----------------------------------------------------------------
void hot_ctrl()
{
if((now_temp<dest_temp)&&(timing_state==N))
{
HOT=1;
}
if((now_temp>=dest_temp)||(timing_state==Y))
{
HOT=0;
}
}
/*===============MAIN()函数==============*/
void main()
{
HOT=0;
Init_DS18B20();
lcd_ini();
while(1)
{
if(loop2==0){readtemp_conver();}
if(loop2==1){readtemp_readdata();}
if(loop2==2){readtemp_process();}
display_1602();
key();
model_process();
hot_ctrl();
//------------------------
loop++;
if(loop>=20)
{
loop=20;
}
loop1++;
if(loop1>=6)
{
loop1=0;
}
loop2++;
if(loop2>=3)
{
loop2=0;
}
loop3++;
if(loop3>=100)
{
loop3=0;
if((timing_state==Y)&&(min_num>0))
{
min_num--;
if(min_num==0)
{
timing_state=N;
}
}
}
//------------------------------------------------
if(((timing_state==Y)||(timersetting_state>0))&&(poweron==Y))
{
timerled=0;
}
else
{
timerled=1;
}
}
}
我的情况跟你的一模一样,你的解决了吗?
QQ:973139361
一起探讨一下呗
才发现是13年的帖子。