附件是用STM32F103實現的USB_HID有關游戲手柄的實現,希望對有相關需求的客戶有所幫助
本程序能夠模擬手柄基本功能的鍵,并可以做一般的游戲應用,增加了鍵盤掃描程序,不使用中斷來處理。
將方向鍵換為搖桿來使用。 兼容win7
0.png (49.42 KB, 下載次數: 105)
下載附件
2017-7-18 17:15 上傳
所有資料51hei提供下載:
stm32_手柄(增強版)VET6,兼容win7.rar
(982.69 KB, 下載次數: 116)
2017-7-18 17:20 上傳
點擊文件名下載附件
USB—HID 下載積分: 黑幣 -5
單片機源程序如下:
- #include "stm32f10x.h"
- #include "user_lib.h"
- #include "stdio.h"
- #include "usb_hw.h"
- #include "key.h"
- #include "adc.h"
- #include "termi.h"
- extern BYTE USB_Configuration;
- /**************************************************************************
- * 函數名 : GpioInitialisation
- * 函數描述 : 設置各GPIO端口功能
- * 輸入參數 : 無
- * 輸出結果 : 無
- * 返回值 : 無
- **************************************************************************/
- void GpioInitialisation(void)
- {
- /* 定義GPIO初始化結構體 GPIO_InitStructure*/
- GPIO_InitTypeDef GPIO_InitStructure;
-
- /* 打開APB2總線上的GPIOA時鐘*/
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
-
- /* 設置 GPIOA0 , GPIOA1 為上拉輸入 */
- GPIO_InitStructure.GPIO_Pin = KEYPIN;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
- GPIO_Init(KEYPORT, &GPIO_InitStructure);
-
- /* 設置 GPIOA4 ,GPIOA5 為推挽輸出,最大翻轉頻率為50MHz*/
- // GPIO_InitStructure.GPIO_Pin = LED0PIN | LED1PIN;
- // GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- // GPIO_Init(LEDPORT, &GPIO_InitStructure);
- }
- int main(void)
- {
- /*此處與調試宏assert_param有關,在調試階段不準刪除*/
- GpioInitialisation();
- USART_Config();
-
- NVIC_Config();
- //EXTI_Config();
- key_init();
-
- USB_Init();
- USB_Connect(TRUE);
- /*等待USB枚舉成功*/
- while (! USB_Configuration)
- ;
-
- termi_clr();
- printf("Hello\n");
-
-
- ……………………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
|