51单片机向计算机穿数据!求大神找错
我这段代码计算机接收的总是00,请问这是为什么啊?谢谢啦!!
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar code tab[16] = {
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
void send(uchar dat)
{
SBUF = dat;
while(TI == 0)
;
TI = 0;
}
void delay()
{
uint a = 50000;
while(a--);
}
void main()
{ uchar i = 0;
TMOD = 0x02;
SCON = 0x40;
PCON = 0x00;
TH1=0xfd;
TL1=0xfd;
TR1 = 1;
while(1)
{
for(i = 0;i<16;i++)
{
send(tab[i]);
delay();
}
}
}
[解决办法]
scon=0x50;
tmod=0x20;
th1 =0xfd;
tl1 =0xfd;
tr1 =1;
es =1;
ea =1;