第一次用双UART的单片机,有没有人用过MG82FE216AF的uart1阿,晶振是24M。初始化不太会,我是想设为38400的波特率,主要是有些寄存器的地址共用,还要分页?
以下是初始化代码,工作不正常,不知道设得对不对?
sfr SFRPI = 0xAC;
sfr SCFG = 0x9A;
sfr S1BRT = 0x9A;
#define SCON_PAGE0 0x00
#define SCON_PAGE1 0x01
#define SCFG_PAGE0 0x00
#define S1BRT_PAGE1 0x01
#define SBUF_PAGE1 0x01
void v_uart1_init(void)
{
SFRPI = SCFG_PAGE0; //page0
SCFG = 0x14; //S1TR = 1,S1TX12 = 1
SFRPI = S1BRT_PAGE1;
S1BRT = 0xEC; //256-20
SFRPI = SCON_PAGE1;
SCON = 0x40; //mode 1 8-bit uart
ES = 1;
} |