資源簡介
51單片機溫度報警系統(tǒng)(溫度可以通過串口上傳至相關(guān)軟件,用1602顯示溫度)
代碼片段和文件信息
#include?
sbit?beep=P1^5;
sbit?DSPORT=P3^7;
#define?lcd?P0
sbit?RS=P2^6;
sbit?RW=P2^5;
sbit?E=P2^7;
int?temp1;
int?time;
char?num[16]=“????.???????????“;
/******************************************延遲函數(shù)*******************************/
void?delay(int?i)
{
while(i--);
}
void?Delay1ms(int?y)
{
int?x;
for(?;?y>0;?y--)
{
for(x=110;?x>0;?x--);
}
}
/*************************1602相關(guān)函數(shù)*************************/
void?mingling(int?ml)//寫入命令
{
??E=0;
??RS=0;//0
??RW=0;
??lcd=ml;
??delay(1000);
??E=1;
??delay(5000);
??E=0;
}
void?chushihua()//1602初始化設(shè)置
{
?mingling(0x38);
?mingling(0x0c);
?mingling(0x06);
?mingling(0x01);
?mingling(0x80);
}
void?write(char?sj)//寫入數(shù)據(jù)
{
? ??E=0;
??RS=1;//1
??RW=0;
??lcd=sj;
??delay(1000);
??E=1;
??delay(5000);
??E=0;
}
/********************串口函數(shù)******************************/
void?chuankou()
{
SCON=0X50;
TMOD=0X20;
PCON=0X80;
TR1=1;
TH1=0XF3; ?
TL1=0XF3;
ES=1;
EA=1;
}
/**********************數(shù)據(jù)處理函數(shù)*****************************/
int?shujuchuli(int?temp)
{ ?
??? float?tp;??
if(temp0)
?? {
temp=temp-1;
temp=~temp;
tp=temp;
temp=tp*0.0625*100+0.5;
?
?? }
? else
?? {
tp=temp;
temp=tp*0.0625*100+0.5;
}
if(temp<0)
{
num[4]=‘-‘;
}
num[1]=temp/10000+‘0‘;
num[2]=temp/1000%10+‘0‘;
num[3]=temp/100%10+‘0‘;
num[5]=temp/10%10+‘0‘;
num[6]=temp%10+‘0‘;
return?temp; ?//數(shù)據(jù)處理:溫度為負數(shù)時要取其反碼?temp=0.0625a*100+0.5?溫度=temp/100
}
/**************************************ds18b62函數(shù)***********************************************************/
int?chushihua1()
{
??int?i;
??DSPORT=0;
??i?=?70;
??while(i--);//延時642us
??DSPORT?=?1;
??i=0;
評論
共有 條評論