温度控制系统代码范文Word格式.docx

上传人:b****4 文档编号:17073263 上传时间:2022-11-28 格式:DOCX 页数:22 大小:19.82KB
下载 相关 举报
温度控制系统代码范文Word格式.docx_第1页
第1页 / 共22页
温度控制系统代码范文Word格式.docx_第2页
第2页 / 共22页
温度控制系统代码范文Word格式.docx_第3页
第3页 / 共22页
温度控制系统代码范文Word格式.docx_第4页
第4页 / 共22页
温度控制系统代码范文Word格式.docx_第5页
第5页 / 共22页
点击查看更多>>
下载资源
资源描述

温度控制系统代码范文Word格式.docx

《温度控制系统代码范文Word格式.docx》由会员分享,可在线阅读,更多相关《温度控制系统代码范文Word格式.docx(22页珍藏版)》请在冰豆网上搜索。

温度控制系统代码范文Word格式.docx

/*DS1620clockline*/

//sbitDQ=0xA4;

/*DS1620dataline*/

//unsignedchardis1[]={"

lichunming"

};

//unsignedcharshow[]={"

ABCDEF"

unsignedcharshow10[]={"

"

unsignedcharshownum[]={"

000"

unsignedchartemp[]={"

temp:

structPID{

unsignedintSetPoint;

//设定目标DesiredValue

unsignedintProportion;

//比例常数ProportionalConst

unsignedintIntegral;

//积分常数IntegralConst

unsignedintDerivative;

//微分常数DerivativeConst

unsignedintLastError;

//Error[-1]

unsignedintPrevError;

//Error[-2]

unsignedintSumError;

//SumsofErrors

structPIDspid;

//PIDControlStructure

unsignedintrout;

//PIDResponse(Output)

unsignedintrin;

//PIDFeedback(Input)

//全局变量

unsignedintSetTemp;

/*----------------------------------------------------------------------*/

/*Functionprototypes*/

/*函数声明*/

unsignedintGet1620byte(void);

//读取DS1620数值

unsignedintRead1620byte(void);

//读取DS1620数值(10位的)

unsignedintDS1620StartConv(void);

//DS1620转换温度

unsignedintDS1620ReadConf(void);

//读取DS1620控制字

unsignedintDS1620read(void);

//读取DS1620温度值

unsignedintset_temp();

//设置预期温度值

voidInitDS1620(void);

//初始化DS1620

voidDisplay_Temp();

//显示温度值

voidPut1620byte(unsignedcharm);

//向DS1620写数值

voidWrite1620byte(unsignedcharm);

//向DS1620写数值(10位的)

unsignedintDS1620SetConf(unsignedcharval);

//设置DS1620控制字

voidDS1620SetTemp(unsignedTH,unsignedTL);

//设置TH、TL

voidPIDInit(structPID*pp);

/*----LCD1602显示声明函数---------*/

voidLCD_init(void);

//初始化函数

voidLCD_write_command(uchardat);

//LCD1602写指令函数

voidLCD_write_data(uchardat);

//LCD1602写数据函数

voidLCD_disp_char(ucharx,uchary,uchardat);

//LCD1602显示字符函数

voiddelay10ms(void);

//延时10ms程序

BOOLLCD_check_busy(void);

//检查忙函数

voidLCD_pos(BYTEpos);

//位置显示函数

voidLCD_disp_temp();

//显示“tem:

voidLCD_disp_num(unsignednum);

//显示读取的数字

voidp27Twin();

//灯p27闪烁程序

voidcompare_temper();

/********************************************************************/

/*---------------------------延时程序---------------------------------*/

voiddelay(intm)//m=20约为10ms

{

unsignedinti,j;

for(i=0;

i<

m;

i++)

for(j=0;

j<

253;

j++);

}

voiddelay1(intm)

12253;

voiddelay10ms(void)

unsignedinti,j,k;

for(i=5;

i>

0;

i--)

for(j=4;

j>

j--)

for(k=250;

k>

k--);

/*------------------------函数定义------------------------------------------*/

/*---------------GettempfromDS1620-----------------------------*/

/*-------------------------------------------------------------------------*/

/*从DS1620读字节函数*/

unsignedintGet1620byte(void)

unsignedintj,k,b;

k=0;

//k=valve

b=1;

//位移变量

RST=1;

for(j=0;

j<

8;

j++)

DQ=1;

CLK=0;

if(DQ)k|=b;

/*Readbitandorif=1*/

CLK=1;

b=(b<

<

1);

/*Setupfornextreadandor*/

delay10ms();

//RST=0;

returnk;

/*PuttemptoDS1620*/

/*对DS1620写字节函数*/

voidPut1620byte(unsignedintm)

unsignedintk,b;

//高电平写

for(k=0;

k<

k++)

//上升沿有效

DQ=(m&

b);

/*Sendbitto1620*/

b<

=1;

/*Setuptosendnextbit*/

//m=(m>

>

//delay10ms();

return;

/*readtempfromDS1620*/

/*DS1620读字节函数*/

//10位读取。

unsignedintRead1620byte(void)

//临时变量

//移位变量赋初值

10;

//CLK低

//输出数据

//CLK高

//移位b<

=1

/*writetempfromDS1620*/

/*DS1620函数*/

//写10位。

voidWrite1620byte(unsignedintm)

unsignedintk,b=1;

//k为临时变量

//RST高电平才能传输数据

RST=0;

/*转换温度函数*/

/*startconversion*/

unsignedintDS1620StartConv(void)

RST=1;

//RST高

Put1620byte(0xEE);

//写命令字

delay10ms();

RST=0;

//RST低

return0x00;

//返回值

}

/*读取DS1620控制字*/

/*ReadConfigRegisterofDS1620*/

unsignedintDS1620ReadConf(void)

unsignedinttemp;

//返回值临时变量

//RST高

Put1620byte(0xAC);

//写命令控制字0xAC为ReadConfig

temp=Get1620byte();

//读取控制寄存器值

//RST低

returntemp;

//返回值

/*设置DS1620控制字*/

/*SettingConfigRegisterofDS1620*/

unsignedintDS1620SetConf(unsignedintval)

{

Put1620byte(0x0C);

//写命令字

Put1620byte(val);

//写控制寄存器参数

return1;

/*从DS1620读取温度值*/

/*ReadTempfromDS1620*/

unsignedintDS1620read(void)

unsignedinttemp_and_half_bit;

/*tempbyteandhalfbit*/

unsignedintsign_bit;

/*signbit温度正负位*/

unsignedchark;

doubletemp_c;

/*temperatureindeg.C*/

doubletemp_f;

/*temperatureindeg.F*/

doubletemp_read;

/**/

unsignedintcount_remain;

/*usedforgetting.1deg.*/

unsignedintcount_per_c;

inttempi;

DS1620StartConv();

for(tempi=0;

tempi<

100;

tempi++)

{

delay10ms();

}

for(k=0;

k<

100;

k++)

Put1620byte(0xAA);

temp_and_half_bit=Get1620byte();

//读取温度的第一个字节

sign_bit=Get1620byte();

//读取温度的符号位,即正负位

/*-----Getcountremain&

countperCfor.1resolution------------*/

Put1620byte(0xA0);

//readcountremaining

count_remain=Get1620byte();

//read1stbyte

count_remain+=Get1620byte()*256;

//read2ndbyte

Put1620byte(0x41);

//loadslopeintocounter

/*readslopeascount/c0xA0=ReadCounter*/

count_per_c=Get1620byte();

count_per_c+=Get1620byte()*256;

/*----------------------------------------------------------------------*/

/*Calculate?

Cand?

F*/

if(count_per_c==0)

count_per_c=1;

temp_read=(temp_and_half_bit>

if(sign_bit!

=0)

temp_read=(temp_read-128);

temp_c=(float)temp_read-0.25+(count_per_c-count_remain)/(float)count_per_c;

//temp_c为真实摄氏温度值,上式为芯片手册给的转换公式

temp_f=temp_c*9/5+32;

//转换为华氏度

returntemp_c;

/*初始化DS1620*/

/*InitialDS1620*/

voidInitDS1620(void)

DS1620SetConf(0x02);

//设置初始化值位0x00

//DS1620SetTemp(0x50,0x14);

//设置初始温度为TH=+40℃,TL=+10℃

/*--------设置TH,TL--------------*/

voidDS1620SetTemp(TH,TL)

Put1620byte(0x01);

Write1620byte(TH);

delay(20);

Put1620byte(0x02);

Write1620byte(TL);

return;

/*显示温度函数*/

/*Display_Temp*/

voidDisplay_Temp()

unsignedintRead_Temp;

//unsignedinta,b,i,j;

//unsignedshow_data;

Read_Temp=0x00;

//转换温度

delay(50);

Read_Temp=0x12;

LCD_disp_num(Read_Temp);

p27Twin();

/*if(Read_Temp==0)

{

j=0;

while(dis1[j]!

='

\0'

LCD_pos(0x40+j);

LCD_write_data(dis1[j]);

j++;

}

else

i=0;

while(temp[i]!

)//显示字符“temp:

LCD_pos(i);

LCD_write_data(temp[i]);

i++;

*/

/*---LCD1602函数---------------*/

/****初始化函数*****/

voidLCD_init(void)

LCD_write_command(0x38);

delay

(1);

LCD_write_command(0x0c);

delay(

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 党团工作 > 党团建设

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1