我的51单片机无法进入串口中断服务程序内,

说明:串口的配置应该没有问题,因为我在轮训模式下(即轮训RI的状态值)可以正确的接收外部通过串口发送来的数据,而且也可以通过串口向外发送数据;
我用的是c语言写的,中断服务程序如下:
void USART_ISR() interrupt 4
{
//DISABLE(EA);
EA = 0;
if(RI)
{
RI = 0;
USART_Data.Rbuf[USART_Data.RxEp] = SBUF;
USART_Data.RxEp = USART_Data.RxEp + 1;
RecBytes = USART_Data.RxEp;
if(USART_Data.RxEp >= 4)
{
USART_Data.RxEp = 0;
IsRecMsg = 1;
}

}
else if(TI)
{
TI = 0;
}
EA = 1;
}

且串口的中断允许位ES=1;

请各位帮忙分析一下,谢谢
void USART_baudrate(unsigned baudrate)
{
EA = 0;
TI = 0;
TR1 = 0;
ET1 = 0;
PCON |= 0x80;
TMOD &= ~0xf0;
TMOD |= 0x20;
TH1 = BAUD_VALUE_8051(baudrate);
TR1 = 1;
EA = 1;
}
void USART_Init(void)
{
USART_baudrate(9600);
EA = 0;
SM0 = 0;
SM1 = 1;
REN = 1;
TI = 0;
RI = 0;
ES = 1;
PS = 1;
EA = 1;
IE = 0x90;
}

void main()
{
USART_Init();
while(1)
{
IE= 0x90;
CH6_LED = 1;
keyMatrix_Scan();

if(KeyPressed == 1)
{
USART_CreateKeyData();
USART_SendData();
KeyPressed = 0; CH1_LED = 0;
KeyCol = 0;
KeyRow = 0;
}
else if(KeyReleased == 1)
{
//whether button release event is need to be deal with
CH1_LED = 1;

KeyReleased = 0;
}
if(IsRecMsg == 1)
{
USART_RecvDataCheck();
if(RecMsgOk == 1)
{
Proccess_UsartRecvMsg();
USART_ResponseData();
USART_SendData();
}
IsRecMsg = 0;
RecMsgOk = 0;
}
}
}

第1个回答  2011-09-28
中断程序似乎没有问题,不过你的问题 是进不到中断服务程序,所以要找原因还得去主程序找。追问

您好,我已经把主程序及串口初始化程序附上,请再帮忙看看

第2个回答  2011-10-10
IE = 0x90;

把里面的上面那句去掉,就行了。把ES=1,再来一个IE = 0x90;实际上ES=0了本回答被网友采纳
相似回答