申请最小系板之前,还以为要像51那样配合ds1302才能显示实时时钟,不过看handbook了解到RL78G13自带实时时钟,这样电路就能大大简化。
操作RTC,首先要注意时钟的选择,子系统时钟要注意勾选XT1 oscillation
其次要记得关闭看门狗,不然时钟显示走动4秒又会退回去
接着是对时钟进行初始化操作
记得一开始我的时钟在液晶上一直显示全零,百思不得其解,后来发现是纯软件思维导致的,一开始仅仅定义了一个rtc_counter_value_t * counter_read_val指针变量,并没让它指向任何实体变量,后来改成下面这样问题得到解决
rtc_counter_value_t s;
rtc_counter_value_t * counter_read_val=&s ;
关键代码:
void main(void)
{
/* Start user code. Do not edit comment generated here */
uchar temp;
uchar p,*q;
uchar time[7];
rtc_counter_value_t s;
rtc_counter_value_t * counter_read_val=&s ;
uchar * week[]={"Sun","Mon","Tues","Wed","Thur","Fri","Sat"};
PM1&=0x00;
init_1602();
R_RTC_Start();
while (1U)
{
R_RTC_Get_CounterValue(counter_read_val);
temp=counter_read_val->sec;
temp=temp/16*10+temp%16;
time[0]=temp;
temp=counter_read_val->min;
temp=temp/16*10+temp%16;
time[1]=temp;
temp=counter_read_val->hour;
temp=temp/16*10+temp%16;
time[2]=temp;
temp=counter_read_val->week;
temp=temp/16*10+temp%16;
time[3]=temp;
temp=counter_read_val->day;
temp=temp/16*10+temp%16;
time[4]=temp;
temp=counter_read_val->month;
temp=temp/16*10+temp%16;
time[5]=temp;
temp=counter_read_val->year;
temp=temp/16*10+temp%16;
time[6]=temp;
//////////1602display//////////
write_1602_com(0x80);
write_1602_dat(2+'0');
write_1602_dat(0+'0');
write_1602_dat(time[6]/10+'0');
write_1602_dat(time[6]%10+'0');
write_1602_dat('-');
write_1602_dat(time[5]/10+'0');
write_1602_dat(time[5]%10+'0');
write_1602_dat('-');
write_1602_dat(time[4]/10+'0');
write_1602_dat(time[4]%10+'0');
write_1602_dat(' ');
p=time[3]%10;//纯粹是为了消隐,若简单像时间那样赋值会出现这样的问题,比如由Thur过
q=week[p];//渡到时Fri会不刷新最后一位导致显示Frir
while(*week[p] != '\0')
{
write_1602_dat(*week[p]);
week[p]++;
}
week[p]=q;
write_1602_dat(' ');
write_1602_com(0xc0);
write_1602_dat(time[2]/10+'0');
write_1602_dat(time[2]%10+'0');
write_1602_dat(':');
write_1602_dat(time[1]/10+'0');
write_1602_dat(time[1]%10+'0');
write_1602_dat(':');
write_1602_dat(time[0]/10+'0');
write_1602_dat(time[0]%10+'0');
}
/* End user code. Do not edit comment generated here */
}
图片展示: