如何改變N76E003的頻率HIRC,以用于更準(zhǔn)確的UART傳輸?
N76E003的HIRC頻率為16 MHz,常溫下偏差在1%以內(nèi)。當(dāng)用于38400以上baud rate的UART傳輸時,會因?yàn)?6 MHz無法除頻出38400 Hz的頻率,造成baud rate偏差過大,無法穩(wěn)定傳輸。
此時用戶可以更改HIRC的頻率到16.588 MHz,就能產(chǎn)生精準(zhǔn)的baud rate。
- 更改HIRC頻率的步驟如下:
1. Trim value = RCTRIM0(HIRCTRIM[8:1]) + RCTRIM1(HIRCTRIM[0])將Trim value–15可以調(diào)整HIRC的頻率為16.6 MHz。
2. 將計(jì)算值寫回RCTRIM0 和RCTRIM1,寫入后HIRC的更改會立即生效。
3. 每次上電后HIRC會恢復(fù)成16 MHz,使用者需要通過寫SFR來更改HIRC。
4. 按照16.588 MHz重新計(jì)算baud rate,再設(shè)定timer產(chǎn)生的baud rate就能符合標(biāo)準(zhǔn)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