单片机论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 100|回复: 1
收起左侧

电脑鼠走迷宫的STM32源程序

[复制链接]
Strongest丶星空 发表于 2019-7-10 21:02 | 显示全部楼层 |阅读模式
其中红外参数让我在程序里锁死了,只能用蓝牙写入

单片机源程序如下:
  1. /* USER CODE END Header */

  2. /* Includes ------------------------------------------------------------------*/
  3. #include "main.h"
  4. #include "adc.h"
  5. #include "dma.h"
  6. #include "i2c.h"
  7. #include "tim.h"
  8. #include "usart.h"
  9. #include "gpio.h"

  10. /* Private includes ----------------------------------------------------------*/
  11. /* USER CODE BEGIN Includes */
  12. #include "sensor.h"
  13. #include "maze.h"

  14. #include <string.h>
  15. /* USER CODE END Includes */

  16. /* Private typedef -----------------------------------------------------------*/
  17. /* USER CODE BEGIN PTD */

  18. /* USER CODE END PTD */

  19. /* Private define ------------------------------------------------------------*/
  20. /* USER CODE BEGIN PD */

  21. /* USER CODE END PD */

  22. /* Private macro -------------------------------------------------------------*/
  23. /* USER CODE BEGIN PM */

  24. /* USER CODE END PM */

  25. /* Private variables ---------------------------------------------------------*/

  26. /* USER CODE BEGIN PV */

  27. /* USER CODE END PV */

  28. /* Private function prototypes -----------------------------------------------*/
  29. void SystemClock_Config(void);
  30. /* USER CODE BEGIN PFP */

  31. /* USER CODE END PFP */

  32. /* Private user code ---------------------------------------------------------*/
  33. /* USER CODE BEGIN 0 */

  34. /* USER CODE END 0 */

  35. /**
  36.   * @brief  The application entry point.
  37.   * @retval int
  38.   */
  39. int main(void)
  40. {
  41.     /* USER CODE BEGIN 1 */
  42.     //uint8_t ucLedRun = 0;
  43.     //uint8_t ucLedCount = 0;
  44.                
  45.     /* USER CODE END 1 */

  46.     /* MCU Configuration--------------------------------------------------------*/

  47.     /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  48.     HAL_Init();

  49.     /* USER CODE BEGIN Init */

  50.     /* USER CODE END Init */

  51.     /* Configure the system clock */
  52.     SystemClock_Config();

  53.     /* USER CODE BEGIN SysInit */

  54.     /* USER CODE END SysInit */

  55.     /* Initialize all configured peripherals */
  56.     MX_GPIO_Init();
  57.     MX_DMA_Init();
  58.     MX_TIM1_Init();
  59.     MX_TIM2_Init();
  60.     MX_TIM3_Init();
  61.     MX_ADC1_Init();
  62.     MX_I2C1_Init();
  63.     MX_USART3_UART_Init();
  64.     /* USER CODE BEGIN 2 */
  65.                
  66.     PIDInit();
  67.    
  68.     HAL_Delay(200);
  69.     getStaticAngle();
  70.                 HAL_Delay(200);
  71.                 mouseInit();
  72.     /* USER CODE END 2 */

  73.     /* Infinite loop */
  74.     /* USER CODE BEGIN WHILE */
  75.     while (1)
  76.     {
  77.         /* USER CODE END WHILE */

  78.         /* USER CODE BEGIN 3 */
  79.                                 mainTask();
  80.     }
  81.     /* USER CODE END 3 */
  82. }

  83. /**
  84.   * @brief System Clock Configuration
  85.   * @retval None
  86.   */
  87. void SystemClock_Config(void)
  88. {
  89.     RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  90.     RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  91.     RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};

  92.     /**Initializes the CPU, AHB and APB busses clocks
  93.     */
  94.     RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  95.     RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  96.     RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  97.     RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  98.     RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  99.     RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  100.     RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
  101.     if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  102.     {
  103.         Error_Handler();
  104.     }
  105.     /**Initializes the CPU, AHB and APB busses clocks
  106.     */
  107.     RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  108.                                   |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  109.     RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  110.     RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  111.     RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  112.     RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  113.     if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  114.     {
  115.         Error_Handler();
  116.     }
  117.     PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC;
  118.     PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6;
  119.     if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  120.     {
  121.         Error_Handler();
  122.     }
  123. }

  124. /* USER CODE BEGIN 4 */

  125. /* USER CODE END 4 */

  126. /**
  127.   * @brief  This function is executed in case of error occurrence.
  128.   * @retval None
  129.   */
  130. void Error_Handler(void)
  131. {
  132.     /* USER CODE BEGIN Error_Handler_Debug */
  133.     /* User can add his own implementation to report the HAL error return state */

  134.     /* USER CODE END Error_Handler_Debug */
  135. }

  136. #ifdef  USE_FULL_ASSERT
  137. /**
  138.   * @brief  Reports the name of the source file and the source line number
  139.   *         where the assert_param error has occurred.
  140.   * @param  file: pointer to the source file name
  141.   * @param  line: assert_param error line source number
  142.   * @retval None
  143.   */
  144. void assert_failed(uint8_t *file, uint32_t line)
  145. {
  146.     /* USER CODE BEGIN 6 */
  147.     /* User can add his own implementation to report the file name and line number,
  148.        tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  149.     /* USER CODE END 6 */
  150. }
  151. #endif /* USE_FULL_ASSERT */

  152. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
复制代码

所有资料51hei提供下载:
MouseOrgV0.9.7z (2.91 MB, 下载次数: 3)

评分

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

查看全部评分

回复

使用道具 举报

 楼主| Strongest丶星空 发表于 2019-7-10 21:03 | 显示全部楼层
因为头文件太多了,所以不方便张贴出来,所以想看的只能破费了
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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