21ic问答首页 - 关于芯圣HC89F3XX1使用8M晶振误差问题
关于芯圣HC89F3XX1使用8M晶振误差问题
Wbhdpj2022-10-30
最近在使用HC89F3541的外部时钟,晶振使用8M 规格书误差为20PPM,实测29小时误差约为0.015%。麻烦各位大佬看看,那里能改进。 下面为初始化配置:
(IO口初始化略....)
WDTC|=0x10;
CLKCON |= 0x04; // 外部晶振打开
XTALCFG |= 0x01; // 选择外部高频晶振
CLKOUT = 0x03;// 选择外部时钟xtal_clk 输出位
CLKSWR = 0xf0; // 选择外部高频RC为系统时钟
CLKDIV = 0x01; // 1分频
// Time0配置
TCON = 0;
TCON1 = 0x01;
TMOD = 0x00;
TH0 = 0xFC; // 125us
TL0 = 0x18;
ET0 = 1;
TR0 = 1;
void TIMER0_Rpt(void) interrupt TIMER0_VECTOR
{
if(++R_u8add10ms>=80) // 10ms
{
R_u8add10ms=0;
if(++R_u8Input_1s>=100)
{
R_u8Input_1s=0;
if(++R_BeijingTimeS>=60)
{
R_BeijingTimeS=0;
R_BeijingTimeM++;
if(R_BeijingTimeM>=60)
{
R_BeijingTimeM=0;
R_BeijingTimeH++;
if(R_BeijingTimeH>=24)
{
R_BeijingTimeH=0;
R_BeijingWeek++;
if(R_BeijingWeek>7)
{
R_BeijingWeek=1;
}
}
}
}
}
}
}
(IO口初始化略....)
WDTC|=0x10;
CLKCON |= 0x04; // 外部晶振打开
XTALCFG |= 0x01; // 选择外部高频晶振
CLKOUT = 0x03;// 选择外部时钟xtal_clk 输出位
CLKSWR = 0xf0; // 选择外部高频RC为系统时钟
CLKDIV = 0x01; // 1分频
// Time0配置
TCON = 0;
TCON1 = 0x01;
TMOD = 0x00;
TH0 = 0xFC; // 125us
TL0 = 0x18;
ET0 = 1;
TR0 = 1;
void TIMER0_Rpt(void) interrupt TIMER0_VECTOR
{
if(++R_u8add10ms>=80) // 10ms
{
R_u8add10ms=0;
if(++R_u8Input_1s>=100)
{
R_u8Input_1s=0;
if(++R_BeijingTimeS>=60)
{
R_BeijingTimeS=0;
R_BeijingTimeM++;
if(R_BeijingTimeM>=60)
{
R_BeijingTimeM=0;
R_BeijingTimeH++;
if(R_BeijingTimeH>=24)
{
R_BeijingTimeH=0;
R_BeijingWeek++;
if(R_BeijingWeek>7)
{
R_BeijingWeek=1;
}
}
}
}
}
}
}
赞0
评论
2022-10-31
赞0
评论
2022-10-31
您需要登录后才可以回复 登录 | 注册