標題: stm32f103單片機USB_HID游戲手柄的實現(xiàn),可以直接燒寫 兼容win7 [打印本頁]

作者: 東方神鹿2017    時間: 2017-7-18 14:27
標題: stm32f103單片機USB_HID游戲手柄的實現(xiàn),可以直接燒寫 兼容win7
附件是用STM32F103實現(xiàn)的USB_HID有關(guān)游戲手柄的實現(xiàn),希望對有相關(guān)需求的客戶有所幫助
本程序能夠模擬手柄基本功能的鍵,并可以做一般的游戲應用,增加了鍵盤掃描程序,不使用中斷來處理。
將方向鍵換為搖桿來使用。 兼容win7


所有資料51hei提供下載:
stm32_手柄(增強版)VET6,兼容win7.rar (982.69 KB, 下載次數(shù): 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. * 函數(shù)名          : GpioInitialisation
  11. * 函數(shù)描述            : 設(shè)置各GPIO端口功能
  12. * 輸入?yún)?shù)      : 無
  13. * 輸出結(jié)果      : 無
  14. * 返回值        : 無
  15. **************************************************************************/
  16. void GpioInitialisation(void)
  17. {
  18.     /* 定義GPIO初始化結(jié)構(gòu)體 GPIO_InitStructure*/
  19.     GPIO_InitTypeDef GPIO_InitStructure;
  20.    
  21.     /* 打開APB2總線上的GPIOA時鐘*/
  22.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
  23.    
  24.     /* 設(shè)置 GPIOA0 , GPIOA1 為上拉輸入 */
  25.     GPIO_InitStructure.GPIO_Pin = KEYPIN;
  26.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  27.     GPIO_Init(KEYPORT, &GPIO_InitStructure);
  28.    
  29.     /* 設(shè)置 GPIOA4 ,GPIOA5 為推挽輸出,最大翻轉(zhuǎn)頻率為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.         /*此處與調(diào)試宏assert_param有關(guān),在調(diào)試階段不準刪除*/
  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
很想學習關(guān)于HID的這部分,謝謝分享




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1