西电2022年A测(线上)题目
文章目录二,运行工程文件,获取HEX可执行文件 3.运行得到可执行文件 三,仿真四,根据学号更改自己的温度阈值
前言
这道A测题目老师在文档中已经给出了大部分代码,(不过是图片),我已经把代码,仿真电路都整理完毕,这篇文章主要帮助大家配置环境以及更换自己学号相关联的温度阈值 。
祝大家毕业顺利!
一、Keil5的安装 1.获取安装包
首先你需要一个Keil5的安装包百度云连接:
提取码: 0mo9
2.安装Keil5
上述链接中,有两个文件,先运行.EXE,一切按照默认进行,老师发的文件好像也有一个安装包,两个都可以使用,按照老师的教程可以完成此步骤 。
看这个也行:的博客
【基于 stm32f103 芯片的直流电机驱动控制仿真系统】3.运行注册机
见2中的链接博客 。
4.安装器件库
老师源文件的器材库不太对火,我重新搞了一个,链接如下:
百度网盘链接:
提取码 s51v,
内含两个器件库,一个ARM的,一个的 。直接双击就可以安装 。
我们的实验是在上进行的,故而需要我发送的第二个库 。
文章插图
至此,keil5安装完成 。
二,运行工程文件,获取HEX可执行文件 1,获取工程文件
完整的工程文件链接如下:基于芯片的直流电机驱动控制仿真系统工程文件全套
其中main函数如下:其实你仅需要将老师的工程文件中的main函数做一个替换 。(如果你跑不起来,可以参考上面的文件)
/* USER CODE BEGIN Header *//********************************************************************************* @file: main.c* @brief: Main program body******************************************************************************* @attention** © Copyright (c) 2020 STMicroelectronics.* All rights reserved.** This software component is licensed by ST under BSD 3-Clause license,* the "License"; You may not use this file except in compliance with the* License. You may obtain a copy of the License at:*opensource.org/licenses/BSD-3-Clause********************************************************************************//* USER CODE END Header *//* Includes ------------------------------------------------------------------*/#include "main.h"/* Private includes ----------------------------------------------------------*//* USER CODE BEGIN Includes */#include "stdio.h"#include "string.h"/* USER CODE END Includes *//* Private typedef -----------------------------------------------------------*//* USER CODE BEGIN PTD */#ifdef __GNUC__#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)#else#define PUTCHAR_PROTOTYPE int fputc(int ch,FILE *f)#endif/* USER CODE END PTD *//* Private define ------------------------------------------------------------*//* USER CODE BEGIN PD */#define DS18B20_DQ_HHAL_GPIO_WritePin(GPIOA,GPIO_PIN_11,GPIO_PIN_SET)#define DS18B20_DQ_LHAL_GPIO_WritePin(GPIOA,GPIO_PIN_11,GPIO_PIN_RESET)#define DS18B20_DQ_ReadPinHAL_GPIO_ReadPin(GPIOA,GPIO_PIN_11)#define DIR_ReadPinHAL_GPIO_ReadPin(GPIOA,GPIO_PIN_8)#define DIR_HHAL_GPIO_WritePin(GPIOA,GPIO_PIN_0,GPIO_PIN_SET)#define DIR_LHAL_GPIO_WritePin(GPIOA,GPIO_PIN_0,GPIO_PIN_RESET)#define PWM_HHAL_GPIO_WritePin(GPIOA,GPIO_PIN_1,GPIO_PIN_SET)#define PWM_LHAL_GPIO_WritePin(GPIOA,GPIO_PIN_1,GPIO_PIN_RESET)/* USER CODE END PD *//* Private macro -------------------------------------------------------------*//* USER CODE BEGIN PM *//* USER CODE END PM *//* Private variables ---------------------------------------------------------*/TIM_HandleTypeDef htim3;UART_HandleTypeDef huart1;/* USER CODE BEGIN PV */uint8_t const table1[]="Temp=";uint8_t const table2[]="DC Motor opened";uint8_t const table3[]="DC Motor closed";char buff[16];/* USER CODE END PV *//* Private function prototypes -----------------------------------------------*/void SystemClock_Config(void);static void MX_GPIO_Init(void);static void MX_TIM3_Init(void);static void MX_USART1_UART_Init(void);void Deplay_us(uint16_t us);void DS18B20_DQ_DDR(uint8_t ddr);uint8_t DS18B20_Rbit(void);uint8_t DS18B20_Rbyte(void);void DS18B20_Wbyte(uint8_t xbyte);void DS18B20_Reset(void);short DS18B20_Get_Temp(void);/* USER CODE BEGIN PFP *//* USER CODE END PFP *//* Private user code ---------------------------------------------------------*//* USER CODE BEGIN 0 */PUTCHAR_PROTOTYPE{HAL_UART_Transmit(&huart1,(uint8_t*)&ch,1,0xFFFF);return ch;}/* USER CODE END 0 *//*** @briefThe application entry point.* @retval int*/int main(void){/* USER CODE BEGIN 1 */int8_t temp;/* USER CODE END 1 *//* MCU Configuration--------------------------------------------------------*//* Reset of all peripherals, Initializes the Flash interface and the Systick. */HAL_Init();/* USER CODE BEGIN Init *//* USER CODE END Init *//* Configure the system clock */SystemClock_Config();/* USER CODE BEGIN SysInit *//* USER CODE END SysInit *//* Initialize all configured peripherals */MX_GPIO_Init();MX_TIM3_Init();MX_USART1_UART_Init();/* USER CODE BEGIN 2 */DS18B20_Get_Temp();printf("Testing OK\r");HAL_Delay(800);/* USER CODE END 2 *//* Infinite loop *//* USER CODE BEGIN WHILE */while (1){/* USER CODE END WHILE *//* USER CODE BEGIN 3 */HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_12);temp=DS18B20_Get_Temp();sprintf(&buff[0],"Temp=%dCCCW",temp);printf("%s\r",buff);if(temp > 28.3){printf("%s\r",table2);PWM_H;HAL_Delay(30);PWM_L;HAL_Delay(70);}else{printf("%s\r",table3);PWM_H;HAL_Delay(100);}}}/* USER CODE END 3 *//*** @brief System Clock Configuration* @retval None*/void SystemClock_Config(void){RCC_OscInitTypeDef RCC_OscInitStruct = {0};RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};/** Initializes the RCC Oscillators according to the specified parameters* in the RCC_OscInitTypeDef structure.*/RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;RCC_OscInitStruct.HSEState = RCC_HSE_ON;RCC_OscInitStruct.HSEPredivValue = http://www.kingceram.com/post/RCC_HSE_PREDIV_DIV1;RCC_OscInitStruct.HSIState = RCC_HSI_ON;RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK){Error_Handler();}/** Initializes the CPU, AHB and APB buses clocks*/RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK){Error_Handler();}}/*** @brief TIM3 Initialization Function* @param None* @retval None*/static void MX_TIM3_Init(void){/* USER CODE BEGIN TIM3_Init 0 *//* USER CODE END TIM3_Init 0 */TIM_ClockConfigTypeDef sClockSourceConfig = {0};TIM_MasterConfigTypeDef sMasterConfig = {0};/* USER CODE BEGIN TIM3_Init 1 *//* USER CODE END TIM3_Init 1 */htim3.Instance = TIM3;htim3.Init.Prescaler = 72-1;htim3.Init.CounterMode = TIM_COUNTERMODE_UP;htim3.Init.Period = 5000;htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;if (HAL_TIM_Base_Init(&htim3) != HAL_OK){Error_Handler();}sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;if (HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig) != HAL_OK){Error_Handler();}sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK){Error_Handler();}/* USER CODE BEGIN TIM3_Init 2 *//* USER CODE END TIM3_Init 2 */}/*** @brief USART1 Initialization Function* @param None* @retval None*/static void MX_USART1_UART_Init(void){/* USER CODE BEGIN USART1_Init 0 *//* USER CODE END USART1_Init 0 *//* USER CODE BEGIN USART1_Init 1 *//* USER CODE END USART1_Init 1 */huart1.Instance = USART1;huart1.Init.BaudRate = 19200;huart1.Init.WordLength = UART_WORDLENGTH_8B;huart1.Init.StopBits = UART_STOPBITS_1;huart1.Init.Parity = UART_PARITY_NONE;huart1.Init.Mode = UART_MODE_TX_RX;huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;huart1.Init.OverSampling = UART_OVERSAMPLING_16;if (HAL_UART_Init(&huart1) != HAL_OK){Error_Handler();}/* USER CODE BEGIN USART1_Init 2 *//* USER CODE END USART1_Init 2 */}/*** @brief GPIO Initialization Function* @param None* @retval None*/static void MX_GPIO_Init(void){GPIO_InitTypeDef GPIO_InitStruct = {0};/* GPIO Ports Clock Enable */__HAL_RCC_GPIOD_CLK_ENABLE();__HAL_RCC_GPIOA_CLK_ENABLE();/*Configure GPIO pin Output Level */HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_11|GPIO_PIN_12, GPIO_PIN_RESET);/*Configure GPIO pins : PA0 PA1 PA11 PA12 */GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_11|GPIO_PIN_12;GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;GPIO_InitStruct.Pull = GPIO_NOPULL;GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);}/* USER CODE BEGIN 4 *//* USER CODE END 4 *//*** @briefThis function is executed in case of error occurrence.* @retval None*/void Error_Handler(void){/* USER CODE BEGIN Error_Handler_Debug *//* User can add his own implementation to report the HAL error return state *//* USER CODE END Error_Handler_Debug */}void Delay_us(uint16_t us){uint16_t differ=0xffff-us-5;__HAL_TIM_SET_COUNTER(&htim3,differ);HAL_TIM_Base_Start(&htim3);while(differ
- 电机驱控芯片:TMC5160介绍与使用
- 基于QR分解迭代求解方阵特征值和特征向量
- 48K到16K 基于C语言实现PCM音频流或音频文件重采样
- fifo2mig_axi 基于 DDR3 的串口传图帧缓存系统设计实现
- 干货!基于部分-整体关系的概念、关系和物理场景认知推理
- 芯片+步进电机档位控制实验
- ORIN/征程5/骁龙/ARM 盘一盘现有主流车规级芯片
- 智能控制技术_基于Matlab的二阶系统模糊控制仿真实例_课程学习
- 基于FPGA的串口传图SRAM缓存VGA显示
- Matlab代码实现 【sop】基于灵敏度分析的有源配电网智能软开关优化配置