#include<reg52.h>
typedef unsigned int u16;
typedef unsigned char u8;
float a[3];
float w[3];
float angle[3];
u8 chunchu[5];
int shuju[11];
u8 i=0;
u8 pp=0;
int k;
void sheding(void)
{
TMOD = 0x20;
SCON = 0x50;
TH1 = 0xFD;
TL1 = TH1;
PCON = 0x00;
EA = 1;
ES = 1;
TR1 = 1;
}
void chuli(u8 *s,float tpdata)
{
tpdata=tpdata*10;
k=(int)(tpdata);
if(k<0)
{
k=-k;
*s='-';
}
else
{ *s=' ' ; }
*++s=k/1000+0x30;
k=k%1000;
*++s=k/100+0x30;
k=k%100;
*++s=k/10+0x30;
k=k%10;
*++s=k+0x30;
}
void send(u8 c)
{
SBUF = c;
while(!TI);
TI = 0;
}
void fs_shuzu()
{
int i;
for(i=0;i<6;i++)
{
send(chunchu[i]);
}
send(0x0d);
send(0x0a);
}
void main()
{
sheding();
while(1)
{
if(pp==1)
{
pp=0;
if(shuju[0]==0x55)
{
switch(shuju[1])
{
case 0x51:
a[0]=(shuju[3]<<8|shuju[2])/(32768/16);
a[1]=(shuju[5]<<8|shuju[4])/(32768/16);
a[2]=(shuju[7]<<8|shuju[6])/(32768/16);
break;
case 0x52:
w[0]=(shuju[3]<<8|shuju[2])/(32768/2000);
w[1]=(shuju[5]<<8|shuju[4])/(32768/2000);
w[2]=(shuju[7]<<8|shuju[6])/(32768/2000);
break;
case 0x53:
angle[0]=shuju[3]<<8+shuju[2];
angle[1]=(short)(shuju[5]<<8+shuju[4])*180/32768;
angle[2]=(short)(shuju[7]<<8+shuju[6])*180/32768;
send(shuju[3]);
send(shuju[2]);
send(0x0d);
send(0x0a);
break;
}
//chuli(chunchu,angle[0]);
//fs_shuzu();
}
}
}
}
void jieshou(void) interrupt 4
{
while(RI==0);
RI = 0;
shuju[i]=SBUF;
if(i==0&&shuju[0]!=0x55)
{
return;
}
else
{
i=i+1;
}
if(i==11)
{
i=0;
pp=1;
}
}
typedef unsigned int u16;
typedef unsigned char u8;
float a[3];
float w[3];
float angle[3];
u8 chunchu[5];
int shuju[11];
u8 i=0;
u8 pp=0;
int k;
void sheding(void)
{
TMOD = 0x20;
SCON = 0x50;
TH1 = 0xFD;
TL1 = TH1;
PCON = 0x00;
EA = 1;
ES = 1;
TR1 = 1;
}
void chuli(u8 *s,float tpdata)
{
tpdata=tpdata*10;
k=(int)(tpdata);
if(k<0)
{
k=-k;
*s='-';
}
else
{ *s=' ' ; }
*++s=k/1000+0x30;
k=k%1000;
*++s=k/100+0x30;
k=k%100;
*++s=k/10+0x30;
k=k%10;
*++s=k+0x30;
}
void send(u8 c)
{
SBUF = c;
while(!TI);
TI = 0;
}
void fs_shuzu()
{
int i;
for(i=0;i<6;i++)
{
send(chunchu[i]);
}
send(0x0d);
send(0x0a);
}
void main()
{
sheding();
while(1)
{
if(pp==1)
{
pp=0;
if(shuju[0]==0x55)
{
switch(shuju[1])
{
case 0x51:
a[0]=(shuju[3]<<8|shuju[2])/(32768/16);
a[1]=(shuju[5]<<8|shuju[4])/(32768/16);
a[2]=(shuju[7]<<8|shuju[6])/(32768/16);
break;
case 0x52:
w[0]=(shuju[3]<<8|shuju[2])/(32768/2000);
w[1]=(shuju[5]<<8|shuju[4])/(32768/2000);
w[2]=(shuju[7]<<8|shuju[6])/(32768/2000);
break;
case 0x53:
angle[0]=shuju[3]<<8+shuju[2];
angle[1]=(short)(shuju[5]<<8+shuju[4])*180/32768;
angle[2]=(short)(shuju[7]<<8+shuju[6])*180/32768;
send(shuju[3]);
send(shuju[2]);
send(0x0d);
send(0x0a);
break;
}
//chuli(chunchu,angle[0]);
//fs_shuzu();
}
}
}
}
void jieshou(void) interrupt 4
{
while(RI==0);
RI = 0;
shuju[i]=SBUF;
if(i==0&&shuju[0]!=0x55)
{
return;
}
else
{
i=i+1;
}
if(i==11)
{
i=0;
pp=1;
}
}