找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2384|回复: 1
收起左侧

AT9S混控,STM32F103C8T6解析SBUS程序

[复制链接]
ID:600656 发表于 2019-8-16 09:33 | 显示全部楼层 |阅读模式
通过STM32解析SBUS然后完成混控

单片机源程序如下:
  1. #include "led.h"
  2. #include "delay.h"
  3. #include "key.h"
  4. #include "sys.h"
  5. #include "usart.h"
  6. #include "timer.h"


  7. extern int usart1_stop_flag;

  8. u16 channel[8];
  9. extern int sbus[200];
  10. int main(void)
  11. {
  12.        
  13.          uart_init(100000);
  14.          NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
  15.          TIM3_PWM_Init(7199,199);         //不分频。PWM频率  50hz  7200/50
  16.          TIM4_PWM_Init(7199,199);         //不分频。PWM频率  50hz  7200/50
  17.          TIM_SetCompare2(TIM3,539);
  18.          TIM_SetCompare3(TIM3,539);
  19.          TIM_SetCompare4(TIM3,539);
  20.          TIM_SetCompare1(TIM4,359);
  21. //         TIM_SetCompare2(TIM4,539);
  22. //         TIM_SetCompare3(TIM4,539);
  23. while(1)
  24. {         
  25.         if(usart1_stop_flag==1)
  26.         {
  27.             usart1_stop_flag=0;
  28.             channel[0] = (((sbus[1] & 0x7) << 8)   | sbus[0])*0.5+30;//*0.77+767;                               
  29.                         channel[1] = (((sbus[2] & 0x3f) << 5)  | (sbus[1] >> 3))*0.5+30;//*0.77+767;
  30.                         channel[2] = (((sbus[4] & 0x1)<<10)    | (sbus[3] << 2) | (sbus[2] >> 6))*0.261+279.27;//*0.77+767;
  31.                         channel[3]=  (((sbus[5] & 0xf) << 7)   | (sbus[4] >> 1))*0.5+30;//*0.77+767;
  32.                         channel[4]=  (((sbus[6] & 0x7f) << 4)  | (sbus[5] >> 4))*0.5+30;//*0.77+767;
  33.                         channel[5]=  (((sbus[8] & 0x2) << 9)   | (sbus[7] << 1) | (sbus[6] >> 7))*0.5+30;//*0.77+767;
  34.                         channel[6] = (((sbus[9] & 0x1f) << 6)  | (sbus[8] >> 2))*0.5+30;//*0.77+767;
  35.                         channel[7] = ((sbus[10]  << 3)         | (sbus[9] >> 5))*0.5+30;//*0.77+767;
  36.        
  37.                  
  38.                         TIM_SetCompare2(TIM3,channel[0]-channel[1]+539);
  39.                   TIM_SetCompare3(TIM3,channel[0]+channel[1]-539);
  40.                         TIM_SetCompare4(TIM3,channel[0]+channel[3]-539);
  41.                        
  42.                

  43.                   TIM_SetCompare1(TIM4,channel[2]);
  44. //            TIM_SetCompare2(TIM4,a);
  45. //            TIM_SetCompare3(TIM4,a);
  46.                
  47.           printf("1=%d\t",channel[0]);
  48.           printf("2=%d\t",channel[1]);
  49.                 printf("3=%d\t",channel[2]);
  50.                 printf("4=%d\t",channel[3]);
  51.                 printf("5=%d\t",channel[4]);
  52.                 printf("6=%d\t",channel[5]);
  53.                 printf("7=%d\t",channel[6]);
  54.                 printf("8=%d\r\n ",channel[7]);

  55.         }
  56. }
  57. }
复制代码

所有资料51hei提供下载:
AT9S混控.7z (195.14 KB, 下载次数: 70)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

ID:863817 发表于 2020-12-20 10:47 | 显示全部楼层
你好,能开发一块通用的混控板吗?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表