/*****************读出年的十进制数***************************/
uchar readyear(void) {
uchar dat;
dat=Read_DS1302(0x8d);
year=((dat&0xf0)>>4)*10+(dat&0x0f); return year; }
void key_scan(void) {
if(key_1==0){ delay_ms(5); if(key_1==0){
while(!key_1); mode_cnt++; key_flag=1;
write_DS1302(0x8E,0x00); write_DS1302(0x80,0x80); write_DS1302(0x8E,0x80); if(mode_cnt==8){ key_flag=0; mode_cnt=0;
write_command(0x0C); write_DS1302(0x8E,0x00); write_DS1302(0x80,0x00);
write_DS1302(0x80,(second/10)<<4|(second)); write_DS1302(0x82,(minute/10)<<4|(minute)); write_DS1302(0x84,(hour/10)<<4|(hour)); write_DS1302(0x86,(day/10)<<4|(day)); write_DS1302(0x88,(month/10)<<4|(month)); write_DS1302(0x8A,(week/10)<<4|(week)); write_DS1302(0x8C,(year/10)<<4|(year)); //write_DS1302(0x80,0x00); write_DS1302(0x8E,0x80);
}
switch(mode_cnt){ case 7:
write_command(third_line+wek_addr_pos); delay_ms(5);
write_command(0x0F); delay_ms(5); break; case 6:
//write_command(second_line+11);
write_command(second_line+sec_addr_pos);//秒 delay_ms(5);
write_command(0x0F); delay_ms(5); break; case 5:
//write_command(second_line+8);
write_command(second_line+min_addr_pos);//分 delay_ms(5);
write_command(0x0F); delay_ms(5); break; case 4:
//write_command(second_line+5);//时
write_command(second_line+hor_addr_pos); delay_ms(5);
write_command(0x0F); delay_ms(5); break; case 3:
write_command(first_line+day_addr_pos); delay_ms(5);
write_command(0x0F); delay_ms(5); break; case 2:
write_command(first_line+mon_addr_pos); delay_ms(5);
write_command(0x0F); delay_ms(5); break; case 1:
write_command(first_line+yer_addr_pos); delay_ms(5);
write_command(0x0F); delay_ms(5); break; } } }
if(key_2==0){
delay_ms(5); if(key_2==0){ while(!key_2);
switch(mode_cnt){ case 6:
second++;
if(second==60){ second=0; }
write_time(sec_addr_pos,second); delay_ms(5);
//write_command(second_line+11);
write_command(second_line+sec_addr_pos); delay_ms(5); break; case 5:
minute++;
if(minute==60){ minute=0; }
write_time(min_addr_pos,minute); delay_ms(5);
//write_command(second_line+8);
write_command(second_line+min_addr_pos); delay_ms(5); break; case 4: hour++;
if(hour==24){ hour=0; }
write_time(hor_addr_pos,hour); delay_ms(5);
{
//write_command(second_line+5);
write_command(second_line+hor_addr_pos); delay_ms(5); break; case 7: week++;
if(week==8){ week=1; }
write_week(week); delay_ms(5);
write_command(third_line+wek_addr_pos); delay_ms(5); break; case 3: day++;
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12) if(day==32){ day=1; //month++; } }
if(month==2){
if((year+2000)%4==0&&((year+2000)0)!=0||(year+2000)@0==0){ if(day>=30){ day=1;
//month++;; } }else{
if(day>=29){ day=1; //month++; } } }
if(month==4||month==6||month==9||month==11){ if(day>=31){ day=1;