找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2966|回复: 1
打印 上一主题 下一主题
收起左侧

瑞萨单片机四轴飞行器源码

[复制链接]
跳转到指定楼层
楼主
ID:240583 发表于 2017-10-18 15:07 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
附件为瑞萨单片机做的四轴飞行器源代码,希望可以帮到大家

所有资料51hei提供下载:
RL78四轴飞行器完美起飞开源代码.zip (239.66 KB, 下载次数: 14)


单片机源程序(主程序)如下:
  1. /***********************************************************************************************************************
  2. * DISCLAIMER
  3. * This software is supplied by Renesas Electronics Corporation and is only
  4. * intended for use with Renesas products. No other uses are authorized. This
  5. * software is owned by Renesas Electronics Corporation and is protected under
  6. * all applicable laws, including copyright laws.
  7. * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
  8. * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
  9. * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
  10. * AND NON-INFRINGEMENT.  ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
  11. * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
  12. * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
  13. * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
  14. * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
  15. * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  16. * Renesas reserves the right, without notice, to make changes to this software
  17. * and to discontinue the availability of this software.  By using this software,
  18. * you agree to the additional terms and conditions found by accessing the
  19. * following link:
  20. * http://www.renesas.com/disclaimer
  21. *
  22. * Copyright (C) 2011, 2013 Renesas Electronics Corporation. All rights reserved.
  23. ***********************************************************************************************************************/

  24. /***********************************************************************************************************************
  25. * File Name    : r_main.c
  26. * Version      : CodeGenerator for RL78/G13 V2.00.00.07 [22 Feb 2013]
  27. * Device(s)    : R5F100LE
  28. * Tool-Chain   : CA78K0R
  29. * Description  : This file implements main function.
  30. * Creation Date: 2015/8/5
  31. ***********************************************************************************************************************/

  32. /***********************************************************************************************************************
  33. Pragma directive
  34. ***********************************************************************************************************************/
  35. /* Start user code for pragma. Do not edit comment generated here */
  36. /* End user code. Do not edit comment generated here */

  37. /***********************************************************************************************************************
  38. Includes
  39. ***********************************************************************************************************************/
  40. #include "r_cg_macrodriver.h"
  41. #include "r_cg_cgc.h"
  42. #include "r_cg_port.h"
  43. #include "r_cg_serial.h"
  44. #include "r_cg_timer.h"
  45. /* Start user code for include. Do not edit comment generated here */
  46. #include "RF24L01.h"
  47. #include "MPU6050.h"
  48. #include "moto.h"
  49. #include "rc.h"
  50. #include "control.h"
  51. #include "timing.h"
  52. /* End user code. Do not edit comment generated here */
  53. #include "r_cg_userdefine.h"

  54. /***********************************************************************************************************************
  55. Global variables and functions
  56. ***********************************************************************************************************************/
  57. /* Start user code for global. Do not edit comment generated here */
  58. unsigned char si=0;
  59. #define BYTE0(x) x&0xff
  60. #define BYTE1(x) (x&0xff00)>>8
  61. MD_STATUS Rstatus;
  62. //unsigned char SYS_INIT_OK = 0;
  63. extern char TxBuf[32];
  64. void UARTA1_Send_AF(void);
  65. /* End user code. Do not edit comment generated here */
  66. void R_MAIN_UserInit(void);

  67. /***********************************************************************************************************************
  68. * Function Name: main
  69. * Description  : This function implements main function.
  70. * Arguments    : None
  71. * Return Value : None
  72. ***********************************************************************************************************************/
  73. void main(void)
  74. {
  75.     R_MAIN_UserInit();
  76.     /* Start user code. Do not edit comment generated here */
  77.     //R_UART0_Start();
  78.     while (1U)
  79.     {
  80.                 //(mpuBuf,1);
  81.                 //P13.0=0;
  82.                 //Prepare_Data();
  83.                 //SetRX_Mode();
  84.                 //P13.0=1;
  85.                 //Get_Attitude();
  86.                 NOP();
  87.                 //UARTA1_Send_AF();
  88.                 //NRF_Send_AF();
  89.                
  90.        
  91.                 //DelayUs(32000);
  92.                 //DelayUs(32000);
  93.                
  94.                 //DelayUs(5000);
  95.                
  96.                 //P7.6=~P7.6;
  97.         //ISendStrS(DEVICE_ADDRESS,0x6b,mpuBuf,1);
  98.     }
  99.     /* End user code. Do not edit comment generated here */
  100. }

  101. /***********************************************************************************************************************
  102. * Function Name: R_MAIN_UserInit
  103. * Description  : This function adds user code before implementing main function.
  104. * Arguments    : None
  105. * Return Value : None
  106. ***********************************************************************************************************************/
  107. void R_MAIN_UserInit(void)
  108. {
  109.     /* Start user code. Do not edit comment generated here */
  110.     unsigned long time=200000;
  111.     EI();
  112.     //unsigned long time=100000;
  113.     while(time--)NOP();
  114.     CreateIICPort();
  115.     InitMPU6050();
  116.     RF24L01_IO_set();
  117.     init_NRF24L01();
  118.     R_TAU0_Channel5_Start();
  119.     R_TAU0_Channel0_Start();
  120.     Pid_init();
  121.     /* End user code. Do not edit comment generated here */
  122. }

  123. /* Start user code for adding. Do not edit comment generated here */
  124. void UARTA1_Send_AF(void)
  125. {
  126.         unsigned char i,sum;
  127.         unsigned int _temp;

  128.         TxBuf[0]=0x88;
  129.         TxBuf[1]=0xAF;
  130.         TxBuf[2]=0x1C;
  131.         TxBuf[3]=BYTE1(MPU6050_ACC_LAST.x);
  132.         TxBuf[4]=BYTE0(MPU6050_ACC_LAST.x);
  133.         TxBuf[5]=BYTE1(MPU6050_ACC_LAST.y);
  134.         TxBuf[6]=BYTE0(MPU6050_ACC_LAST.y);
  135.         TxBuf[7]=BYTE1(MPU6050_ACC_LAST.z);
  136.         TxBuf[8]=BYTE0(MPU6050_ACC_LAST.z);
  137.         TxBuf[9]=BYTE1(MPU6050_GYRO_LAST.x);
  138.         TxBuf[10]=BYTE0(MPU6050_GYRO_LAST.x);
  139.         TxBuf[11]=BYTE1(MPU6050_GYRO_LAST.y);
  140.         TxBuf[12]=BYTE0(MPU6050_GYRO_LAST.y);
  141.         TxBuf[13]=BYTE1(MPU6050_GYRO_LAST.z);
  142.         TxBuf[14]=BYTE0(MPU6050_GYRO_LAST.z);
  143.         TxBuf[17]=0;
  144.         TxBuf[18]=0;
  145.         TxBuf[19]=0;
  146.         TxBuf[20]=0;
  147.         _temp = (int)(Q_angle.x*100);
  148.         TxBuf[21]=BYTE1(_temp);
  149.         TxBuf[22]=BYTE0(_temp);
  150.         _temp = (int)(Q_angle.y*100);
  151.         TxBuf[23]=BYTE1(_temp);
  152.         TxBuf[24]=BYTE0(_temp);
  153.         TxBuf[25]=0;
  154.         TxBuf[26]=0;

  155.         sum = 0;
  156.         for(i=0;i<31;i++)
  157.                 sum += TxBuf[i];

  158.         TxBuf[31]=sum;
  159.         R_UART0_Send((unsigned char*)TxBuf,32);       
  160. }
  161. /* End user code. Do not edit comment generated here */
复制代码


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:600532 发表于 2019-8-15 18:24 | 只看该作者
请问是个瑞萨G12的吗?
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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