找回密码
 立即注册

QQ登录

只需一步,快速开始

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

STM32空中3D鼠标源程序与原理图

[复制链接]
跳转到指定楼层
楼主
分享一个3D鼠标的方案
包括软件,原理图


单片机源程序如下:
  1. /*
  2. [3D空间鼠标固件-发送端]

  3. MCU   :STM32F103C8T6
  4. IMU   :MPU6050
  5. RF2.4G:NRF24L01

  6. [ 秋阳 2013-11 ]
  7. */
  8. #include "stm32f10x.h"
  9. #include "stdlib.h"
  10. #include "math.h"
  11. #include "delay.h"
  12. #include "NRF24L01.H"
  13. #include "MPU6050.H"
  14. #include "IIC.H"
  15. #include "spi.H"
  16. #include "ALL_config.h"
  17. #include "var_global.h"
  18. #include "Cal.h"
  19. #include "KEY.h"
  20. //-----------------------------------------------------------------//
  21. u16 dir_time=0;
  22. u8 RC_CON=0;
  23. float Button=0;
  24. u16 TO=0;
  25. u16 C_count,L_count;
  26. u8 D_Clk;
  27. u8 clk1,clk2;

  28. //---------------------------------------------------------------------//


  29. int main()
  30. {
  31. RCC_Configuration(); //配置系统时钟
  32. delay_ms(50);
  33. I2C_Configuration();
  34. GPIO_Configuration();       
  35. SPIx_Init();

  36. //设置为发射模式
  37. NRF24L01Int();   
  38. NRFSetTxMode(TxDate);       

  39. //设置IMU
  40. IIC_Reboot();
  41. IIC_Reboot();
  42. Init_MPU6050();       

  43. //设置陀螺仪零点
  44. Set_Offset();       

  45. //设置5ms中断
  46. TIM3_INT();

  47. while(1)
  48. {
  49.         //简单闪灯
  50.   GPIO_ResetBits(GPIOB,GPIO_Pin_0);
  51.         Delay_s(5);
  52.         GPIO_SetBits(GPIOB,GPIO_Pin_0);       
  53.   Delay_s(5);
  54. }

  55. }
  56. //----------------------------5ms中断--------------------------------------
  57. void TIM3_IRQHandler()
  58. {
  59. TIM_ClearITPendingBit(TIM3,TIM_FLAG_Update);
  60. dir_time++;

  61. //读取传感器
  62. READ_MPU6050();       
  63. Cal_TsData();

  64. sensfusion6UpdateQ(-GRY_F.X,-GRY_F.Y,GRY_F.Z,ACC_AVG.X*100,ACC_AVG.Y*100,ACC_AVG.Z*100,0.005f);
  65. sensfusion6GetEulerRPY(&Q_ANGLE.Roll, &Q_ANGLE.Pitch, &Q_ANGLE.Yaw);


  66. //----------------单击双击优化,防止双击时指针漂移---------------------------------
  67. //-无线数据包标志:【左单1】【 左双2】 【左长3】 【右单4】 【左右长5】

  68. if(dir_time>=5) //按键扫描周期:5ms*5=25ms
  69. {         
  70.          dir_time=0;
  71.          Get_KEY();   //取得按键状态
  72.          if (!K_Trg && !K_TrgR) Button=0;
  73.    if (K_Trg) {Button=1;D_Clk=1;}  //左键键按下,双击计时开始
  74.    if (K_TrgR)Button=4; //右键按下
  75.    if (K_Cont) L_count++;else L_count=0;         
  76.          if (D_Clk && C_count<15)  C_count++; else {D_Clk=0;C_count=0;} //双击超时  
  77.    if (K_Trg && C_count>2) {Button=2;C_count=0;D_Clk=0;}//第一下点完,未超时且又被触发,为左键双击
  78.          if (L_count>15)            Button=3;//左键长按
  79.          if( K_Cont && K_ContR) Button=5;    //左右键按下
  80. }         
  81. //------------------------------------------------------
  82. if(Button==1)clk1++;
  83. if(Button==2)clk2++;

  84. Send_RFdata();    // 发送RF数据包

  85. }

复制代码

Keil代码下载:
STM32空中3D鼠标.7z (1.6 MB, 下载次数: 34)


评分

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

查看全部评分

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

使用道具 举报

沙发
ID:756400 发表于 2022-11-23 18:45 | 只看该作者
谢谢分享,我看看好不好用。
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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