这是我串口2的程序
#define S2RI 0x01
#define S2TI 0x02
#define S2RB8 0x04
#define S2TB8 0x08
#define S2REN 0x10
#define S2SM2 0x20
#define S2SM1 0x40
#define S2SM0 0x80
//初始化
void uart2_init(void) //[email protected]
{
AUXR &= 0xf7; //波特率不倍速
S2CON = 0x50; //8位数据,可变波特率
BRT = 0xDC; //设定独立波特率发生器重装值
AUXR |= 0x04; //独立波特率发生器时钟为Fosc,即1T
AUXR |= 0x10; //启动独立波特率发生器
// AUXR1 &= 0x20; //选择P4口作为串口2
}
//串口2发送程序
uint8 uart2_send_string(uint8 const *dat)
{
uint8 *buf;
buf = dat;
S2CON &= ~S2TI; //发送前清发送中断
while (*buf != '\0')
{
S2BUF = *buf++; //填入发送缓冲区
while (S2CON &= ~S2TI); //等待发送完毕,TI=1 发送成功
S2CON &= ~S2TI; //发送完清发送中断
}
return (buf-dat); //返回发送字节
}