STC12c5a60S2单片机,用串口1下载程序,用串口2通信(p4.2-Rxd, p4.3-Txd),
时间:10-02
整理:3721RD
点击:
但是利用串口助手发送数据时,串口助手接受缓冲区没反应。求大神#include "STC12C5A60S2.H"
#define uchar unsigned char
#define uint unsigned int
uint flag,k;
void uart2_init()
{
AUXR &= 0xF7; //波特率不倍速
S2CON = 0x50; //8位数据,可变波特率
AUXR &= 0xFB; //独立波特率发生器时钟为Fosc/12,即12T
BRT = 0xFD; //设定独立波特率发生器重装值
AUXR |= 0x10; //启动独立波特率发生器
AUXR1|=0Xf0; //S2_P4=1 将uart2切换到p4口
IE2|=0X01;// 允许串口2中断
EA=1;
}
void uart2_receive(void) interrupt 8
{
uchar a;
a=S2CON&0X01; //RI=0;
if(a==1)
{
S2CON&=0xfe;
k=S2BUF;
flag=1;
}
}
void main()
{
uart2_init();
while(1)
{
if(flag==1)
{
IE2=0X00; //Es=0
S2BUF=k;
while(!(S2CON&=0x02));
S2CON&=0xfd;
IE2=0x01;
flag=0;
}
}
}
#define uchar unsigned char
#define uint unsigned int
uint flag,k;
void uart2_init()
{
AUXR &= 0xF7; //波特率不倍速
S2CON = 0x50; //8位数据,可变波特率
AUXR &= 0xFB; //独立波特率发生器时钟为Fosc/12,即12T
BRT = 0xFD; //设定独立波特率发生器重装值
AUXR |= 0x10; //启动独立波特率发生器
AUXR1|=0Xf0; //S2_P4=1 将uart2切换到p4口
IE2|=0X01;// 允许串口2中断
EA=1;
}
void uart2_receive(void) interrupt 8
{
uchar a;
a=S2CON&0X01; //RI=0;
if(a==1)
{
S2CON&=0xfe;
k=S2BUF;
flag=1;
}
}
void main()
{
uart2_init();
while(1)
{
if(flag==1)
{
IE2=0X00; //Es=0
S2BUF=k;
while(!(S2CON&=0x02));
S2CON&=0xfd;
IE2=0x01;
flag=0;
}
}
}