51单片机+ds1302+DS18b20温度时钟(电路图+C语言程序)

clock_en=0;//开机时默认关闭闹钟 init_t0(); TR0=1;//

// set_ds1302();//设置DS1302的初始时间 //接下来开始编写让数码管显示的程序 while(1) {

get_ds1302();

judge_dis();//显示处理 judge_s1(); judge_s2(); judge_s3();

judge_clock();//闹钟处理程序 } }

void timer0() interrupt 1 {

TH0=(65536-50000)/256; TL0=(65536-50000)%6; t0_crycle++;

if(t0_crycle==2)// 0.1秒 {

t0_crycle=0;

msecond_flag=1; msecond_count++;

if(msecond_count==10)//1秒 {

msecond_count=0; second_flag=1; } } }

//************************************************** //显示处理函数 void judge_dis() {

if(flag1==0) {

if(second_flag==1) {

zancun7++; second_flag=0; }

if(zancun7<1)

{

if(temp_flag2==1) {

readtemp_ds18b20();//读取温度 temp_flag2=0; }

dis_temp();//温度显示函数 }

if(zancun7>=1) {

temp_flag2=1;

zancun4=hour_count&0xf0; zancun4>>=4;

zancun5=minute_count&0xf0; zancun5>>=4;

zancun6=second_count&0xf0; zancun6>>=4;

dis(zancun4,hour_count&0x0f,zancun5,minute_count&0x0f,zancun6,second_count&0x0f);

dis_led();

if(zancun7==5)zancun7=0; } }

if(flag1!=0) {

switch(flag1) {

case 1:

dis(5,10,11,1,12,12);//显示SET1 led1_bit=1; led2_bit=1; break; case 2:

dis(5,10,11,2,12,12);//显示SET2 break; case 3:

dis(5,10,11,3,12,12);//显示SET3 break; case 4:

dis(5,10,11,4,12,12);//显示SET4 break; case 5:

dis(5,10,11,5,12,12);//显示SET5 break; case 6:

dis_san(zancun1/10,zancun1,zancun2/10,zancun2,12,12,1); break; case 7:

dis_san(zancun1/10,zancun1,zancun2/10,zancun2,12,12,2); break; case 8:

dis_san(zancun1/10,zancun1,zancun2/10,zancun2,12,12,3); break;

case 9://进入修改时间,时间分位个位闪烁

dis_san(zancun1/10,zancun1,zancun2/10,zancun2,12,12,4); break;

case 10://进入修改闹钟,闹钟小时十位闪烁

dis_san(zancun1/10,zancun1,zancun2/10,zancun2,12,zancun3,1); break;

case 11://进入修改闹钟,闹钟小时个位闪烁

dis_san(zancun1/10,zancun1,zancun2/10,zancun2,12,zancun3,2); break;

case 12://进入修改闹钟,闹钟小时十位闪烁

dis_san(zancun1/10,zancun1,zancun2/10,zancun2,12,zancun3,3); break;

case 13://进入修改闹钟,闹钟小时个位闪烁

dis_san(zancun1/10,zancun1,zancun2/10,zancun2,12,zancun3,4); break;

case 14://进入修改闹钟的开关

dis_san(zancun1/10,zancun1,zancun2/10,zancun2,12,zancun3,6); break; case 15:

dis_san(zancun1/10,zancun1,zancun2/10,zancun2,zancun3/10,zancun3,1);

break; case 16:

dis_san(zancun1/10,zancun1,zancun2/10,zancun2,zancun3/10,zancun3,2);

break; case 17:

dis_san(zancun1/10,zancun1,zancun2/10,zancun2,zancun3/10,zancun3,3);

break; case 18:

dis_san(zancun1/10,zancun1,zancun2/10,zancun2,zancun3/10,zancun3,4);

break; case 19:

dis_san(zancun1/10,zancun1,zancun2/10,zancun2,zancun3/10,zancun3,5);

break; case 20:

dis_san(zancun1/10,zancun1,zancun2/10,zancun2,zancun3/10,zancun3,6);

break; case 21:

if(second_flag==1) {

second_flag=0;

countdown_second--;

if(countdown_second==255) {

countdown_second=59; countdown_minute--;

if(countdown_minute==255) {

countdown_minute=59; countdown_hour--;

if(countdown_hour==255) {

flag1=22;

countdown_minute=0; countdown_hour=0; countdown_second=0; countdown_flag=1;

联系客服:779662525#qq.com(#替换为@)