基于lpc922单片机的电子钟温度计设计(5)

2020-02-21 13:37

else P0=0xff; delay(1); P0=0xff; }

void displaytemp() {

//显示温度 if(lm71()<0) {temp=(-lm71())/12.8+1; //得到温度值 judgetemp=-1;} else {judgetemp=1; temp=lm71()/12.8;}

DCOUNT_INT_BCD(temp); P2=0xef; //温度小数位 P0=BCD_TO_DISP(BCD[0]); delay(1); P0=0xff;

P2=0xdf; //温度个位 P0=BCD_TO_DISP(BCD[1]); tempnum=0; delay(1); P0=0xff;

P2=0xbf; //温度十位 if(temp>99) P0=BCD_TO_DISP(BCD[2]); else {if(judgetemp==-1) P0=0xbf; else P0=0xff;} delay(1); P0=0xff;

P2=0x7f; //温度百位 if(temp>999) P0=BCD_TO_DISP(BCD[3]); else if(judgetemp==-1 && temp>99) P0=0xbf; else

21

P0=0xff; delay(1); P0=0xff; }

/////////////////////////////////////////////////////时间调整函数群 /******************************** 确认键按键次数子程序

********************************/ void anjian_num() {

cort++;

if(cort==1) //第一次按下确认键 {

first_sure=1; second_sure=0; third_sure=0; fourth_sure=0; fifth_sure=0; sixth_sure=0; seventh_sure=0;

}

else if(cort==2) //第二次按下确认键 {

first_sure=0; second_sure=1; third_sure=0; fourth_sure=0; fifth_sure=0; sixth_sure=0; seventh_sure=0;

}

else if(cort==3) //第三次按下确认键 {

first_sure=0; second_sure=0; third_sure=1; fourth_sure=0; fifth_sure=0; sixth_sure=0; seventh_sure=0;

}

22

else if(cort==4) //第四次按下确认键 {

first_sure=0; second_sure=0; third_sure=0; fourth_sure=1; fifth_sure=0; sixth_sure=0; seventh_sure=0;

}

else if(cort==5) //第五次按下确认键 {

first_sure=0; second_sure=0; third_sure=0; fourth_sure=0; fifth_sure=1; sixth_sure=0; seventh_sure=0;

}

else if(cort==6) //第六次按下确认键 {

first_sure=0; second_sure=0; third_sure=0; fourth_sure=0; fifth_sure=0; sixth_sure=1; seventh_sure=0;

}

else if(cort==7) //第七次按下确认键 {

first_sure=0; second_sure=0; third_sure=0; fourth_sure=0; fifth_sure=0; sixth_sure=0; seventh_sure=1; }

23

else if(cort==8) //第8次按下确认键 { cort=0; if(judgealarm==0 && judgeupdate==1)//只有调整过时间且该时间非闹钟之时间才写入DS1302.

{

TimeByteWrite(0x80,second); //秒 TimeByteWrite(0x82,minute); //分 TimeByteWrite(0x84,hour); //时 TimeByteWrite(0x8a,week); //星期 TimeByteWrite(0x86,day); //日 TimeByteWrite(0x88,month); //月 TimeByteWrite(0x8c,year); //年 } update=1;

judgeupdate=0; } }

/******************************* 加一键子程序

*******************************/ void inc_key() {

Dsecond=X_Dswitch(second);//十六进制直接作为十进制(eg:0x16变为16) Dminute=X_Dswitch(minute); Dhour=X_Dswitch(hour); Dweek=X_Dswitch(week); Dday=X_Dswitch(day);

Dmonth=X_Dswitch(month); Dyear=X_Dswitch(year); if(seventh_sure) { Dsecond++;judgeupdate=1; if(Dsecond==60) Dsecond=0; }

if(sixth_sure) { Dminute++;judgeupdate=1; if(Dminute==60) Dminute=0; }

if(fifth_sure) {

24

Dhour++;judgeupdate=1; if(Dhour==24) Dhour=0; } if(fourth_sure) { Dweek++;judgeupdate=1; if(Dweek>7) Dweek=1; }

if(third_sure) { lastday=months(Dmonth,Dyear); Dday++;judgeupdate=1; if(Dday>lastday) Dday=1; } if(second_sure) { Dmonth++;judgeupdate=1; if(Dmonth>12) Dmonth=1; }

if(first_sure) { Dyear++;judgeupdate=1; if(Dyear==100) Dyear=0; }

second=D_Xswitch(Dsecond);//十进制直接作为十六进制(eg:16变为0x16) minute=D_Xswitch(Dminute); hour=D_Xswitch(Dhour); week=D_Xswitch(Dweek); day=D_Xswitch(Dday);

month=D_Xswitch(Dmonth); year=D_Xswitch(Dyear); if(alarmclock==0 && update==0)

{savesecond=second;saveminute=minute;savehour=hour;judgealarm=1;} }

/******************************* 减一键子程序

*******************************/ void dec_key()

25


基于lpc922单片机的电子钟温度计设计(5).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:迷人的阅读读书笔记

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: