找回密码
 立即注册

QQ登录

只需一步,快速开始

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

STM32和HMI人机通信程序源码

[复制链接]
跳转到指定楼层
楼主
分享一个好玩的小东西
STM32的程序和HMI的程序都有,有时间的可以自己下载下来玩一玩.


单片机源程序如下:
  1. /* Includes ------------------------------------------------------------------*/
  2. #include "stm32f1xx_hal.h"
  3. #include "dma.h"
  4. #include "usart.h"
  5. #include "gpio.h"

  6. /* USER CODE BEGIN Includes */

  7. /* USER CODE END Includes */

  8. /* Private variables ---------------------------------------------------------*/

  9. /* USER CODE BEGIN PV */
  10. /* Private variables ---------------------------------------------------------*/

  11. /* USER CODE END PV */

  12. /* Private function prototypes -----------------------------------------------*/
  13. void SystemClock_Config(void);
  14. void Error_Handler(void);

  15. /* USER CODE BEGIN PFP */
  16. /* Private function prototypes -----------------------------------------------*/

  17. /* USER CODE END PFP */

  18. /* USER CODE BEGIN 0 */

  19. /* USER CODE END 0 */

  20. int main(void)
  21. {

  22.   /* USER CODE BEGIN 1 */

  23.   /* USER CODE END 1 */

  24.   /* MCU Configuration----------------------------------------------------------*/

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

  27.   /* Configure the system clock */
  28.   SystemClock_Config();

  29.   /* Initialize all configured peripherals */
  30.   MX_GPIO_Init();
  31.   MX_DMA_Init();
  32.   MX_USART1_UART_Init();

  33.   /* USER CODE BEGIN 2 */
  34.         HAL_UART_Receive_DMA(&huart1, UsartType.RX_pData, RX_LEN);  
  35.         __HAL_UART_ENABLE_IT(&huart1, UART_IT_IDLE);

  36.   /* USER CODE END 2 */

  37.   /* Infinite loop */
  38.   /* USER CODE BEGIN WHILE */
  39.   while (1)
  40.   {
  41.   /* USER CODE END WHILE */

  42.   /* USER CODE BEGIN 3 */
  43.                         if(UsartType.RX_flag)            // Receive flag
  44.                         {  
  45.                                         UsartType.RX_flag=0;        // clean flag
  46.                                         HAL_UART_Transmit(&huart1, "123", 3, 0xFFFF);
  47.                         }
  48.   }
  49.   /* USER CODE END 3 */

  50. }

  51. /** System Clock Configuration
  52. */
  53. void SystemClock_Config(void)
  54. {

  55.   RCC_OscInitTypeDef RCC_OscInitStruct;
  56.   RCC_ClkInitTypeDef RCC_ClkInitStruct;

  57.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  58.   RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  59.   RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV5;
  60.   RCC_OscInitStruct.Prediv1Source = RCC_PREDIV1_SOURCE_PLL2;
  61.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  62.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  63.   RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
  64.   RCC_OscInitStruct.PLL2.PLL2State = RCC_PLL2_ON;
  65.   RCC_OscInitStruct.PLL2.PLL2MUL = RCC_PLL2_MUL8;
  66.   RCC_OscInitStruct.PLL2.HSEPrediv2Value = RCC_HSE_PREDIV2_DIV5;
  67.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  68.   {
  69.     Error_Handler();
  70.   }

  71.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  72.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  73.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  74.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  75.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  76.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  77.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  78.   {
  79.     Error_Handler();
  80.   }

  81.   HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

  82.   HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

  83.   __HAL_RCC_PLLI2S_ENABLE();

  84.   /* SysTick_IRQn interrupt configuration */
  85.   HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
  86. }

  87. /* USER CODE BEGIN 4 */

  88. /* USER CODE END 4 */

  89. /**
  90.   * @brief  This function is executed in case of error occurrence.
  91.   * @param  None
  92.   * @retval None
  93.   */
  94. void Error_Handler(void)
  95. {
  96.   /* USER CODE BEGIN Error_Handler */
  97.   /* User can add his own implementation to report the HAL error return state */
  98.   while(1)
  99.   {
  100.   }
  101.   /* USER CODE END Error_Handler */
  102. }

  103. #ifdef USE_FULL_ASSERT

  104. /**
  105.    * @brief Reports the name of the source file and the source line number
  106.    * where the assert_param error has occurred.
  107.    * @param file: pointer to the source file name
  108.    * @param line: assert_param error line source number
  109.    * @retval None
  110.    */
  111. void assert_failed(uint8_t* file, uint32_t line)
  112. {
  113.   /* USER CODE BEGIN 6 */
  114.   /* User can add his own implementation to report the file name and line number,
  115.     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  116.   /* USER CODE END 6 */

  117. }

  118. #endif

  119. /**
  120.   * @}
  121.   */

  122. /**
  123.   * @}
  124. */

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

所有资料51hei提供下载:
收发.rar (3.36 MB, 下载次数: 119)



评分

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

查看全部评分

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

使用道具 举报

沙发
ID:1 发表于 2018-11-2 02:43 | 只看该作者
好资料,51黑有你更精彩!!!
回复

使用道具 举报

板凳
ID:1 发表于 2018-11-2 02:43 | 只看该作者
好资料,51黑有你更精彩!!!
回复

使用道具 举报

地板
ID:596488 发表于 2019-8-7 17:23 | 只看该作者
感谢楼主的无私分享
回复

使用道具 举报

5#
ID:620291 发表于 2020-1-1 20:04 | 只看该作者

感谢楼主的无私分享
回复

使用道具 举报

6#
ID:680133 发表于 2020-1-3 00:21 | 只看该作者
最好五寸以上屏使用,就可以装在机械上了。
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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