為了獲得一點黑幣,好下載,也是不擇手段了!
0.png (47.44 KB, 下載次數: 40)
下載附件
2018-6-9 03:45 上傳
IDE-Version:
*********************************************
μVision V4
下載方式
*********************************************
·SWD JTAG
程序功能
*********************************************
·STM32 USB鼠標實驗
硬件連接
*********************************************
·將USB插到開發板上
實驗現象
*********************************************
·可以使用KEY來控制電腦的鼠標的方向
單片機源程序如下:
- /*********************************************************************************************************
- *
- * File : main.c
- * Hardware Environment:
- * Build Environment : RealView MDK-ARM Version: 4.32
- * Version : V1.0
- * By : mao
- *
- *
- *********************************************************************************************************/
- /* Includes ------------------------------------------------------------------*/
- #include "stm32f10x.h"
- #include "usb_lib.h"
- #include "hw_config.h"
- #include "usb_pwr.h"
- #include "usart1.h"
- #include "Data.h"
- #ifdef __GNUC__
- /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
- set to 'Yes') calls __io_putchar() */
- #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
- #else
- #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
- #endif /* __GNUC__ */
- /* Private function prototypes -----------------------------------------------*/
- u8 MsgCmd;
- void Delay (uint32_t nCount);
- void USB_SendString(u8 *str) //
- {
- u8 ii=0;
- while(*str)
- {
- Transi_Buffer[ii++]=*(str++);
- if (ii ==22) break;
- }
- UserToPMABufferCopy(Transi_Buffer, ENDP2_TXADDR, 22);
- _SetEPTxStatus(ENDP2, EP_TX_VALID);
- }
- /*******************************************************************************
- * Function Name : main
- * Description : Main program
- * Input : None
- * Output : None
- * Return : None
- * Attention : None
- *******************************************************************************/
- int main(void)
- {
-
- Set_System();
-
- USB_Interrupts_Config();
-
- Set_USBClock();
-
- USB_Init();
- /* USART1 config 115200 8-N-1 */
- USART1_Config();
- NVIC_USART1_Configuration();
- MsgCmd=0;
-
- while (1)
- {
- if(MsgCmd) //當上位機發送數據以后,對MsgCmd置1
- {
- Delay(50000); //沒有這個延時,會少部分數據?為什么?
- // while(EP_RX_NAK!=GetEPRxStatus(ENDP1));
- printf("\r\n進入主函數");
- GET_CMD();
- }
- }
- }
- /*******************************************************************************
- * Function Name : Delay
- * Description : Delay Time
- * Input : - nCount: Delay Time
- * Output : None
- * Return : None
- * Attention : None
- *******************************************************************************/
- void Delay (uint32_t nCount)
- {
- for(; nCount != 0; nCount--)
- {
- }
- }
- /*******************************************************************************
- * Function Name : GPIO_Configuration
- * Description : Configure GPIO Pin
- * Input : None
- * Output : None
- * Return : None
- * Attention : None
- *******************************************************************************/
- //void GPIO_Configuration(void)
- //{
- // GPIO_InitTypeDef GPIO_InitStructure;
- //
- // RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB , ENABLE);
- ///**
- // * LED1 -> PB15 , LED2 -> PB14 , LED3 -> PB13 , LED4 -> PB12
- // */
- // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
- // GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- // GPIO_Init(GPIOB, &GPIO_InitStructure);
- //}
- //
- #ifdef USE_FULL_ASSERT
- /**
- * @brief Reports the name of the source file and the source line number
- * where the assert_param error has occurred.
- * @param file: pointer to the source file name
- * @param line: assert_param error line source number
- * @retval None
- */
- void assert_failed(uint8_t* file, uint32_t 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
- /*********************************************************************************************************
- END FILE
- *********************************************************************************************************/
復制代碼
所有資料51hei提供下載:
usb下位機1(上位機發,下位機收).rar
(407.71 KB, 下載次數: 36)
2018-6-9 03:45 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|