单片机温度控制系统.docx
- 文档编号:7237985
- 上传时间:2023-01-22
- 格式:DOCX
- 页数:14
- 大小:17.78KB
单片机温度控制系统.docx
《单片机温度控制系统.docx》由会员分享,可在线阅读,更多相关《单片机温度控制系统.docx(14页珍藏版)》请在冰豆网上搜索。
单片机温度控制系统
#include
#include
//*******************函数定义*********************
voidlong_delay(void);//长延时
voidshort_delay(void);//短延时
voiddelay10ms(unsignedchar);//延时10MS
voidwrite7279(unsignedchar,unsignedchar);//写入到HD7279
unsignedcharread7279(unsignedchar);//从HD7279读出
voidsend_byte(unsignedchar);//发送一个字节
unsignedcharreceive_byte(void);//接收一个字节
voidzhidingzhi(void);//读取按键给定指定值
voidTempDelay(unsignedchar);//延时处理
voidInit18b20(void);//18B20初始化
voidWriteByte(unsignedchar);//向18B20写入一个字节
unsignedcharReadByte(void);//读18B20的一个字节
voidread_bytes(unsignedchar);//读18B20
unsignedcharCRC(unsignedchar);//CRC校验
voidGemTemp(void);//读取温度
voidConfig18b20(void);//重新配置报警限定值和分辨率
voidReadID(void);//读取器件
voidTemperatuerResult(void);//18B20ID全处理
//*************变量及I/O口定义******************
unsignedchardigit[5];
unsignedcharkey_number,j,i,k,t;//flag做键标记
unsignedinttmr,flag1,flag[8];//fflag1数码管位标记
unsignedlongwait_cnter;
sbitcs=P0^3;//csatP0.3
sbitclk=P0^2;//clk连接于P0.2
sbitdat=P0^0;//dat连接于P0.0
sbitkey=P0^1;//key连接于P0.1
sbitzdz=P1^0;
sbitdq=P1^7;
bitflag2;
unsignedintTemperature;
unsignedintzhidz;
unsignedintTP[5];
unsignedchartemp_buff[9];//存储读取的字节,readscratchpad为9字节,readromID为8字节
unsignedcharid_buff[8];
unsignedchar*p;
unsignedcharcrc_data;
unsignedcharcodeCrcTable[256]={0,94,188,226,97,63,221,131,194,156,126,32,163,253,31,65,157,195,33,127,252,162,64,30,95,1,227,189,62,96,130,220,35,125,159,193,66,28,254,160,225,191,93,3,128,222,60,98,190,224,2,92,223,129,99,61,124,34,192,158,29,67,161,255,70,24,250,164,39,121,155,197,132,218,56,102,229,187,89,7,219,133,103,57,186,228,6,88,25,71,165,251,120,38,196,154,101,59,217,135,4,90,184,230,167,249,27,69,198,152,122,36,248,166,68,26,153,199,37,123,58,100,134,216,91,5,231,185,140,210,48,110,237,179,81,15,78,16,242,172,47,113,147,205,17,79,173,243,112,46,204,146,211,141,111,49,178,236,14,80,175,241,19,77,206,144,114,44,109,51,209,143,12,82,176,238,50,108,142,208,83,13,239,177,240,174,76,18,145,207,45,115,202,148,118,40,171,245,23,73,8,86,180,234,105,55,213,139,87,9,235,181,54,104,138,212,149,203,41,119,244,170,72,22,233,183,85,11,136,214,52,106,43,117,151,201,74,20,246,168,116,42,200,150,21,75,169,247,182,232,10,84,215,137,107,53};
//****************HD7279A指令************
#defineCMD_RESET0xa4
#defineCMD_TEST0xbf
#defineDECODE00x80
#defineDECODE10xc8
#defineCMD_READ0x15
#defineUNDECODE0x90
#defineRTL_CYCLE0xa3
#defineRTR_CYCLE0xa2
#defineRTL_UNCYL0xa1
#defineRTR_UNCYL0xa0
#defineACTCTL0x98
#defineSEGON0xe0
#defineSEGOFF0xc0
#defineBLINKCTL0x88
//****************按键宏定义************
#definekey10x3a
#definekey20x39
#definekey30x38
#definekey40x32
#definekey50x31
#definekey60x30
#definekey70x2a
#definekey80x29
#definekey90x28
#definekey00x21
#definekey_left0x37
#definekey_right0x2f
#definekey_up0x3f
#definekey_down0x27
#definekey_esc0x22
#definekey_enter0x20
//***************主程序*****************
main()
{
for(tmr=0;tmr<0x2000;tmr++);//上电延时
send_byte(CMD_RESET);//复位HD7279A
cs=1;
flag1=7;
write7279(DECODE0+7,0x0a);
write7279(DECODE0+6,0x0a);
while
(1)
{
zhidingzhi();
for(t=0;t<5;t++)
{
TemperatuerResult();
TP[t]=Temperature;
}
Temperature=(TP[0]+TP[1]+TP[2]+TP[3]+TP[4])/5;
write7279(DECODE1,Temperature%10);
write7279(DECODE1+1,0x80+(Temperature%100)/10);
write7279(DECODE1+2,Temperature/100);
zhidz=flag[7]*100+flag[6]*10;
if(zhidz>=Temperature){zdz=1;}
else{zdz=0;}
write7279(BLINKCTL,0xff);//清除闪烁设置
delay10ms(10);
}
}
voidwrite7279(unsignedcharcmd,unsignedchardta)
{send_byte(cmd);
send_byte(dta);
cs=1;}
unsignedcharread7279(unsignedcharcommand)
{send_byte(command);
cs=1;
return(receive_byte());
}
voidsend_byte(unsignedcharout_byte)//发送一个命令字
{unsignedchari;
clk=0;
cs=0;
short_delay();
for(i=0;i<8;i++)
{clk=0;
if(out_byte&0x80){dat=1;}
else{dat=0;}
clk=1;
short_delay();
out_byte=out_byte*2;}
dat=1;
}
unsignedcharreceive_byte(void)//接收一个命令字
{
unsignedchari,in_byte;
cs=0;
clk=0;
dat=1;//设为输入状态
short_delay();
for(i=0;i<8;i++)
{
clk=0;
in_byte=in_byte*2;
clk=1;
if(dat==1)
{in_byte=in_byte|0x01;}
}
dat=1;
//cs=1;
return(in_byte);
}
voidlong_delay(void)//长延时
{unsignedchari;
for(i=0;i<0x30;i++);}
voidshort_delay(void)//短延时
{unsignedchari;
for(i=0;i<8;i++);
}
//*********************n*10ms**********************
voiddelay10ms(unsignedchartime)
{unsignedchari;
unsignedintj;
for(i=0;i
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 单片机 温度 控制系统