找回密码
 立即注册

QQ登录

只需一步,快速开始

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

STM32 USB HID键盘例程

[复制链接]
跳转到指定楼层
楼主
非常好STM32 USB HID键盘例程,欢迎请需要的同学下载!

/******************** (C) COPYRIGHT *********************************************
* Project Name       : MyUSB_hid
* Author             : DZ561
* Version            : V1.0
* Date               : Jun-17-2010
* Description        : STM32 USB HID

********************************************************************************/
#include "stm32f10x_lib.h"
#include "usb_lib.h"
#include "hw_config.h"
#include "stm32f10x_it.h"
#define nReportCnt 22
extern u8 Receive_Buffer[22];
extern u8 Transi_Buffer[22];
extern u8 USB_ReceiveFlg;
void DebugApp(void);
void NVIC_Configuration(void);
extern RCC_Configuration(void);
extern void USB_SendString(u8 *str);
vu8 MsgCmd;
extern u8 TimeCount;
int main(void)
{
#ifdef USER_DEBUG
    // DBGMCU->CR |= DBGMCU_CR_DBG_STOP;  //for debug purpose
#endif  
     RCC_Configuration();
     NVIC_Configuration();
     Set_System();  
//Control USB connecting via SW
//enable USB for STM32F103RB
#ifdef STM32F103RB
     RCC->APB2ENR |= (1 << 5);                 // enable clock for GPIOD  
     GPIOD->CRL &= ~0x00000F00;                // clear port PD2  
     GPIOD->CRL |=  0x00000700;                // PD2 General purpose output open-drain, max speed 50 MHz  
     GPIOD->BRR  = 0x0004;                     // reset PD2  (set to low)  
#endif
     USB_Interrupts_Config();
     Set_USBClock();   
     USB_Init();
     USB_ReceiveFlg = FALSE;
     while(1) //
     {
         if (TimeCount && USB_ReceiveFlg == TRUE) //&Ecirc;&Otilde;&micro;&frac12;&ordm;ó&Eacute;&Iuml;&Icirc;&raquo;&raquo;ú&micro;&Auml;&Ecirc;&yacute;&frac34;&Yacute;&ordm;ó&pound;&not;&frac12;&laquo;1S·&cent;&Euml;&Iacute;&Ograve;&raquo;&acute;&Icirc;&Ecirc;&yacute;&frac34;&Yacute;&cedil;&oslash;PC
         {
             USB_SendString("Hi,PC! I'm STM32-ARM");
             TimeCount = 0x00;
         }
     }
}
void USB_SendString(u8 *str)
{
     u8 ii=0;   
     while(*str)
     {
         Transi_Buffer[ii++]=*(str++);
         if (ii == nReportCnt) break;
     }
     UserToPMABufferCopy(Transi_Buffer, ENDP2_TXADDR, nReportCnt);
     SetEPTxValid(ENDP2);
}
/*******************************************************************************
* Function Name  : NVIC_Configuration
* Description    : Configures Vector Table base location.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void NVIC_Configuration(void)
{   
  //NVIC_InitTypeDef NVIC_InitStructure;
#ifdef  VECT_TAB_RAM  
  /* Set the Vector Table base location at 0x20000000 */
     NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else  /* VECT_TAB_FLASH  */
  /* Set the Vector Table base location at 0x08000000 */
     NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);   
#endif
}
/*******************************************************************************
* Function Name  : Delay
* Description    : Inserts a delay time.
* Input          : nCount: specifies the delay time length.
* Output         : None
* Return         : None
*******************************************************************************/
void Delay(vu32 nCount)
{
  for(; nCount!= 0;nCount--);
}
#ifdef  DEBUG
/*******************************************************************************
* Function Name  : assert_failed
* Description    : Reports the name of the source file and the source line number
*                  where the assert_param error has occurred.
* Input          : - file: pointer to the source file name
*                  - line: assert_param error line source number
* Output         : None
* Return         : None
*******************************************************************************/
void assert_failed(u8* file, u32 line)
{
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* Infinite loop */
  while(1)
  {
  }
  
}
#endif


捕获.PNG (83.98 KB, 下载次数: 33)

捕获.PNG

MyUSB_HID_KEIL.rar

366.28 KB, 下载次数: 122, 下载积分: 黑币 -5

评分

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

查看全部评分

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

使用道具 举报

沙发
ID:434678 发表于 2020-8-6 00:04 | 只看该作者
搬运都不该注释的吗?人家博客都在里边放着。
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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