找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3537|回复: 2
收起左侧

MM32F103 USB应用实例Custom_HID通讯例程

[复制链接]
ID:714588 发表于 2020-7-30 16:39 | 显示全部楼层 |阅读模式
基于MM32F103 USB Custom_HID 通讯例程,基于32位 ARM Cortex M3 的MM32F103xBx8的例程

单片机源程序如下:
  1. /* Includes ------------------------------------------------------------------*/
  2. #include "MM32F103.h"
  3. #include "usb_lib.h"
  4. #include "hw_config.h"
  5. #include "usbio.h"
  6. #include "usb_regs.h"


  7. #include "usb_pwr.h"
  8. #include "usb_desc.h"
  9. #include "sys.h"
  10. #include "uart.h"
  11. #include "delay.h"
  12. #include "led.h"


  13. /* Private typedef -----------------------------------------------------------*/
  14. /* Private define ------------------------------------------------------------*/
  15. /* Private macro -------------------------------------------------------------*/
  16. /* Private variables ---------------------------------------------------------*/
  17. /* Extern variables ----------------------------------------------------------*/
  18. /* Private function prototypes -----------------------------------------------*/
  19. void Delay(__IO uint32_t nCount);

  20. extern uint8_t Flag_Receive;


  21. /* Private functions ---------------------------------------------------------*/

  22. /*******************************************************************************
  23. * Function Name  : main.
  24. * Description    : main routine.
  25. * Input          : None.
  26. * Output         : None.
  27. * Return         : None.
  28. *******************************************************************************/

  29. uint8_t table_data[64]={
  30.         
  31.         0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
  32.         0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
  33.         0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
  34.         0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,        
  35.         
  36. };


  37. int main(void)
  38. {
  39.         
  40.         delay_init();
  41.         
  42.         uart_initwBaudRate(115200);
  43.         
  44.         LED_Init();
  45.         
  46.   Set_System();

  47.   USB_Interrupts_Config();

  48.   Set_USBClock();

  49.   USB_Init();
  50.         
  51.         printf("System Initial Success\r\n");
  52.         
  53.   while (1)
  54.   {
  55.         if(bDeviceState == CONFIGURED)  //等待USB初始化完成
  56.                                 {
  57. //                                        if(Flag_Receive)
  58. //                                        {
  59. //                                                                                         
  60. //                                                        USB_Send_Buffer[0] = 0xaa;
  61. //                                                        USB_Send_Buffer[1] = 0x55;
  62. //                                                        USB_Send_Buffer[2] = 0xaa;
  63. //                                                        USB_Send_Buffer[3] = 0x55;
  64. //                                                        USB_Send_Buffer[4] = 0xaa;
  65. //                                                        USB_Send_Buffer[5] = 0x55;
  66. //                                                        USB_SendData(USB_Send_Buffer,64);         
  67. //                                                
  68. //                                                        Flag_Receive = 0;        
  69. //                                                
  70. //                                        }                                       
  71.                                         USB_SendData(table_data,5);
  72.                                         delay_ms(5000);
  73.                                 }
  74.         //USB_SendData(table_data,64);
  75.                
  76.   }
  77.         
  78. }

  79. /*******************************************************************************
  80. * Function Name  : Delay
  81. * Description    : Inserts a delay time.
  82. * Input          : nCount: specifies the delay time length.
  83. * Output         : None
  84. * Return         : None
  85. *******************************************************************************/
  86. void Delay(__IO uint32_t nCount)
  87. {
  88.   for(; nCount!= 0;nCount--);
  89. }

  90. #ifdef  USE_FULL_ASSERT
  91. /*******************************************************************************
  92. * Function Name  : assert_failed
  93. * Description    : Reports the name of the source file and the source line number
  94. *                  where the assert_param error has occurred.
  95. * Input          : - file: pointer to the source file name
  96. *                  - line: assert_param error line source number
  97. * Output         : None
  98. * Return         : None
  99. *******************************************************************************/
  100. void assert_failed(uint8_t* file, uint32_t line)
  101. {
  102.   /* User can add his own implementation to report the file name and line number,
  103.      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  104.   /* Infinite loop */
  105.   while(1)
  106.   {
  107.   }
  108. }
  109. #endif

  110. /******************* (C) COPYRIGHT 2009 Mindmotion *****END OF FILE****/
复制代码

所有资料51hei提供下载:
MM32F103_USB_Custom_HID.7z (161.23 KB, 下载次数: 43)
回复

使用道具 举报

ID:584195 发表于 2021-8-5 22:40 | 显示全部楼层
楼主,好像用这个的人很少呀?你是做宣传的吗?
回复

使用道具 举报

ID:825413 发表于 2022-3-31 09:18 | 显示全部楼层
这个程序,我在WIN10上可用正常使用,在win7  和 XP上USB不能识别,是什么问题?
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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