温度检测系统 C51程序.docx

上传人:b****5 文档编号:4355252 上传时间:2022-11-30 格式:DOCX 页数:18 大小:169.34KB
下载 相关 举报
温度检测系统 C51程序.docx_第1页
第1页 / 共18页
温度检测系统 C51程序.docx_第2页
第2页 / 共18页
温度检测系统 C51程序.docx_第3页
第3页 / 共18页
温度检测系统 C51程序.docx_第4页
第4页 / 共18页
温度检测系统 C51程序.docx_第5页
第5页 / 共18页
点击查看更多>>
下载资源
资源描述

温度检测系统 C51程序.docx

《温度检测系统 C51程序.docx》由会员分享,可在线阅读,更多相关《温度检测系统 C51程序.docx(18页珍藏版)》请在冰豆网上搜索。

温度检测系统 C51程序.docx

温度检测系统C51程序

原理图

PCB图

程序

#include"reg51.h"

#include"intrins.h"

#include"ctype.h"

#defineucharunsignedchar

#defineuintunsignedint

typedefunsignedcharBYTE;

typedefbitBOOL;

sbitAD_CLK=P1^2;

sbitAD_CS=P1^1;

sbitAD_DI=P1^0;

sbitlb=P3^7;

sbitk1=P3^1;

sbitk2=P3^0;

sbitkw=P3^2;

sbitLCD_RS=P2^5;

sbitLCD_RW=P2^6;

sbitLCD_EP=P2^7;

unsignedcharc;

unsignedchara;

unsignedcharb;

//unsignedcharfm;

unsignedcharzs;

unsignedcharss;

unsignedcharxs;

unsignedcharxx;

unsignedchari;

unsignedcharmiao;

unsignedcharfen;

unsignedcharshi;

unsignedchard;

bitf;

unsignedchardat;

doubledat1;

doubletemp;

doublez;

