各位大虾,帮忙看一下下面的程序错在哪里?怎么接收数据丢失?
#include <reg52.h> sbit in1 = P0^5; sbit in2 = P0^4; sbit stepcontl = P2^6; sbit out = P2^1; sbit cs = P3^3; sbit inc = P3^4; sbit u = P3^5;
unsigned char test,count,point=0;
unsigned char temp[4]={0}; unsigned char buf[4]={0}; unsigned char flag;
void delay (int timer);
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
{ unsigned char ch;
if (RI) {
RI=0;
ch =SBUF;
if(point==0) { if((ch=='y')|(ch=='m')) point++; else point=0; }
else if((point>0)&(point<4))
buf[point++]=ch;
else point=0;
} }
main()
{ int j,i=0;
com_intilize();
stepcontl = 0;
out=0;
delay(100);
while (1){
if(point==4){
temp[0]=buf[0];
count=temp;
//count=count&0x80; buf[0]=0; if(count==0x88){ cs= 0;
while(count) { temp[1]=buf[1]; buf[1]=0;
temp[2]=buf[2];
buf[2]=0;
temp[3]=buf[3];
buf[3]=0;
test=temp[1];
test=test&0x01;
if(test==0x01){ //正向加
u = 1;
inc =0; for(j=0;j<temp[2];j++) { inc=1;
delay(50);
inc=0; }
delay(1000);
u=0; //要求的零电平 for(i=0;i<32;i++) {
inc=1; delay(50);
inc=0;
} delay(6670);
out=1;
for(j=0;j<(temp[3]);j++)
{ delay(100);
}
out=0;
} else // 正向减 {
u = 0;
inc =0; for(j=0;j<temp[2];j++) { inc=1;
delay(50);
inc=0; }
delay(100); u=0; //要求的零电平 for(i=0;i<32;i++) {
inc=1; delay(50);
inc=0;
}
delay(6670);
out=1;
for(j=0;j<(temp[3]);j++)
{ delay(200);
}
out=0;
}
if(test==0x01){
u = 1;
inc =0;
for(j=0;j<(temp[2]);j++) { inc=1;
delay(50);
inc=0; }
delay(100);
} else {
u = 0;
inc =0;
for(j=0;j<(temp[2]);j++) { inc=1;
delay(50);
inc=0; } }
count=0;
} } } } }
void delay(int timer) { while(--timer); }
|