标题: stm32f103单片机USB_HID游戏手柄的实现,可以直接烧写 兼容win7 [打印本页]

作者: 东方神鹿2017    时间: 2017-7-18 14:27
标题: stm32f103单片机USB_HID游戏手柄的实现,可以直接烧写 兼容win7
附件是用STM32F103实现的USB_HID有关游戏手柄的实现,希望对有相关需求的客户有所帮助
本程序能够模拟手柄基本功能的键,并可以做一般的游戏应用,增加了键盘扫描程序,不使用中断来处理。
将方向键换为摇杆来使用。 兼容win7


所有资料51hei提供下载:
stm32_手柄(增强版)VET6,兼容win7.rar (982.69 KB, 下载次数: 116)


单片机源程序如下:
  1. #include "stm32f10x.h"
  2. #include "user_lib.h"
  3. #include "stdio.h"
  4. #include "usb_hw.h"
  5. #include "key.h"
  6. #include "adc.h"
  7. #include "termi.h"

  8. extern BYTE        USB_Configuration;


  9. /**************************************************************************
  10. * 函数名          : GpioInitialisation
  11. * 函数描述            : 设置各GPIO端口功能
  12. * 输入参数      : 无
  13. * 输出结果      : 无
  14. * 返回值        : 无
  15. **************************************************************************/
  16. void GpioInitialisation(void)
  17. {
  18.     /* 定义GPIO初始化结构体 GPIO_InitStructure*/
  19.     GPIO_InitTypeDef GPIO_InitStructure;
  20.    
  21.     /* 打开APB2总线上的GPIOA时钟*/
  22.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
  23.    
  24.     /* 设置 GPIOA0 , GPIOA1 为上拉输入 */
  25.     GPIO_InitStructure.GPIO_Pin = KEYPIN;
  26.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  27.     GPIO_Init(KEYPORT, &GPIO_InitStructure);
  28.    
  29.     /* 设置 GPIOA4 ,GPIOA5 为推挽输出,最大翻转频率为50MHz*/
  30. //     GPIO_InitStructure.GPIO_Pin = LED0PIN | LED1PIN;
  31. //     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  32. //     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  33. //     GPIO_Init(LEDPORT, &GPIO_InitStructure);
  34. }

  35. int main(void)
  36. {  
  37.         /*此处与调试宏assert_param有关,在调试阶段不准删除*/
  38.         GpioInitialisation();
  39.          USART_Config();

  40.         NVIC_Config();
  41.         //EXTI_Config();

  42.         key_init();
  43.         
  44.         USB_Init();
  45.         USB_Connect(TRUE);
  46.         /*等待USB枚举成功*/
  47.         while (! USB_Configuration)
  48.                 ;
  49.         
  50.         termi_clr();
  51.         printf("Hello\n");
  52.         
  53.         
  54. ……………………

  55. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码





作者: alan_jiang    时间: 2017-7-27 12:21
尝试下
作者: 7839502    时间: 2017-9-7 20:23
谢谢分享,可惜积分不够
作者: ranxy    时间: 2020-6-16 01:09
下了不能用啊
作者: tarchen    时间: 2024-10-21 11:34
好代码,有空看看.
作者: yanggo    时间: 2024-11-12 15:41
还不会,感谢分享,有钱再下载。
作者: happy82828    时间: 2024-11-21 16:13
很想学习关于HID的这部分,谢谢分享




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1