新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > ds1302帶鬧鐘功能的單片機控制的時鐘程序

ds1302帶鬧鐘功能的單片機控制的時鐘程序

作者: 時間:2016-11-30 來源:網(wǎng)絡 收藏

if(k4==0)
{
delay(5);
if(k4==0)
{
while(!k4);
num3++;
}
}
if(num3==1)
{
flag1=1;
lcd_com(0x80+1);
lcd_date(0x41);
}
if(num3==2)
{
ajjd=0;
flag1=0;
if(num4==0)
{
for(num0=0;num0<7;num0++)
lcd_time(lcd_date_add[num0],naozhong[num0]);

lcd_com(0x80+1);
lcd_com(0x0c);//關光標
lcd_date(0x42);
}
//lcd_com(0x0f);
flag=1;
if(k1==0)
{
delay(5);
if(k1==0)
{
while(!k1);

num4++;
if(num4==1)
{

lcd_com(0x80+lcd_date_add[0]);
lcd_com(0x0f);//顯示開關及光標設置,開顯示,顯示光標,光標閃爍
}
if(num4==2)
{
lcd_com(0x80+lcd_date_add[1]);
}
if(num4==3)
{
lcd_com(0x80+lcd_date_add[2]);
}
if(num4==4)
{
lcd_com(0x80+lcd_date_add[3]);
}
if(num4==5)
{
lcd_com(0x80+lcd_date_add[4]);
}
if(num4==6)
{
lcd_com(0x80+lcd_date_add[5]);
}
if(num4==7)
{
lcd_com(0x80+lcd_date_add[6]);
}
if(num4==8)
{
lcd_com(0x0c);//關光標
num4=0;
flag=1;
}
}
}
if(num4!=0)
{
if(k2==0)
{
delay(5);
if(k2==0)
{
while(!k2);
if(num4==1)
{
naozhong[0]++;
if(naozhong[0]==60)
naozhong[0]=0;
_nop_();
lcd_time(lcd_date_add[0],naozhong[0]);
lcd_com(0x80+lcd_date_add[0]);

}
if(num4==2)
{
naozhong[1]++;
if(naozhong[1]==60)
naozhong[1]=0;
_nop_();
lcd_time(lcd_date_add[1],naozhong[1]);
lcd_com(0x80+lcd_date_add[1]);

}
if(num4==3)
{
naozhong[2]++;
if(naozhong[2]==24)
naozhong[2]=0;
_nop_();
lcd_time(lcd_date_add[2],naozhong[2]);
lcd_com(0x80+lcd_date_add[2]);

}
if(num4==4)
{
naozhong[3]++;
if(naozhong[3]==32)
naozhong[3]=1;
_nop_();
lcd_time(lcd_date_add[3],naozhong[3]);
lcd_com(0x80+lcd_date_add[3]);

}
if(num4==5)
{
naozhong[4]++;
if(naozhong[4]==13)
naozhong[4]=1;
_nop_();
lcd_time(lcd_date_add[4],naozhong[4]);
lcd_com(0x80+lcd_date_add[4]);

}
if(num4==6)
{
naozhong[5]++;
if(naozhong[5]==8)
naozhong[5]=1;
_nop_();
lcd_time(lcd_date_add[5],naozhong[5]);
lcd_com(0x80+lcd_date_add[5]);

}
if(num4==7)
{
naozhong[6]++;
if(naozhong[6]==99)
naozhong[6]=1;
_nop_();
lcd_time(lcd_date_add[6],naozhong[6]);
lcd_com(0x80+lcd_date_add[6]);

}
}
}
if(k3==0)
{
delay(5);
if(k3==0)
{
while(!k3);
if(num4==1)
{
naozhong[0]--;
if(naozhong[0]==-1)
naozhong[0]=59;
_nop_();
lcd_time(lcd_date_add[2],naozhong[0]);
lcd_com(0x80+lcd_date_add[0]);

}
if(num4==2)
{
naozhong[1]--;
if(naozhong[1]==-1)
naozhong[1]=59;
_nop_();
lcd_time(lcd_date_add[1],naozhong[1]);
lcd_com(0x80+lcd_date_add[1]);

}
if(num4==3)
{
naozhong[2]--;
if(naozhong[2]==-1)
naozhong[2]=23;
_nop_();
lcd_time(lcd_date_add[2],naozhong[2]);
lcd_com(0x80+lcd_date_add[2]);

}
if(num4==4)
{
naozhong[3]--;
if(naozhong[3]==0)
naozhong[3]=31;
_nop_();
lcd_time(lcd_date_add[3],naozhong[3]);
lcd_com(0x80+lcd_date_add[3]);

}
if(num4==5)
{
naozhong[4]--;
if(naozhong[4]==0)
naozhong[4]=12;
_nop_();
lcd_time(lcd_date_add[4],naozhong[4]);
lcd_com(0x80+lcd_date_add[4]);

}
if(num4==6)
{
naozhong[5]--;
if(naozhong[5]==0)
naozhong[5]=7;
_nop_();
lcd_time(lcd_date_add[5],naozhong[5]);
lcd_com(0x80+lcd_date_add[5]);

}
if(num4==7)
{
naozhong[6]--;
if(naozhong[6]==0)
naozhong[6]=99;
_nop_();
lcd_time(lcd_date_add[6],naozhong[6]);
lcd_com(0x80+lcd_date_add[6]);

}
}
}
}
}
if(num3==3)
{
flag=0;
flag1=0;
lcd_com(0x80+1);
lcd_date(20);//讓lcd什么都不顯示
num3=0;
num4=0;

}

}

void write_ds1302(ucharadd,uchar date)
{
uchar i,temp;
rst=0;
clk=0;
_nop_();
rst=1;
for(i=0;i<8;i++)
{
clk=0;
temp=add;
io=temp&0x01;
add>>=1;
clk=1;
_nop_();
}
for(i=0;i<8;i++)
{
clk=0;
temp=date;
io=temp&0x01;
date>>=1;
clk=1;
_nop_();
}
rst=0;
}
uchar read_ds1302(uchar add)
{
uchar i,temp,data1,j;
rst=0;
clk=0;
_nop_();;
rst=1;
for(i=0;i<8;i++)
{
clk=0;
temp=add;
io=temp&0x01;
add>>=1;
clk=1;
_nop_();
}
for(i=0;i<8;i++)
{
data1>>=1;
clk=0;
if(io)
data1=data1|0x80;
clk=1;
}
rst=0;
_nop_();
j=data1%16;
data1=data1/16;
data1=data1*10+j;
return(data1);
}
void set_ds1302(uchar add,uchar time)
{
uchar j;
write_ds1302(0x8e,0x00);
j=time/10;
time=time%10;
time=time+j*16;
write_ds1302(add,time);
write_ds1302(0x8e,0x80);
}
void read_rtc()
{
uchar i;
for(i=0;i<7;i++)
{
date[i]=read_ds1302(date_read_add[i]);
}
}
void display()
{
uchar i;
for(i=0;i<7;i++)
{
lcd_time(lcd_date_add[i],date[i]);
}
}
void naozhongscan()
{
uchar i=0;
uchar j=0;
while((j==0)&&(i<7))
{
j=naozhong[i]^date[i];
i++;
}
if(i==7)
didi();
}

本文引用地址:http://m.butianyuan.cn/article/201611/323803.htm

上一頁 1 2 下一頁

評論


技術專區(qū)

關閉