write_com(0x80+0x04);
write_com(0x0f);
}
if(func_num==7)
{
write_com(0x80+0x01);
write_com(0x0f);
}
//判断增加键是否按下
if(add==0&&func_num!=0)
{
delaynus(50);
if(add==0&&func_num!=0)
{
while(!add);
if(add==0&&func_num!=0)
{
WriteSet1302(0x81,0x80);//时钟暂停
if(func_num==1)
{
ReadValue = ReadSet1302(0x81); //从秒寄存器读数据
second=((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);//将读出数据转化
delaynus(10);
second++;
if(second==60)
second=0;
delaynus(10);
write_sfm(10,second);
write_com(0x80+0x40+10);
}
if(func_num==2)
{
ReadValue = ReadSet1302(0x83); //从分寄存器读
minute=((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F); //将读出数据转化
delaynus(10);
minute++;
if(minute==60)
minute=0;
delaynus(10);
write_sfm(7,minute);
write_com(0x80+0x40+7);
}
if(func_num==3)
{
ReadValue = ReadSet1302(0x85); //从时寄存器读
hour=((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F); //将读出数据转化
delaynus(10);
hour++;
if(hour==24)
hour=0;
delaynus(10);
write_sfm(4,hour);
write_com(0x80+0x40+4);
}
/*if(func_num==4)
{
week++;
if(week==7)
week=0;
Display_week(week);
write_com(0x80+0x0a);
}
if(func_num==5)
{
day++;
if(day==31)
day=0;
write_sfm_nyrw(0x07,day);
write_com(0x80+0x07);
}
if(func_num==6)
{
month++;
if(month==12)
month=0;
write_sfm_nyrw(4,month);
write_com(0x80+0x04);
}
if(func_num==7)
{
year++;
if(year==99)
year=0;
write_sfm_nyrw(1,month);
write_com(0x80+0x01);
} */
}
}
}
if(func_num==8)
{
func_num=0;
write_com(0x0c);
WriteSet1302(0x81,0x00);//时钟开启
Set_DS1302(second,minute,hour,day,month,year,week);
write_sfm(10,second); //显示秒
write_sfm(7,minute); //显示分
write_sfm(4,hour); //显示小时
write_sfm_nyrw(0x07,day); //显示日
write_sfm_nyrw(0x04,month); //显示月
write_sfm_nyrw(1,year); //显示年
Display_week(week);
flag=0;
}
}
}
}
/*void keyscan(void )
{
uchar func_num=0;
P3=0xff;
//功能选择键,按下键时,所选位置光标闪烁
if(function==0)
{
delaynus(20);
if(function==0)
{
while(!function);
WriteSet1302(0x81,0x80);//时钟暂停
func_num++;
flag=1;
if(func_num==1)
{
write_com(0x80+0x40+10);
write_com(0x0f);
}
if(func_num==2)
{
write_com(0x80+0x40+7);
write_com(0x0f);
}
if(func_num==3)
{
write_com(0x80+0x40+4);
write_com(0x0f);
}
if(func_num==4)
{
write_com(0x80+0x07);
write_com(0x0f);
}
if(func_num==5)
{
write_com(0x80+0x04);
write_com(0x0f);
}
if(func_num==6)
{
write_com(0x80+0x04);
write_com(0x0f);
}
if(func_num==7)
{
write_com(0x80+0x04);
write_com(0x0f);
}
if(func_num==8)
{
func_num=0;
flag=0;
write_com(0x0c);
WriteSet1302(0x81,0x00);//时钟开启
ReadValue = ReadSet1302(0x81); //从秒寄存器读数据
second=((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);//将读出数据转化
ReadValue = ReadSet1302(0x83); //从分寄存器读
minute=((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F); //将读出数据转化
ReadValue = ReadSet1302(0x85); //从时寄存器读
hour=((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F); //将读出数据转化
ReadValue = ReadSet1302(0x87); //从日寄存器读
day=((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F); //将读出数据转化
ReadValue = ReadSet1302(0x89); //从月寄存器读
month=((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F); //将读出数据转化
ReadValue = ReadSet1302(0x8D); //从年寄存器读
year=((ReadValue&0xf0)>>4)*10 + (ReadValue&0x0F); //将读出数据转化
ReadValue= ReadSet1302(0x8b); //从星期寄存器读
week=((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);
Set_DS1302(second,minute,hour,day,month,year,week);
write_sfm(10,second); //显示秒
write_sfm(7,minute); //显示分
write_sfm(4,hour); //显示小时
write_sfm_nyrw(0x07,day); //显示日
write_sfm_nyrw(0x04,month); //显示月
write_sfm_nyrw(1,year); //显示年
Display_week(week);
}
}
//判断增加键是否按下(判断增加的这部分没反应)
if(func_num!=0)
{
if(add==0)
{
delay(10);
if(add==0)
{
while(!add);
if(func_num==1)
{
second++;
if(second==60)
second=0;
write_sfm(10,second);
}
if(func_num==2)
{
minute++;
if(minute==60)
minute=0;
write_sfm(7,minute);
}
if(func_num==3)
{
hour++;
if(hour==24)
hour=0;
write_sfm(4,hour);
}
if(func_num==4)
{
day++;
if(day==31)
day=0;
write_sfm_nyrw(0x07,day);
}
if(func_num==5)
{
month++;
if(month==31)
month=0;
write_sfm_nyrw(0x04,month);
}
if(func_num==6)
{
year++;
if(year==99)
year=0;
write_sfm_nyrw(1,year);
}
if(func_num==7)
{
week++;
if(week==7)
week=0;
Display_week(week);
}
}
}
}
}
}
*/
/*****************************************************
函数功能:主函数
***************************************************/
void main(void)
{
init(); //将液晶初始化
Set_DS1302(56,59,23,27,3,11,7);
while(1)
{
keyscan();
if(flag==0)
{
ReadValue = ReadSet1302(0x81); //从秒寄存器读数据
second=((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);//将读出数据转化
write_sfm(10,second); //显示秒
ReadValue = ReadSet1302(0x83); //从分寄存器读
minute=((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F); //将读出数据转化
write_sfm(7,minute); //显示分
ReadValue = ReadSet1302(0x85); //从时寄存器读
hour=((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F); //将读出数据转化
write_sfm(4,hour); //显示小时
ReadValue = ReadSet1302(0x87); //从日寄存器读
day=((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F); //将读出数据转化
write_sfm_nyrw(0x07,day); //显示日
ReadValue = ReadSet1302(0x89); //从月寄存器读
month=((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F); //将读出数据转化
write_sfm_nyrw(0x04,month); //显示月
ReadValue = ReadSet1302(0x8D); //从年寄存器读
year=((ReadValue&0xf0)>>4)*10 + (ReadValue&0x0F); //将读出数据转化
write_sfm_nyrw(1,year); //显示年
ReadValue= ReadSet1302(0x8b); //从星期寄存器读
week=((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);
Display_week(week);
}
}
} |