51串口中断的问题
刚接触单片机不久,想做一个串口收发的实验,可是 怎么也收不到数据,各位谁帮忙看看这段程序那里有问题呢?
#include<reg52.h>
unsigned char rxbuf[8];
unsigned char tx_count=0,rx_count=0,rx_temp;
void initUart()
{
SCON=0x50;
TMOD=0x20;
PCON=0x80;
TH1=0xf3;
TL1=0xf3;
TR1=1;
ES=1;
EA=1;
}
main()
{
initUart();
while(1)
{
if(rx_count==8)
{
TI=1;
rx_count=0;
}
}
}
void serial() interrupt 4 //串口中断
{
if(TI)
{
if(tx_count < 8)
{
SBUF = rxbuf[tx_count];
tx_count++;
}
if(tx_count>=8)
{
TI = 0;
tx_count=0;
}
}
if(RI)
{
rx_temp=SBUF;
if(rx_count < 8)
{
rxbuf[rx_count]=rx_temp;
rx_count++;
}
RI=0;
}
}