桂林电子科技大学课程设计(论文)报告用纸 第23页 共 32 页
定时器使能,开始计数 */ if( temp<0x06||temp>0x17) {
TR0 =1; } else
TR0 =0;
break;
case 4:
temp=Read1302(DS1302_WEEK); //读取星期数
temp=((temp&0x70)>>4)*10 + (temp&0x0F); temp=temp+1; //星期数加1
up_flag=1; if(temp>7)
temp=1;
temp=temp/10*16+temp;
break; case 5:
temp=Read1302(DS1302_DAY); //读取日数
temp=((temp&0x70)>>4)*10 + (temp&0x0F); temp=temp+1; //日数加1
up_flag=1; if(temp>31) case 6:
temp=1;
temp=temp/10*16+temp; break;
temp=Read1302(DS1302_MONTH); //读取月数
temp=((temp&0x70)>>4)*10 + (temp&0x0F); temp=temp+1; //月数加1
up_flag=1; if(temp>12)
temp=1;
temp=temp/10*16+temp;
break; case 7:
temp=Read1302(DS1302_YEAR); //读取年数
temp=((temp&0xf0)>>4)*10 + (temp&0x0F); temp=temp+1; //年数加1
up_flag=1; if(temp>99)
temp=0;
temp=temp/10*16+temp; break;
桂林电子科技大学课程设计(论文)报告用纸 第24页 共 32 页
}
default:break;
} // while(Up==0); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////// //************************ //降序按键
//************************ void Downkey() {
Down=1; if(Down==0) {
mdelay(5);
switch(count)
{case 1:
temp=Read1302(DS1302_SECOND); //读取秒数 temp=((temp&0x70)>>4)*10 + (temp&0x0F); temp=temp-1; //秒数减1 down_flag=1; //数据调整后更新标志
if(temp==-1) //小于0秒,返回59秒 temp=59;
temp=temp/10*16+temp; break;
case 2:
temp=Read1302(DS1302_MINUTE); //读取分数
temp=((temp&0x70)>>4)*10 + (temp&0x0F); temp=temp-1; //分数减1
if(temp==-1)
temp=59; //小于0秒,返回59秒 temp=temp/10*16+temp; break;
down_flag=1;
case 3:
temp=Read1302(DS1302_HOUR); //读取小时数
temp=((temp&0x70)>>4)*10 + (temp&0x0F); temp=temp-1; //小时数减1 if(temp==-1) temp=23;
down_flag=1;
temp=temp/10*16+temp;
桂林电子科技大学课程设计(论文)报告用纸 第25页 共 32 页
/*定时器使能,开始计数 定时器使能,开始计数 */ if(temp<0x06||temp>0x17)
{ TR0 =1; }
else
TR0 =0;
break; case 4:
temp=Read1302(DS1302_WEEK); //读取星期数;
temp=((temp&0x70)>>4)*10 + (temp&0x0F); temp=temp-1; //星期数减1
down_flag=1; if(temp==0)
temp=7;
temp=temp/10*16+temp; break;
case 5:
temp=Read1302(DS1302_DAY); //读取日数
temp=((temp&0x70)>>4)*10 + (temp&0x0F); temp=temp-1; //日数减1 down_flag=1; if(temp==0) temp=31;
temp=temp/10*16+temp;
break;
case 6:
temp=Read1302(DS1302_MONTH); //读取月数
temp=((temp&0x70)>>4)*10 + (temp&0x0F); temp=temp-1; //月数减1
down_flag=1; if(temp==0)
temp=12;
temp=temp/10*16+temp; break;
case 7:
temp=Read1302(DS1302_YEAR); //读取年数
temp=((temp&0xf0)>>4)*10 + (temp&0x0F); temp=temp-1; //年数减1
down_flag=1; if(temp==-1)
temp=99;
桂林电子科技大学课程设计(论文)报告用纸 第26页 共 32 页
}
temp=temp/10*16+temp;
break; default:break;
}
// while(Down==0); }
//************************** //模式选择按键
//************************** void Setkey() {
Set=1; if(Set==0)
{
mdelay(5);
count=count+1; //Setkey按一次,count就加1
done=1; }
//进入调整模式
while(Set==0);
}
//************************* //按键功能执行
//*************************
void keydone()
{ uchar Second; /* if(flag==0) //关闭时钟,停止计时 { Write1302(0x8e,0x00); //写入允许
temp=Read1302(0x80);
Write1302(0x80,temp|0x80);
Write1302(0x8e,0x80); //禁止写入 flag=1;
//扫描模式切换按键
//count=1,调整秒
}*/
Setkey();
switch(count) {case 1:do {
outkey();
//扫描跳出按钮
Upkey(); //扫描加按钮
桂林电子科技大学课程设计(论文)报告用纸 第27页 共 32 页
Downkey(); //扫描减按钮
if(up_flag==1||down_flag==1) //数据更新,重新写入新的数据 {
Write1302(0x8e,0x00); //写入允许
Write1302(0x80,temp); //写入新的秒数 Write1302(0x8e,0x80); //禁止写入 up_flag=0;
down_flag=0; }
if(Down!=0&&Up!=0) { hide_sec++;
if(hide_sec>3) hide_sec=0;
} else hide_sec=0; show_time(); //液晶显示数据
}while(count==2);break; case 2:do //count=2,调整分 { hide_sec=0;
outkey(); Upkey();
Downkey(); if(temp>0x60) temp=0;
if(up_flag==1||down_flag==1)
{
Write1302(0x8e,0x00); //写入允许
Write1302(0x82,temp); //写入新的分数 Write1302(0x8e,0x80); //禁止写入 up_flag=0; down_flag=0; }
if(Down!=0&&Up!=0) {
hide_min++;
if(hide_min>3) hide_min=0;
} else hide_min=0;
show_time(); }while(count==3);break; case 3:do //count=3,调整小时