9600波待率,串口2不能进中断,这是为什么,串口2 发送正常。0XAA用串口助手,可以收到。
#include "STC12C5A60S2.h"
sbit LED3 = P3^5;
sbit LED1 = P3^7;
#define S2RI 0x01
void USART2_SEND(char x)
{
unsigned char temp;
S2CON=S2CON&0XFD;
S2BUF=x;
do{
temp=S2CON;
temp=temp&0x02;
} while(temp==0);
S2CON=S2CON&0XFD;
}
void main()
{
unsigned int i;
S2CON=0X50;
BRT=0xfd;
AUXR=0X11;
IE2=1;
EA=1;
LED1=0;
while(1)
{
for(i=0;i<60000;i++);
for(i=0;i<60000;i++);
USART2_SEND(0xaa);
}
}
void USART2() interrupt 8 using 1
{
unsigned char x;
x=S2CON;
if((x&S2RI)==S2RI)
{
x=S2BUF;
USART2_SEND(x);
LED3=!LED3;
S2CON&=~S2RI;
}
}
|