本帖最后由 laorenshen 于 2010-11-13 20:03 编辑
我用timer4 做,不知道哪里的问题,请高手指点
void EUART0_ISP(void) interrupt 4
{
EA = 0;
//UartInterface();
EA = 1;
}
void Init_Timer4(void)
{
T4CON = Bin(00000110);
//RCAP4L = LOBYTE(UART_BAUDRATE);
TL4 = LOBYTE(UART_BAUDRATE);
//RCAP4H = HIBYTE(UART_BAUDRATE);
TH4 = HIBYTE(UART_BAUDRATE);
TF4 = 0; // 清定时器0溢出标志
TR4 = 1; // 开启定时器0
IEN0 = Bin(00110000); //timer2 and EUART
IEN1 = Bin(00000000);
}
void EUART_Init(void)
{
P2CR = Bin(00000010); //用于com
P2PCR = Bin(00000001);
P2 = Bin(00000011);
SCON = Bin(01010000);
REN = 1;
RI=0; //允许接收
}
#define FSYSCLK 12000000
#define UART_BAUDRATE_600 (65536-FSYSCLK/32/600)
#define UART_BAUDRATE_1200 (65536-FSYSCLK/32/1200)
#define UART_BAUDRATE_2400 (65536-FSYSCLK/32/2400)
#define UART_BAUDRATE_4800 (65536-FSYSCLK/32/4800)
#define UART_BAUDRATE_9600 (65536-FSYSCLK/32/9600)
#define UART_BAUDRATE UART_BAUDRATE_600 //Uart波特率为600bps
} |