找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1733|回复: 0
收起左侧

普中开发板温度31度报警

[复制链接]
ID:464044 发表于 2019-5-27 11:38 | 显示全部楼层 |阅读模式
普中V2.0板子 ,设置上限报警值,数码管显示温度
# include<reg52.h>
# define uchar unsigned char
# define uint unsigned int
sbit ds=P3^7;
sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;
sbit beep=P1^5;
sbit ina=P2^0;
sbit inb=P2^1;
uchar low=10;
uchar high=31;
Displaydat[6];
uint code smgduan[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
   void Delayus(uchar t)
{
while(t--);
}
void be(int temp)
{ uchar i;
if(temp>(high*100))
  {  for(i=0;i<120;i++)
    { Delayus(60);
     beep=~beep;
    }
  } else
    { beep=0;
     
    }
}
void Datpros(int temp)
{ float tp;
if(temp<0)
  {Displaydat[0]=0x40;
temp=temp-1;
temp=~temp;
tp=temp;
temp=tp*0.0625*100+0.5;
    }
else
{  
Displaydat[0]=0x00;
tp=temp;
temp=tp*0.0625*100+0.5 ;
}
Displaydat[1]=smgduan[temp/10000];
Displaydat[2]=smgduan[temp%10000/1000];
Displaydat[3]=smgduan[temp%1000/100]|0x80;
Displaydat[4]=smgduan[temp%100/10];
Displaydat[5]=smgduan[temp%10];
be(temp);
}
void Dispaly()
{ uchar i;
for(i=0;i<6;i++)
{switch(i)
  { case(0):
    LSA=0;LSB=0;LSC=0; break;//?????0λ
   case(1):
    LSA=1;LSB=0;LSC=0; break;//?????1λ
   case(2):
    LSA=0;LSB=1;LSC=0; break;//?????2λ
   case(3):
    LSA=1;LSB=1;LSC=0; break;//?????3λ
   case(4):
    LSA=0;LSB=0;LSC=1; break;//?????4λ
   case(5):
    LSA=1;LSB=0;LSC=1; break;//?????5λ
  }  
  P0=Displaydat[5-i];  
  Delayus(200);  
  P0=0x00;}
}
uchar Ds18b20_init()
{ uchar i;
ds=0;
Delayus(70);
ds=1;  
i=0;
while(ds)
{ Delayus(20);  
i++;  
if(i>5)  
{ return 0;}  
}
return 1;
}
void Writebyte(uchar dat)
{ uchar i;
for(i=0;i<8;i++)
{ ds=0;  
Delayus(1);  
ds=dat&0x01;  
Delayus(8);  
ds=1;  
dat>>=1; }
}
uchar Readbyte()
{ uchar i,bi,byte;
for(i=0;i<8;i++)
{ ds=0;  
    ds=1;  
Delayus(1);  
bi=ds;  
byte=(byte>>1)|(bi<<7);  
Delayus(6); }
return byte;
}
void Changetemp()
{ Ds18b20_init();
Delayus(100);
Writebyte(0xcc);
Writebyte(0x44);
Delayus(10);  
Ds18b20_init();
Delayus(100);
Writebyte(0xcc);
Writebyte(0xbe);  
}
int Readtemp()
{ uchar tml,tmh;
int temp=0;
Changetemp();
tml=Readbyte();
tmh=Readbyte();
temp=tmh;
temp<<=8;
temp|=tml;
return temp;
}
void main()
{ while(1)
{Datpros(Readtemp());
Dispaly();
}
}




实验2:wd.zip

27.64 KB, 下载次数: 19, 下载积分: 黑币 -5

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表