BYTEcodedis1[]={"0123456789.-+:

a="};

unsignedchardispbuf[8]={0,0,0,0,0,0,0,0};

//////////////////////////////////////////////////////////

ucharreadadc1(void)//0832函数

{

uchari;

AD_CS=1;

AD_CLK=0;

_nop_();

AD_CS=0;

_nop_();

AD_DI=1;

AD_CLK=1;

_nop_();

AD_DI=0;

AD_CLK=0;

AD_DI=1;//配置位1

_nop_();

AD_CLK=1;

_nop_();

AD_CLK=0;

AD_DI=0;//配置位2

_nop_();

AD_CLK=1;

_nop_();

AD_CLK=0;

AD_DI=1;

_nop_();

AD_CLK=1;

for(i=0;i<=8;i++)

{

dat=dat<<1;

_nop_();

AD_CLK=1;

if(AD_DI)

{

dat|=0x01;

}

_nop_();

AD_CLK=0;

}

AD_CS=1;

return(dat);

}

//////////////////////////////////////////////////////////

delay(intms)//延时子程序

{

inti;

while(ms--)

{

for(i=0;i<250;i++)

{

_nop_();

_nop_();

_nop_();

_nop_();

}

}

}

////////////////////////////////////////////////////////////////////////

BOOLlcd_bz()//测试LCD忙碌状态

{

BOOLresult;

LCD_RS=0;

LCD_RW=1;

LCD_EP=1;

_nop_();

_nop_();

_nop_();

_nop_();

result=(BOOL)(P0&0x80);

LCD_EP=0;

returnresult;

}

////////////////////////////////////////////////////////////////////////

lcd_wcmd(BYTEcmd)//写入指令数据到LCD

{

while(lcd_bz());

LCD_RS=0;

LCD_RW=0;

LCD_EP=0;

_nop_();

_nop_();

P0=cmd;

_nop_();

_nop_();

_nop_();

_nop_();

LCD_EP=1;

_nop_();

_nop_();

_nop_();

_nop_();

LCD_EP=0;

}

////////////////////////////////////////////////////////////////////////

lcd_pos(BYTEpos)//设定显示位置

{

lcd_wcmd(pos|0x80);

}

////////////////////////////////////////////////////////////////////////

lcd_wdat(BYTEdat)//写入字符显示数据到LCD

{

while(lcd_bz());

LCD_RS=1;

LCD_RW=0;

LCD_EP=0;

P0=dat;

_nop_();

_nop_();

_nop_();

_nop_();

LCD_EP=1;

_nop_();

_nop_();

_nop_();

_nop_();

LCD_EP=0;

}

////////////////////////////////////////////////////////////////////////

lcd_init()//LCD初始化设定

{

lcd_wcmd(0x38);

delay

(1);

lcd_wcmd(0x0c);

delay

(1);

lcd_wcmd(0x06);

delay

(1);

lcd_wcmd(0x01);

delay

(1);

}

///////////////////////////////////////////////////////////////////

voidwdkz(void)//上下限温度时间调整函数

{

switch(a)

{

case1:

{c=1;

if(k1==0)

{

delay(50);

if(k1==1)

ss++;

elsess=ss+5;

}

if(k2==0)

{

delay(50);

if(k2==1)

ss--;

elsess=ss-5;

}

}break;

case2:

{

if(k1==0)

{

delay(50);

if(k1==1)

xx++;

elsexx=xx+5;

}

if(k2==0)

{

delay(50);

if(k2==1)

xx--;

elsexx=xx-5;

}

}break;

case5:

{

if(k1==0)

{

delay(50);

if(k1==1)

miao++;

elsemiao=miao+5;

if(miao>59)

miao=0;

}

if(k2==0)

{

delay(50);

if(k2==1)

miao--;

elsemiao=miao-5;

if(miao==0)

miao=59;

}

}break;

case4:

{

if(k1==0)

{

delay(50);

if(k1==1)

fen++;

elsefen=fen+5;

if(fen>59)

fen=0;

}

if(k2==0)

{

delay(50);

if(k2==1)

fen--;

elsefen=fen-5;

if(fen==0)

fen=59;

}

}break;

case3:

{

if(k1==0)

{

delay(50);

if(k1==1)

shi++;

elseshi=shi+5;

if(shi>23)

shi=0;

}

if(k2==0)

{

delay(50);

if(k2==1)

shi--;

elseshi=shi-5;

if(shi==0)

shi=23;

}

}break;

}

}

/////////////////////////////////////////////////////////////////

voidxians()//显示函数

{

lcd_wcmd(0x06);

lcd_pos(0x00);//上限温度

lcd_wdat(dis1[ss/100]);

lcd_pos(0x01);

lcd_wdat(dis1[ss/10%10]);

lcd_pos(0x02);

lcd_wdat(dis1[ss%10]);

lcd_pos(0x08);

lcd_wdat(dis1[shi/10]);

lcd_pos(0x09);

lcd_wdat(dis1[shi%10]);

lcd_pos(0x0a);

lcd_wdat(dis1[13]);

lcd_pos(0x0b);

lcd_wdat(dis1[fen/10]);

lcd_pos(0x0c);

lcd_wdat(dis1[fen%10]);

lcd_pos(0x0d);

lcd_wdat(dis1[13]);

lcd_pos(0x0e);

lcd_wdat(dis1[miao/10]);

lcd_pos(0x0f);

lcd_wdat(dis1[miao%10]);

lcd_pos(0x40);

lcd_wdat(dis1[xx/100]);

lcd_pos(0x41);

lcd_wdat(dis1[xx/10%10]);

lcd_pos(0x42);

lcd_wdat(dis1[xx%10]);

lcd_pos(0x45);

lcd_wdat(dis1[14]);

lcd_pos(0x46);

lcd_wdat(dis1[15]);

lcd_pos(0x47);

lcd_wdat(dis1[a]);

lcd_pos(0x4a);

lcd_wdat(dis1[dispbuf[0]]);

lcd_pos(0x4b);

lcd_wdat(dis1[dispbuf[1]]);

lcd_pos(0x4c);

lcd_wdat(dis1[dispbuf[2]]);

lcd_pos(0x4d);

lcd_wdat(dis1[dispbuf[3]]);

lcd_pos(0x4e);

lcd_wdat(dis1[dispbuf[4]]);

lcd_pos(0x4f);

lcd_wdat(dis1[dispbuf[5]]);

}

///////////////////////////////////////////////////////////////////

voidbaojing()//报警

{

lb=1;

if(temp>ss)

{

lb=0;

}

if(temp

{

lb=0;

}

/*fm=1;

if(temp>ss)

{

fm=0;

}

if(temp

{

fm=0;

}*/

}

//////////////////////////////////////////////////////////////////

zhuanhuan()//转换函数

{

z=dat*0.01960784;

if(z>2.602)

{

dispbuf[0]=12;

temp=(z-2.602)*100;

zs=(unsignedchar)temp;

xs=(unsignedchar)((temp-zs)*10);

dispbuf[1]=zs/100;

dispbuf[2]=zs/10%10;

dispbuf[3]=zs%10;

dispbuf[4]=10;

dispbuf[5]=xs;

}

else

{

dispbuf[0]=11;

temp=(2.602-z)*100;

zs=(unsignedchar)temp;

xs=(unsignedchar)((temp-zs)*100);

dispbuf[3]=zs%10;

dispbuf[2]=zs/10%10;

dispbuf[1]=zs/100;

dispbuf[4]=10;

dispbuf[5]=xs/10;

dispbuf[6]=xs%10;

}

}

///////////////////////////////////////////////////////////////////

main()//主函数

{

lcd_init();

delay(10);

ss=123;

xx=3;

f=1;

TMOD=0x11;

TL1=0xb0;

TH1=0x3c;

TH0=(65536-50000)/256;

TL0=(65536-50000)%256;

TR1=1;

TR0=1;

ET0=1;

ET1=1;

EA=1;

IT0=1;

EX0=1;

while

(1)

{

xians();

baojing();

wdkz();

if(f==1)

{

readadc1();

zhuanhuan();

f=0;

}

}

}

////////////////////////////////////////////////////////////////

voidt1(void)interrupt3using0//定时1

{

TL1=0xb0;

TH1=0x3c;

d++;

if(d==20)

{

f=1;

d=0;

}

}

////////////////////////////////////////////////////////////////

voidX0(void)interrupt0//中断

{

delay(20);

if(kw==0)

{

a++;

if(a==6)

a=0;

}

}

//////////////////////////////////////////////////////////////////

voidt0(void)interrupt1using0//定时0

{

TH1=(65536-50000)/256;

TL1=(65536-50000)%256;

b++;

if(b==15)

{

b=0;

miao++;

if(miao>59)

{

miao=0;

fen++;

if(fen>59)

{

fen=0;

shi++;

if(shi>23)

{

shi=0;

}

}

}

}

}

///

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

当前位置:首页 > PPT模板 > 其它模板

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

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