金牌会员
- 积分
- 1619
- 威望
- 799
- 贡献
- 516
- 兑换币
- 518
- 注册时间
- 2013-1-17
- 在线时间
- 152 小时
|
2#
楼主 |
发表于 2015-4-2 14:36:29
|
只看该作者
这个是通信协议,然后我直接调用WirelessSerial(100,200,300,400);没反应
unsigned char TxBuf[10] = {0,0,0,0,0,0,0,0,0,0};
void SCI_sendstring(unsigned char *a,unsigned char stringlen)
{
unsigned char i;
for(i=0;i<=stringlen;i++)
Uart_SendByte(UART4,*(a++));
}
unsigned int CRC_Check(unsigned char *Buf, unsigned char crc_count)
{
unsigned short CRC_Temp;
unsigned char i,j;
CRC_Temp = 0xffff;
for (i=0;i<crc_count; i++)
{
CRC_Temp ^= Buf[i];
for(j=0;j<8;j++)
{
if (CRC_Temp & 0x01)
CRC_Temp = (CRC_Temp >>1 ) ^ 0xa001;
else
CRC_Temp = CRC_Temp >> 1;
}
}
return(CRC_Temp);
}
void WirelessSerial(float a,float b,float c,float d)
{
int num;
unsigned char *data;
#if 1
num = (int)a; //Speed
data = (unsigned char *)#
TxBuf[0] = *data;
data++;
TxBuf[1] = *data;
num = (int)b; //MotorPWM
data = (unsigned char *)#
TxBuf[2] = *data;
data++;
TxBuf[3] = *data;
num = (int)c; //angle
data = (unsigned char *)#
TxBuf[4] = *data;
data++;
TxBuf[5] = *data;
num = (int)d;
data = (unsigned char *)#
TxBuf[6] = *data;
data++;
TxBuf[7] = *data;
#endif
num = CRC_Check(TxBuf,8);
TxBuf[8] = num & 0xFF;
TxBuf[9] = num >> 8;
SCI_sendstring(TxBuf,9);
}
|
|