|
#include
#include
#define uchar unsigned char
uchar data rbuf[5];
uchar data tbuf[5];
uchar rin,rout,tin,tout;
bit rfull,tempty;
void serialInit();
void T0Init();
void delay(int usec);
void sent();
void serial() interrupt 4 using 3
{
if(RI)
{
TI = 0;
rbuf[rin] = SBUF;
rin++;
if(rin>=5)
rfull = 1;
RI = 0;
}
}
void T0INT() interrupt 1 using 1
{
P3_6 = !P3_6;
TH0 = 0x4B;
TL0 = 0xFC;
}
void main()
{
T0Init();
serialInit();
EA = 1;
do
{
/* tbuf[0]=0xFA;
tbuf[1]=0xFB;
tbuf[2]=0xFC;
tbuf[3]=0xFD;
tbuf[4]=0xFE;
tin = 5;
tout = 0;
tempty = 0;*/
sent();
delay(1000);
_nop_();
}while(1);
}
void serialInit()
{
TMOD |= 0x20;
TH1 = 0xFA;
TL1 = 0xFA;
ET1 = 0;
SCON |= 0X50;
TI = 0;
RI = 0;
ES = 1;
TR1 = 1;
}
void T0Init()
{
TMOD |= 0x01;
TH0 = 0x4B;
TL0 = 0xFC;
ET0 = 1;
TR0 = 1;
}
void delay(int usec)
{
while(usec--);
}
void sent()
{
if(!tempty)
{
for(tout=0;tout
{
SBUF = tbuf[tout];
delay(5000);
while(!TI);
TI = 0;
}
if(tout==tin)
{
tempty=1;
tout = tin = 0;
}
}
}
我的代码发送没有问题,可是无法接收,我用keil仿真时发现,能进入串口中断,SBUF中也有数据,可是rbuf[rin] = SBUF;语句似乎没有用,SBUF中的数据怎么也读不到rbuf[rin]里面去,我还试过临时定义一个uchar ch; ch=SBUF;也没有用,SBUF中的数据就是读不出来,请问各位大哥这是怎么回事啊?
|
|