淄博职业学院毕业设计 第三章 电路的硬件与软件设计
3.8程序设计框图与源程序
Y 修正时间 设置闹钟 开始 LCD初始化 1302初始化 启动台灯 显示温度 读取时间 显示时间 有键按下? While(1) 循 环 N
N 闹钟和时间匹配 Y 闹钟
图3.9程序主框图
结束 17
淄博职业学院毕业设计 第三章 电路的硬件与软件设计
图3.10中断流程图
源程序:
# include
unsigned char a=210,b=210,i=0,k;
init_lcd(); ds1302_init(); while(1)
{
for(i=0;i
18
淄博职业学院毕业设计 第三章 电路的硬件与软件设计
for(i=b;i
Led_Off;
k=keyscan(); if(k==1) {
b=(b>=180?210:b+30); }
else if(k==2) {
b=(b<=30)?0:b-30; } {
unsigned char a=0; unsigned char b=0; unsigned int t=0; float tt=0;
Init_DS18B20(); WriteOneChar(0xCC); WriteOneChar(0x44); Init_DS18B20(); WriteOneChar(0xCC); WriteOneChar(0xBE); a=ReadOneChar();
b=ReadOneChar(); t=b; t=t<<8;
display_temp();//显示温度 ds1302();//读取时间
set_time();//设置时间 display_time();//显示时间 set_clock();//设置闹钟
baoshi();//闹钟报警
}
unsigned int Readtemp()//读取温度
19
淄博职业学院毕业设计 第三章 电路的硬件与软件设计
}
t=t|a; tt=t*0.0625; t= tt*100+0.5; return(t);
void display_temp()//显示温度 { } //1602
#include
#define uchar unsigned char #define uint unsigned int sbit lcdrs=P2^4; sbit lcdrw=P2^3; sbit lcden=P2^2; uchar code t0[]=%uchar code t1[]=\
unsigned int num; unsigned int shi,ge,xiaoshu1,xiaoshu2; num=Readtemp(); shi=num/1000; ge=num00/100; xiaoshu1=num0/10; xiaoshu2=num; lcd_wcmd(0x80+2); lcd_wdat(wendu[shi]); lcd_wcmd(0x80+3); lcd_wdat(wendu[ge]); lcd_wcmd(0x80+4); lcd_wdat(0x2e); lcd_wcmd(0x80+5);
lcd_wdat(wendu[xiaoshu1]); lcd_wcmd(0x80+6);
lcd_wdat(wendu[xiaoshu2]);
20
淄博职业学院毕业设计 第三章 电路的硬件与软件设计
void Delayms(uint ms)//延时------------ { uchar i;
while(ms--)for(i=0;i<120;i++);
} { bit result; lcdrs = 0; lcdrw = 1; lcden = 1; _nop_(); _nop_(); _nop_(); _nop_(); result = (bit)(P0&0x80); lcden = 0; return result; } void calculate(void)//计算时间 {
second[0]=tab_1302[0]/10+0x30 ; second[1]=tab_1302[0]+0x30 ; minute[0]=tab_1302[1]/10+0x30 ; minute[1]=tab_1302[1]+0x30 ; hour[0]=tab_1302[2]/10+0x30 ; hour[1]=tab_1302[2]+0x30 ; day[0]=tab_1302[3]/10+0x30 ; day[1]=tab_1302[3]+0x30 ; month[0]=tab_1302[4]/10+0x30 ; month[1]=tab_1302[4]+0x30 ; year[0]=2+0x30 ;
year[1]=tab_1302[6]/100+0x30 ; year[2]=tab_1302[6]/10 +0x30;
bit lcd_busy() //检测LCD是否为忙
21