科创上传代码

#include "include.h"
/******************************************************************
**函数名称:void Data_Send_02(unsigned short int *pst)
**函数功能:向匿名上位机发送九轴传感器数据
**函数输入:九轴数据存放数组,长度为9
**函数返回:无
 *****************************************************************/
void UartData_Send_02(unsigned short int *pst)
{
  unsigned char _cnt=0;
  unsigned char sum = 0;
  unsigned char i=0;
  unsigned char data_to_send[23];
  data_to_send[_cnt++]=0xAA;
  data_to_send[_cnt++]=0xAA;
  data_to_send[_cnt++]=0x02;
  data_to_send[_cnt++]=0;
  data_to_send[_cnt++]=(unsigned char)(pst[0]>>8);
  data_to_send[_cnt++]=(unsigned char)pst[0];
  data_to_send[_cnt++]=(unsigned char)(pst[1]>>8);
  data_to_send[_cnt++]=(unsigned char)pst[1];
  data_to_send[_cnt++]=(unsigned char)(pst[2]>>8);
  data_to_send[_cnt++]=(unsigned char)pst[2];
  data_to_send[_cnt++]=(unsigned char)(pst[3]>>8);
  data_to_send[_cnt++]=(unsigned char)pst[3];
  data_to_send[_cnt++]=(unsigned char)(pst[4]>>8);
  data_to_send[_cnt++]=(unsigned char)pst[4];
  data_to_send[_cnt++]=(unsigned char)(pst[5]>>8);
  data_to_send[_cnt++]=(unsigned char)pst[5];
  data_to_send[_cnt++]=(unsigned char)(pst[6]>>8);
  data_to_send[_cnt++]=(unsigned char)pst[6];
  data_to_send[_cnt++]=(unsigned char)(pst[7]>>8);
  data_to_send[_cnt++]=(unsigned char)pst[7];
  data_to_send[_cnt++]=(unsigned char)(pst[8]>>8);
  data_to_send[_cnt++]=(unsigned char)pst[8];
  data_to_send[3] = _cnt-4;
  sum = 0;
  for(i=0;i<_cnt;i++)
  {
    sum += data_to_send[i];
  }
  data_to_send[_cnt++] = sum;
  for(i=0;i<_cnt;i++)
  {
    UART4_PutChar(data_to_send[i]);
  }
}
/****************************************************************************************
**函数名称:void Data_Send_F1(int *pst,unsigned char len)
**函数功能:向匿名上位机发送len个int型数据
**函数输入:pst:数据存放数组,len要发送的数据长度(1-20)
**函数返回:无
**备    注:传送7个数据需要1680us,每多1个数据需要再加168us(不包括数据赋值过程中的运算)
            比如传送9个数据就需 1680+168*2 = 2016(us)
 ***************************************************************************************/
void UartData_Send_F1(int *pst,unsigned char len)
{
  unsigned char sum = 0;
  unsigned char i;
  unsigned char data_to_send[45];
  data_to_send[0] = 0xAA;
  data_to_send[1] = 0xAA;
  data_to_send[2] = 0xF1;
  data_to_send[3] = 2*len;
  for(i=0;i<len;i++)
  {
    data_to_send[2*i+4] = (unsigned char)(pst[i]>>8);
    data_to_send[2*i+5] = (unsigned char)pst[i];
  }
  for(i=0;i<2*len+4;i++)
  {
    sum += data_to_send[i];
  }
  data_to_send[2*len+4] = sum;
  for(i=0;i<2*len+5;i++)
  {
    UART4_PutChar(data_to_send[i]);
  }
}

https://blog.csdn.net/weixin_45638608/article/details/115121213?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522166279238616800182119151%2522%252C%2522scm%2522%253A%252220140713.130102334…%2522%257D&request_id=166279238616800182119151&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allsobaiduend~default-1-115121213-null-null.142v47control_1,201v3control_2&utm_term=%E5%8C%BF%E5%90%8D%E7%A7%91%E5%88%9B%E5%9C%B0%E9%9D%A2%E7%AB%99&spm=1018.2226.3001.4187

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值