找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1705|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

普中開發(fā)板溫度31度報警

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:464044 發(fā)表于 2019-5-27 11:38 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
普中V2.0板子 ,設(shè)置上限報警值,數(shù)碼管顯示溫度
# 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, 下載次數(shù): 19, 下載積分: 黑幣 -5

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表