高中生
最后登录1970-1-1
在线时间 小时
注册时间2015-1-3
|
想更改时间,首先读取RTC目前值,然后关闭RTC中断,通过触屏进行设置,设置好后,打开RTC中断,设置值写入RTC寄存器,以上流程没有问题吧?
程序如下:
if(even==E_SETTIME)
{
tm = &systmtime;
nian=tm->tm_year;
yue=tm->tm_mon;
ri=tm->tm_mday;
shi=tm->tm_hour;
fen=tm->tm_min;
miao=tm->tm_sec;
even = E_NULL;
while(even !=E_SETTIME)
{
RTC_ITConfig(RTC_IT_SEC, DISABLE);
if(even==E_RIGHT)
{
wei=wei+1;
if(wei>5)
wei=0;
even = E_NULL;
}
else if(even==E_LEFT)
{
wei=wei-1;
if(wei<0)
wei=5;
even = E_NULL;
}
switch(wei)
{
case 0:
if(even==E_UP)
{
nian++;
even = E_NULL;
}
else if(even==E_DOWN)
{
nian--;
even = E_NULL;
}
LCD_ShowNum_8x16(158,304,nian,4,WHITE,RED);
LCD_ShowNum_8x16(198,304,yue,2,WHITE,BLACK);
LCD_ShowNum_8x16(222,304,ri,2,WHITE,BLACK);
LCD_ShowNum_8x16(166,288,shi,2,WHITE,BLACK);
LCD_ShowNum_8x16(190,288,fen,2,WHITE,BLACK);
LCD_ShowNum_8x16(214,288,miao,2,WHITE,BLACK);
break;
case 1:
if(even==E_UP)
{
yue++;
even = E_NULL;
}
else if(even==E_DOWN)
{
yue--;
even = E_NULL;
}
LCD_ShowNum_8x16(158,304,nian,4,WHITE,BLACK);
LCD_ShowNum_8x16(198,304,yue,2,WHITE,RED);
LCD_ShowNum_8x16(222,304,ri,2,WHITE,BLACK);
LCD_ShowNum_8x16(166,288,shi,2,WHITE,BLACK);
LCD_ShowNum_8x16(190,288,fen,2,WHITE,BLACK);
LCD_ShowNum_8x16(214,288,miao,2,WHITE,BLACK);
break;
case 2:
if(even==E_UP)
{
ri++;
even = E_NULL;
}
else if(even==E_DOWN)
{
ri--;
even = E_NULL;
}
LCD_ShowNum_8x16(158,304,nian,4,WHITE,BLACK);
LCD_ShowNum_8x16(198,304,yue,2,WHITE,BLACK);
LCD_ShowNum_8x16(222,304,ri,2,WHITE,RED);
LCD_ShowNum_8x16(166,288,shi,2,WHITE,BLACK);
LCD_ShowNum_8x16(190,288,fen,2,WHITE,BLACK);
LCD_ShowNum_8x16(214,288,miao,2,WHITE,BLACK);
break;
case 3:
if(even==E_UP)
{
shi++;
even = E_NULL;
}
else if(even==E_DOWN)
{
shi--;
even = E_NULL;
}
LCD_ShowNum_8x16(158,304,nian,4,WHITE,BLACK);
LCD_ShowNum_8x16(198,304,yue,2,WHITE,BLACK);
LCD_ShowNum_8x16(222,304,ri,2,WHITE,BLACK);
LCD_ShowNum_8x16(166,288,shi,2,WHITE,RED);
LCD_ShowNum_8x16(190,288,fen,2,WHITE,BLACK);
LCD_ShowNum_8x16(214,288,miao,2,WHITE,BLACK);
break;
case 4:
if(even==E_UP)
{
fen++;
even = E_NULL;
}
else if(even==E_DOWN)
{
fen--;
even = E_NULL;
}
LCD_ShowNum_8x16(158,304,nian,4,WHITE,BLACK);
LCD_ShowNum_8x16(198,304,yue,2,WHITE,BLACK);
LCD_ShowNum_8x16(222,304,ri,2,WHITE,BLACK);
LCD_ShowNum_8x16(166,288,shi,2,WHITE,BLACK);
LCD_ShowNum_8x16(190,288,fen,2,WHITE,RED);
LCD_ShowNum_8x16(214,288,miao,2,WHITE,BLACK);
break;
case 5:
if(even==E_UP)
{
miao++;
even = E_NULL;
}
else if(even==E_DOWN)
{
miao--;
even = E_NULL;
}
LCD_ShowNum_8x16(158,304,nian,4,WHITE,BLACK);
LCD_ShowNum_8x16(198,304,yue,2,WHITE,BLACK);
LCD_ShowNum_8x16(222,304,ri,2,WHITE,BLACK);
LCD_ShowNum_8x16(166,288,shi,2,WHITE,BLACK);
LCD_ShowNum_8x16(190,288,fen,2,WHITE,BLACK);
LCD_ShowNum_8x16(214,288,miao,2,WHITE,RED);
break;
default :break;
}
LCD_DisNum(158,250,nian,WHITE,RED);
printf("\n\r DAY: %d\n\r", yue);
RTC_ITConfig(RTC_IT_SEC, ENABLE);
tm->tm_year= nian;
tm->tm_mon= yue;
tm->tm_mday= ri;
tm->tm_hour= shi;
tm->tm_min= fen;
tm->tm_sec= miao;
RTC_WaitForLastTask(); //等待RTC完成当前任务,增减无影响
GregorianDay(tm); //计算公历,增减无影响
RTC_SetCounter(mktimev(tm)); //计算时间戳,写入寄存器,加上此段代码后,时间日期并不能写入,且带来无法退出设置的问题。
RTC_WaitForLastTask(); //增减无影响
}
even = E_NULL;
}
请注意看后面4行有注释的地方。
说明:触屏触发"设置"后,通过上下左右进行选择和增减时间,再次触摸“设置”后退出设置,写入时间。目前增加写入寄存器时间代码前,显示,数据增减,进入退出设置都正确,但增加写入寄存器时间后,无法写入时间,且无法选择、增减、退出等动作。请大家指点迷津。
谢谢!
|
|