#include <reg51.h>
sbit out = P2^2;
int i=0;
unsigned char buf[3] = {0}; unsigned char temp[3] = {0};
void delay (long t);
void com_intilize (void) { SCON=0x50; //方式1 TMOD|=0x20; //TR1启动,方式1 PCON=0; TH1=0xfd; //9600 TR1=1; ES=1; REN=1; EA=1; } void recive (void) interrupt 4 using 3
{ if (RI){ unsigned char mid;
RI=0;
mid = SBUF ;
i++;
buf=mid;
} }
main()
{ int j,i=0;
com_intilize();
while (1){
temp[0] =buf[0];
temp[1] =buf[1];
temp[2] =buf[2];
buf[2]=0;
buf[1]=0;
buf[0]=0;
out=1;
if (temp[0] == 0xff){
out=1; while(temp[1])
{
for (j=0;j<temp[2];j++) { out=0;
delay(10000); out=1;
delay(temp[1]); }
temp[1]=0; } } } }
void delay(long t) { while(t--) ; } 就是接收数据不对,不知那里出了问题,请求高人指点 |