📄 timeshow.c
字号:
up_flag=1;
if(temp>0x23) //超过23小时,清零
temp=0;
break;
case 4:
temp=Read1302(DS1302_DAY); //读取日数
temp=temp+1; //日数加1
up_flag=1;
if(temp>0x31)
temp=1;
break;
case 5:
temp=Read1302(DS1302_MONTH); //读取月数
temp=temp+1; //月数加1
up_flag=1;
if(temp>0x12)
temp=1;
break;
case 6:
temp=Read1302(DS1302_YEAR); //读取年数
temp=temp+1; //年数加1
up_flag=1;
if(temp>0x85)
temp=0;
break;
case 7:
temp=latitude_integer;
temp=temp+1;
latitude_integer=temp;
up_flag=1;
if(temp>0x90)
temp=0;
break;
case 8:temp=latitude_frag;
temp=temp+1;
latitude_frag=temp;
up_flag=1;
if(temp>0x90)
temp=0;
break;
case 9:
temp=longitude_integer;
temp=temp+1;
longitude_integer=temp;
up_flag=1;
if(temp>0x180)
temp=0;
break;
case 10:temp=longitude_frag;
temp=temp+1;
longitude_frag=temp;
up_flag=1;
if(temp>0x99)
temp=0;
break;
default:break;
}
while((GP4DAT>>Up)&0x01==0);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Downkey()//降序按键
{ int i;
// Down=1;
GP4DAT=0xdd000000;
Delayms(20);
i=(GP4DAT>>Down)&0x01;
if(i==0)
{
mdelay(8000);
switch(count)
{case 1:
temp=Read1302(DS1302_SECOND); //读取秒数
temp=temp-1; //秒数减1
down_flag=1; //数据调整后更新标志
if(temp==0x7f) //小于0秒,返回59秒
temp=0x59;
break;
case 2:
temp=Read1302(DS1302_MINUTE); //读取分数
temp=temp-1; //分数减1
down_flag=1;
if(temp==-1)
temp=0x59; //小于0秒,返回59秒
break;
case 3:
temp=Read1302(DS1302_HOUR); //读取小时数
temp=temp-1; //小时数减1
down_flag=1;
if(temp==-1)
temp=0x23;
break;
case 4:
temp=Read1302(DS1302_DAY); //读取日数
temp=temp-1; //日数减1
down_flag=1;
if(temp==0)
temp=31;
break;
case 5:
temp=Read1302(DS1302_MONTH); //读取月数
temp=temp-1; //月数减1
down_flag=1;
if(temp==0)
temp=12;
break;
case 6:
temp=Read1302(DS1302_YEAR); //读取年数
temp=temp-1; //年数减1
down_flag=1;
if(temp==-1)
temp=0x85;
break;
case 7:
temp=latitude_integer;
temp=temp-1;
latitude_integer=temp;
up_flag=1;
if(temp==-1)
temp=0x90;
break;
case 8:temp=latitude_frag;
temp=temp-1;
latitude_frag=temp;
up_flag=1;
if(temp==-1)
temp=0x90;
break;
case 9:
temp=longitude_integer;
temp=temp-1;
longitude_integer=temp;
up_flag=1;
if(temp==-1)
temp=0x180;
break;
case 10:
temp=longitude_frag;
temp=temp-1;
longitude_frag=temp;
up_flag=1;
if(temp==-1)
temp=0x00;
break;
default:break;
}
while((GP4DAT>>Down)&0x01==0);
}
}
void Setkey()//模式选择按键
{ int i ;
// int Second;
// Set=1;
GP4DAT=0xf5000000;
Delayms(20);
i= (GP4DAT>>Set)&0x00000001;
if(i==0)
{
mdelay(8000);
count=count+1; //Setkey按一次,count就加1
done=1; //进入调整模式
while(i!=0);
GP4DAT=0xff000000;
}
}
void keydone()//按键功能执行
{ uint8 Second;
if(flag==0) //关闭时钟,停止计时
{ Write1302(0x8e,0x00); //写入允许
temp=Read1302(0x80);
Write1302(0x80,temp|0x80);
Write1302(0x8e,0x80); //禁止写入
flag=1;
}
Setkey(); //扫描模式切换按键
Delayms(20);
switch(count)
{case 1:do //count=1,调整秒
{
outkey(); //扫描跳出按钮
Upkey(); //扫描加按钮
Downkey(); //扫描减按钮
if(up_flag==1||down_flag==1) //数据更新,重新写入新的数据
{
Write1302(0x8e,0x00); //写入允许
Write1302(0x80,temp|0x80); //写入新的秒数
Write1302(0x8e,0x80); //禁止写入
up_flag=0;
down_flag=0;
}
hide_sec++; //位闪计数
if(hide_sec>3)
hide_sec=0;
show_time(); //液晶显示数据
}while(count==2);
// hide_sec=0;
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;
}
hide_min++;
if(hide_min>3)
hide_min=0;
show_time();
}
while(count==3);
// hide_min=0;
break;
case 3:do //count=3,调整小时
{
hide_min=0;
outkey();
Upkey();
Downkey();
if(up_flag==1||down_flag==1)
{
Write1302(0x8e,0x00); //写入允许
Write1302(0x84,temp); //写入新的小时数
Write1302(0x8e,0x80); //禁止写入
up_flag=0;
down_flag=0;
}
hide_hour++;
if(hide_hour>3)
hide_hour=0;
show_time();
}
while(count==4);
// hide_hour=0;
break;
case 4:do //count=4,调整星期
{
hide_hour=0;
outkey();
Upkey();
Downkey();
if(up_flag==1||down_flag==1)
{
Write1302(0x8e,0x00); //写入允许
Write1302(0x86,temp); //写入新的日数
Write1302(0x8e,0x80); //禁止写入
up_flag=0;
down_flag=0;
}
hide_day++;
if(hide_day>3)
hide_day=0;
show_time();
}
while(count==5);
// hide_day=0;
break;
case 5:do //count=6,调整月
{
hide_day=0;
outkey();
Upkey();
Downkey();
if(up_flag==1||down_flag==1)
{
Write1302(0x8e,0x00); //写入允许
Write1302(0x88,temp); //写入新的月数
Write1302(0x8e,0x80); //禁止写入
up_flag=0;
down_flag=0;
}
hide_month++;
if(hide_month>3)
hide_month=0;
show_time();
}
while(count==6);
// hide_month=0;
break;
case 6:do //count=7,调整年
{
hide_month=0;
outkey();
Upkey();
Downkey();
if(up_flag==1||down_flag==1)
{
Write1302(0x8e,0x00); //写入允许
Write1302(0x8c,temp); //写入新的年数
Write1302(0x8e,0x80); //禁止写入
up_flag=0;
down_flag=0;
}
hide_year++;
if(hide_year>3)
hide_year=0;
show_time();
}while(count==7);
//hide_year=0;
break;
case 7:do //count=1,调整秒
{
outkey(); //扫描跳出按钮
Upkey(); //扫描加按钮
Downkey(); //扫描减按钮
if(up_flag==1||down_flag==1) //数据更新,重新写入新的数据
{
latitude_integer=temp;
up_flag=0;
down_flag=0;
}
hide_latitude_integer++; //位闪计数
if(hide_latitude_integer>3)
hide_latitude_integer=0;
show_time(); //液晶显示数据
}while(count==8);
// hide_latitude_integer=0;
break;
case 8:do //count=1,调整秒
{
outkey(); //扫描跳出按钮
Upkey(); //扫描加按钮
Downkey(); //扫描减按钮
if(up_flag==1||down_flag==1) //数据更新,重新写入新的数据
{
latitude_frag=temp;
up_flag=0;
down_flag=0;
}
hide_latitude_frag++; //位闪计数
if(hide_latitude_frag>3)
hide_latitude_frag=0;
show_time(); //液晶显示数据
}while(count==9);
// hide_latitude_frag=0;
break;
case 9:do //count=1,调整秒
{
outkey(); //扫描跳出按钮
Upkey(); //扫描加按钮
Downkey(); //扫描减按钮
if(up_flag==1||down_flag==1) //数据更新,重新写入新的数据
{
longitude_integer=temp;
up_flag=0;
down_flag=0;
}
hide_longitude_integer++; //位闪计数
if(hide_longitude_integer>3)
hide_longitude_integer=0;
show_time(); //液晶显示数据
}while(count==10);
// hide_longitude_integer=0;
break;
case 10:do //count=1,调整秒
{
outkey(); //扫描跳出按钮
Upkey(); //扫描加按钮
Downkey(); //扫描减按钮
if(up_flag==1||down_flag==1) //数据更新,重新写入新的数据
{
longitude_frag=temp;
up_flag=0;
down_flag=0;
}
hide_longitude_frag++; //位闪计数
if(hide_longitude_frag>3)
hide_longitude_frag=0;
show_time(); //液晶显示数据
}
while(count==11);
// hide_longitude_frag=0;
break;
case 11: count=0;hide_year=0; //count8, 跳出调整模式,返回默认显示状态
Second=Read1302(DS1302_SECOND);
Write1302(0x8e,0x00); //写入允许
Write1302(0x80,Second&0x7f);
Write1302(0x8E,0x80); //禁止写入
done=0;break; //count=7,开启中断,标志位置0并退出
default:break;
}
}
void show_time() //液晶显示程序
{
DS1302_GetTime(&CurrentTime); //获取时钟芯片的时间数据
TimeToStr(&CurrentTime); //时间数据转换液晶字符
DateToStr(&CurrentTime); //日期数据转换液晶字符
longitudeTostr();
latitudeTostr();
LCD_WriteCommand(0x80,1);
LCD_PrintString(CurrentTime.TimeString); //显示时间
LCD_WriteCommand(0xC0,1);
LCD_PrintString(CurrentTime.DateString); //显示日期
LCD_WriteCommand(0x80|0x09,1);
LCD_PrintString("W");
LCD_WriteCommand(0x80|0x0A,1);
LCD_PrintString(latitude);
LCD_WriteCommand(0xC0|0x09,1);
LCD_PrintString("J");
LCD_WriteCommand(0xC0|0x0A,1);
LCD_PrintString(longitude);
Delay1ms(400); //扫描延时
}
main()
{
GP0DAT=0xff000000;
GP1DAT=0xff000000;
GP2DAT=0xff000000;
GP3DAT=0xff000000;
GP4DAT=0xff000000;
GP4CLR=0x00ff0000;
flag=1; //时钟停止标志
LCD_Init(); //液晶初始化
Initial_DS1302(); //时钟芯片初始化
up_flag=0;
down_flag=0;
done=0; //进入默认液晶显示
while(1)
{
while(done==1)
keydone(); //进入调整模式
while(done==0)
{
show_time(); //液晶显示数据
flag=0;
Setkey(); //扫描各功能键
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -