如何改变N76E003的频率HIRC,以用于更准确的UART传输?
N76E003的HIRC频率为16 MHz,常温下偏差在1%以内。当用于38400以上baud rate的UART传输时,会因为16 MHz无法除频出38400 Hz的频率,造成baud rate偏差过大,无法稳定传输。
此时用户可以更改HIRC的频率到16.588 MHz,就能产生精准的baud rate。
- 更改HIRC频率的步骤如下:
1. Trim value = RCTRIM0(HIRCTRIM[8:1]) + RCTRIM1(HIRCTRIM[0])将Trim value–15可以调整HIRC的频率为16.6 MHz。
2. 将计算值写回RCTRIM0 和RCTRIM1,写入后HIRC的更改会立即生效。
3. 每次上电后HIRC会恢复成16 MHz,使用者需要通过写SFR来更改HIRC。
4. 按照16.588 MHz重新计算baud rate,再设定timer产生的baud rate就能符合标准baud rate。
- 范例程序如下:
sfr RCTRIM0 = 0x84;
sfr RCTRIM1 = 0x85;
bit BIT_TMP;
#define set_IAPEN BIT_TMP = EA; EA=0; TA=0xAA; TA=0x55; CHPCON |= SET_BIT0; EA= BIT_TMP
#define set_IAPGO BIT_TMP = EA; EA = 0; TA = 0xAA; TA = 0x55; IAPTRG |= SET_BIT0; EA = BIT_TMP
#define clr_IAPEN BIT_TMP = EA; EA = 0; TA = 0xAA; TA = 0x55; CHPCON &= ~SET_BIT0; EA=BIT_TMP
unsigned char hircmap0,hircmap1;
unsigned int trimvalue16bit;
void MODIFY_HIRC_VLAUE(void)
{
set_IAPEN;
IAPAL = 0x30;
IAPAH = 0x00;
IAPCN = READ_UID;
set_IAPGO;
hircmap0 = IAPFD;
IAPAL = 0x31;
IAPAH = 0x00;
set_IAPGO;
hircmap1 = IAPFD;
clr_IAPEN;
trimvalue16bit = ((hircmap0<<1)+(hircmap1&0x01));
trimvalue16bit = trimvalue16bit - 15;
hircmap1 = trimvalue16bit&0x01;
hircmap0 = trimvalue16bit>>1;
TA=0XAA;
TA=0X55;
RCTRIM0 = hircmap0;
TA=0XAA;
TA=0X55;
RCTRIM1 = hircmap1;
编辑:admin 最后修改时间:2018-03-09