【STM32G431RBTx】备战蓝桥杯嵌入式→决赛试题→第十四届

文章目录

    • 前言
    • 一、题目
    • 二、模块初始化
    • 三、代码实现
      • interrupt.h:
      • interrupt.c:
      • main.h:
      • main.c:
    • 四、完成效果
    • 五、总结

前言

一、题目

二、模块初始化

三、代码实现

bsp组中共有
【STM32G431RBTx】备战蓝桥杯嵌入式→决赛试题→第十四届_第1张图片

interrupt.h:

#ifndef __INTERRUPT_H__
#define __INTERRUPT_H__	

#include "main.h"
#include "stdbool.h"

struct keys
{
	unsigned char key_judge;
	bool key_sta;
	bool single_flag;
	unsigned int key_time;
	bool long_flag;
};

#endif

interrupt.c:

#include "interrupt.h"
#include "tim.h"
#include "lcd.h"
#include "stdio.h"
#include "badc.h"
#include "adc.h"
struct keys key[4] = {0, 0, 0, 0, 0};

extern unsigned int FreStore[1000];
extern unsigned int DutyStore[1000];
extern double AdcVoltStore[1000];
extern unsigned int StoreIndex;
extern unsigned int HaveStored;
extern unsigned int adc2;
extern unsigned char keylock;
extern double DutyOut[1000];
extern unsigned int outIndex;
extern unsigned char fsetMode;
unsigned int HaveOut = 0;
extern unsigned int FP;
char tex[30];
extern unsigned char LD1tick;
extern unsigned char LD2tick;
extern unsigned char LD3tick;
extern unsigned char LD1shouldFlash;
extern unsigned char LD2shouldFlash;
extern unsigned char LD3shouldFlash;
extern unsigned char LED;
extern unsigned int Ttick;
extern unsigned char should_get_T;

/* Captured Values */
uint32_t uwIC2Value1_T2CH2 = 0;
uint32_t uwIC2Value2_T2CH2 = 0;
uint32_t uwHighCapture_T2CH2 = 0;
uint32_t uwLowCapture_T2CH2 = 0;
/* Capture index */
uint16_t uhCaptureIndex_T2CH2 = 0;

/* Frequency Value */
uint32_t uwFrequency_T2CH2 = 0;
double uwDuty_T2CH2 = 0;

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef * htim)
{
	if(htim->Instance == TIM4)
	{
		key[0].key_sta = HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_0);
		key[1].key_sta = HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_1);
		key[2].key_sta = HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_2);
		key[3].key_sta = HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0);
		for(unsigned char i = 0; i < 4; i++)
		{
			switch(key[i].key_judge)
			{
				case 0:
				{
					if(key[i].key_sta == 0)
					{
						key[i].key_judge = 1;
						key[i].key_time = 0;
					}
					break;
				}
				case 1:
				{
					if(key[i].key_sta == 0)
					{
						key[i].key_judge = 2;
					}
					else
					{
						key[i].key_judge = 0;
					}
					break;
				}
				case 2:
				{
					if(key[i].key_sta == 1)
					{
						key[i].key_judge = 0;
						if(key[i].key_time <= 200)
						{
							key[i].single_flag = 1;
						}
					}
					else
					{
						key[i].key_time++;
						if(key[i].key_time > 200)
						{
							key[i].long_flag = 1;
						}
					}
				}
			}
		}
		if(should_get_T == 0)
		{
			Ttick++;
			if(Ttick == 25)
			{
				should_get_T = 1;
				Ttick = 0;
			}
		}
	}
	if(htim->Instance == TIM6)
	{
		FreStore[HaveStored] = uwFrequency_T2CH2;
		DutyStore[HaveStored] = (unsigned int)uwDuty_T2CH2;
		AdcVoltStore[HaveStored] = adc2 * 3.3 / 4096.0;
		HaveStored++;
		if(HaveStored == StoreIndex)
		{
			HaveStored = 0;
			keylock = 0;
			HAL_TIM_Base_Stop_IT(htim);
		}
	}
	if(htim->Instance == TIM7)
	{
		if(fsetMode == PULS)
		{
			__HAL_TIM_SET_COMPARE(&htim17, TIM_CHANNEL_1, DutyStore[HaveOut]);
			__HAL_TIM_SET_PRESCALER(&htim17, 80000000 / 100 / (FreStore[HaveOut] / FP));
			HaveOut++;
			if(HaveOut == outIndex)
			{
				HaveOut = 0;
				fsetMode = 0;
				HAL_TIM_Base_Stop_IT(htim);
				HAL_TIM_PWM_Stop(&htim17, TIM_CHANNEL_1);
			}
		}
		if(fsetMode == VOLT)
		{
			__HAL_TIM_SET_COMPARE(&htim17, TIM_CHANNEL_1,DutyOut[HaveOut]);
			__HAL_TIM_SET_PRESCALER(&htim17, 80000000 / 100 / 1000);
			HaveOut++;
			if(HaveOut == outIndex)
			{
				HaveOut = 0;
				fsetMode = 0;
				HAL_TIM_Base_Stop_IT(htim);
				HAL_TIM_PWM_Stop(&htim17, TIM_CHANNEL_1);
			}
		}
	}
	if(htim->Instance == TIM16)
	{
		if(LD1shouldFlash)
		{
			LD1tick++;
			if(LD1tick == 100)
			{
				LED ^= 0x01;
				LD1tick = 0;
			}
		}
		if(LD2shouldFlash)
		{
			LD2tick++;
			if(LD2tick == 100)
			{
				LED ^= 0x02;
				LD2tick = 0;
			}
		}
		if(LD3shouldFlash)
		{
			LD3tick++;
			if(LD3tick == 100)
			{
				LED ^= 0x04;
				LD3tick = 0;
			}
		}
	}
}








void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{
	if(htim->Instance == TIM2)
	{
		if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_2)
		{
			if(uhCaptureIndex_T2CH2 == 0)
			{
				/* Get the 1st Input Capture value */
				uwIC2Value1_T2CH2 = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_2);
				__HAL_TIM_SET_CAPTUREPOLARITY(htim, TIM_CHANNEL_2, TIM_INPUTCHANNELPOLARITY_FALLING);
				uhCaptureIndex_T2CH2 = 1;
			}
			else if(uhCaptureIndex_T2CH2 == 1)
			{
				/* Get the 2nd Input Capture value */
				uwIC2Value2_T2CH2 = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_2); 
				__HAL_TIM_SET_CAPTUREPOLARITY(htim, TIM_CHANNEL_2, TIM_INPUTCHANNELPOLARITY_RISING);
				/* Capture computation */
				if (uwIC2Value2_T2CH2 > uwIC2Value1_T2CH2)
				{
					uwHighCapture_T2CH2 = (uwIC2Value2_T2CH2 - uwIC2Value1_T2CH2); 
				}
				else if (uwIC2Value2_T2CH2 < uwIC2Value1_T2CH2)
				{
					/* 0xFFFF is max TIM1_CCRx value */
					uwHighCapture_T2CH2 = ((0xFFFFFFFF - uwIC2Value1_T2CH2) + uwIC2Value2_T2CH2) + 1;
				}
				else
				{
					/* If capture values are equal, we have reached the limit of frequency
						 measures */
					Error_Handler();
				}
				uwIC2Value1_T2CH2 = uwIC2Value2_T2CH2;
				uhCaptureIndex_T2CH2 = 2;
				/* Frequency computation: for this example TIMx (TIM1) is clocked by
					 APB2Clk */      

			}
			else if(uhCaptureIndex_T2CH2 == 2)
			{
				uwIC2Value2_T2CH2 = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_2);
				if (uwIC2Value2_T2CH2 > uwIC2Value1_T2CH2)
				{
					uwLowCapture_T2CH2 = (uwIC2Value2_T2CH2 - uwIC2Value1_T2CH2); 
				}
				else if (uwIC2Value2_T2CH2 < uwIC2Value1_T2CH2)
				{
					/* 0xFFFF is max TIM1_CCRx value */
					uwLowCapture_T2CH2 = ((0xFFFFFFFF - uwIC2Value1_T2CH2) + uwIC2Value2_T2CH2) + 1;
				}
				uwFrequency_T2CH2 = 1000000 / (uwLowCapture_T2CH2 + uwHighCapture_T2CH2);
				uwDuty_T2CH2 = uwHighCapture_T2CH2 * 100.0 / (uwLowCapture_T2CH2 + uwHighCapture_T2CH2);
				uhCaptureIndex_T2CH2 = 0;
			}
		}
	}
}

main.h:

/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.h
  * @brief          : Header for main.c file.
  *                   This file contains the common defines of the application.
  ******************************************************************************
  * @attention
  *
  * 

© Copyright (c) 2023 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 */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __MAIN_H #define __MAIN_H #ifdef __cplusplus extern "C" { #endif /* Includes ------------------------------------------------------------------*/ #include "stm32g4xx_hal.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ /* Exported types ------------------------------------------------------------*/ /* USER CODE BEGIN ET */ /* USER CODE END ET */ /* Exported constants --------------------------------------------------------*/ /* USER CODE BEGIN EC */ /* USER CODE END EC */ /* Exported macro ------------------------------------------------------------*/ /* USER CODE BEGIN EM */ /* USER CODE END EM */ /* Exported functions prototypes ---------------------------------------------*/ void Error_Handler(void); /* USER CODE BEGIN EFP */ /* USER CODE END EFP */ /* Private defines -----------------------------------------------------------*/ /* USER CODE BEGIN Private defines */ #define DATA 0 #define PARA 1 #define RECD 2 #define FSET 3 #define VOLT 1 #define PULS 2 /* USER CODE END Private defines */ #ifdef __cplusplus } #endif #endif /* __MAIN_H */

main.c:

/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @attention
  *
  * 

© Copyright (c) 2023 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" #include "adc.h" #include "tim.h" #include "gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include "led.h" #include "interrupt.h" #include "lcd.h" #include "badc.h" #include "stdio.h" #include "ds18b20.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN PTD */ /* USER CODE END PTD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ extern struct keys key[4]; unsigned int adc2; char text[30]; double Temperature; extern uint32_t uwFrequency_T2CH2; extern double uwDuty_T2CH2; unsigned char DisplayMode; unsigned int FH = 2000; double AH = 3.0; unsigned int TH = 30; unsigned int FHtemp = 2000; double AHtemp = 3.0; unsigned int THtemp = 30; unsigned int FN; unsigned int AN; unsigned int TN; unsigned int FP = 1; double VP = 0.9; unsigned int TT = 6; unsigned int FPtemp = 1; double VPtemp = 0.9; unsigned int TTtemp = 6; unsigned char TemperatureOverFlag; unsigned char AdcOverFlag; unsigned char FreOverFlag; unsigned char keylock; unsigned int FreStore[1000] = {0}; unsigned int DutyStore[1000] = {0}; double AdcVoltStore[1000] = {0}; unsigned char DutyOut[1000] = {0}; unsigned int StoreIndex; unsigned int HaveStored; unsigned char SettingIndex; unsigned char LCD_Should_Clear; double k; double b; unsigned char fset_should_begin; unsigned int outIndex; unsigned char fsetMode; unsigned char LED; unsigned char LD1tick; unsigned char LD2tick; unsigned char LD3tick; unsigned char LD1shouldFlash; unsigned char LD2shouldFlash; unsigned char LD3shouldFlash; unsigned int Ttick; unsigned char should_get_T; /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); /* USER CODE BEGIN PFP */ void DisposeKey(void); void LCD_Disp(void); void JudgeIsOverPara(void); unsigned char Volt2Duty(double volt); void LED_Control(void); /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ /** * @brief The application entry point. * @retval int */ int main(void) { /* USER CODE BEGIN 1 */ /* 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_TIM4_Init(); MX_ADC2_Init(); MX_TIM2_Init(); MX_TIM17_Init(); MX_ADC1_Init(); MX_TIM6_Init(); MX_TIM7_Init(); MX_TIM16_Init(); /* USER CODE BEGIN 2 */ while((unsigned char)(ds18b20_read()) == 85) { if(uwTick > 750) break; } HAL_TIM_Base_Start_IT(&htim4); HAL_TIM_Base_Start_IT(&htim16); HAL_TIM_IC_Start_IT(&htim2, TIM_CHANNEL_2); HAL_TIM_PWM_Stop(&htim17, TIM_CHANNEL_1); adc2 = getADC(&hadc2); LCD_Init(); LCD_Clear(Black); LCD_SetBackColor(Black); LCD_SetTextColor(White); adc2 = getADC(&hadc2); if(Temperature > TH) { TemperatureOverFlag = 1; } else { TemperatureOverFlag = 0; } if(adc2 * 3.3 / 4096 > AH) { AdcOverFlag = 1; } else { AdcOverFlag = 0; } if(uwFrequency_T2CH2 > FH) { FreOverFlag = 1; } else { FreOverFlag = 0; } LED_Disp(0X00); // HAL_TIM_PWM_Start(&htim17, TIM_CHANNEL_1); // __HAL_TIM_SET_COMPARE(&htim17, TIM_CHANNEL_1,50); // __HAL_TIM_SET_PRESCALER(&htim17, 80000000 / 100 / 1000); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ adc2 = getADC(&hadc2); HAL_TIM_IC_Stop_IT(&htim2, TIM_CHANNEL_2); if(should_get_T) { Temperature = ds18b20_read(); should_get_T = 0; } HAL_TIM_IC_Start_IT(&htim2, TIM_CHANNEL_2); DisposeKey(); JudgeIsOverPara(); LCD_Disp(); LED_Control(); LED_Disp(LED); } /* USER CODE END 3 */ } /** * @brief System Clock Configuration * @retval None */ void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; /** Configure the main internal regulator output voltage */ HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1); /** 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.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV3; RCC_OscInitStruct.PLL.PLLN = 20; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2; RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2; 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_DIV1; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) { Error_Handler(); } } /* USER CODE BEGIN 4 */ void DisposeKey(void) { if(key[0].single_flag) { if(!keylock) { LCD_Clear(Black); DisplayMode++; DisplayMode %= 4; if(DisplayMode == PARA) SettingIndex = 0; if(DisplayMode == FSET) SettingIndex = 0; } key[0].single_flag = 0; } if(key[1].single_flag) { if(!keylock) { if(DisplayMode == DATA) { keylock = 1; StoreIndex = TT * 100; HaveStored = 0; HAL_TIM_Base_Start_IT(&htim6); } if(DisplayMode == PARA) { SettingIndex++; SettingIndex %= 3; } if(DisplayMode == FSET) { SettingIndex++; SettingIndex %= 3; } if(DisplayMode == RECD) { TN = 0; AN = 0; FN = 0; } } key[1].single_flag = 0; } if(key[2].single_flag) { if(!keylock) { if(DisplayMode == PARA) { if(SettingIndex == 0) { FHtemp += 1000; if(FHtemp == 11000) FHtemp = 10000; } if(SettingIndex == 1) { AHtemp += 0.3; if((int)(AHtemp * 10) == 36) AHtemp = 3.3; } if(SettingIndex == 2) { THtemp++; if(THtemp == 81) THtemp = 80; } } if(DisplayMode == FSET) { if(SettingIndex == 0) { FPtemp++; if(FPtemp == 11) FPtemp = 10; } if(SettingIndex == 1) { VPtemp += 0.3; if((int)(VPtemp * 10) == 36) VPtemp = 3.3; } if(SettingIndex == 2) { TTtemp += 2; if(TTtemp == 12) TTtemp = 10; } } if(DisplayMode == DATA) { if(fsetMode == 0) { fsetMode = VOLT; outIndex = StoreIndex; for(unsigned int i = 0; i < StoreIndex; i++) { DutyOut[i] = (unsigned char)(Volt2Duty(AdcVoltStore[i])); } HAL_TIM_Base_Start_IT(&htim7); HAL_TIM_PWM_Start(&htim17, TIM_CHANNEL_1); } } } key[2].single_flag = 0; } if(key[3].single_flag) { if(!keylock) { if(DisplayMode == PARA) { if(SettingIndex == 0) { FHtemp -= 1000; if(FHtemp == 0) FHtemp = 1000; } if(SettingIndex == 1) { AHtemp -= 0.3; if(AHtemp * 10 < 0) AHtemp = 0.0; } if(SettingIndex == 2) { THtemp--; if(THtemp == 0xffffffff) THtemp = 0; } } if(DisplayMode == FSET) { if(SettingIndex == 0) { FPtemp--; if(FPtemp == 0) FPtemp = 1; } if(SettingIndex == 1) { VPtemp -= 0.3; if((int)(VP * 10) < 0) VPtemp = 0.0; } if(SettingIndex == 2) { TTtemp -= 2; if(TTtemp == 0) TTtemp = 2; } } if(DisplayMode == DATA) { if(fsetMode == 0) { fsetMode = PULS; outIndex = StoreIndex; HAL_TIM_Base_Start_IT(&htim7); HAL_TIM_PWM_Start(&htim17, TIM_CHANNEL_1); } } } key[3].single_flag = 0; } if(key[3].long_flag) { if(key[2].long_flag) { if(DisplayMode != DATA) LCD_Clear(Black); DisplayMode = DATA; FH = 2000; AH = 3.0; TH = 30; FP = 1; VP = 0.9; TT = 6; AN = 0; FN = 0; TN = 0; key[2].long_flag = 0; } key[3].long_flag = 0; } if(key[2].long_flag) { if(key[3].long_flag) { if(DisplayMode != DATA) LCD_Clear(Black); DisplayMode = DATA; FH = 2000; AH = 3.0; TH = 30; FP = 1; VP = 0.9; TT = 6; AN = 0; FN = 0; TN = 0; key[3].long_flag = 0; } key[2].long_flag = 0; } } void LCD_Disp(void) { if(DisplayMode == DATA) { LCD_DisplayStringLine(Line1, " DATA"); sprintf(text, " F=%d ", uwFrequency_T2CH2); LCD_DisplayStringLine(Line3, text); sprintf(text, " D=%d%% ", (unsigned int)uwDuty_T2CH2); LCD_DisplayStringLine(Line4, text); sprintf(text, " A=%.1f", adc2 * 3.3 / 4096); LCD_DisplayStringLine(Line5, text); sprintf(text, " T=%.1f ", Temperature); LCD_DisplayStringLine(Line6, text); FP = FPtemp; VP = VPtemp; TT = TTtemp; } else if(DisplayMode == PARA) { LCD_DisplayStringLine(Line1, " PARA"); sprintf(text, " FH=%d ", FHtemp); LCD_DisplayStringLine(Line3, text); sprintf(text, " AH=%.1f", AHtemp); LCD_DisplayStringLine(Line4, text); sprintf(text, " TH=%d ", THtemp); LCD_DisplayStringLine(Line5, text); } else if(DisplayMode == RECD) { LCD_DisplayStringLine(Line1, " RECD"); sprintf(text, " FN=%d ", FN); LCD_DisplayStringLine(Line3, text); sprintf(text, " AN=%d ", AN); LCD_DisplayStringLine(Line4, text); sprintf(text, " TN=%d ", TN); LCD_DisplayStringLine(Line5, text); FH = FHtemp; AH = AHtemp; TH = THtemp; } else if(DisplayMode == FSET) { LCD_DisplayStringLine(Line1, " FSET"); sprintf(text, " FP=%d ", FPtemp); LCD_DisplayStringLine(Line3, text); sprintf(text, " VP=%.1f", VPtemp); LCD_DisplayStringLine(Line4, text); sprintf(text, " TT=%d ", TTtemp); LCD_DisplayStringLine(Line5, text); } } void JudgeIsOverPara(void) { if(Temperature > TH) { if(TemperatureOverFlag == 0) { TN++; } TemperatureOverFlag = 1; } else { TemperatureOverFlag = 0; } if(adc2 * 3.3 / 4096 > AH) { if(AdcOverFlag == 0) { AN++; } AdcOverFlag = 1; } else { AdcOverFlag = 0; } if(uwFrequency_T2CH2 > FH) { if(FreOverFlag == 0) { FN++; } FreOverFlag = 1; } else { FreOverFlag = 0; } } unsigned char Volt2Duty(double volt) { unsigned char Duty; if(volt < VP) { Duty = 0; } else if(volt < 3.3) { k = (10 - 100) / (VP - 3.3); b = (-1 * k * 3.3) + 100; Duty = (unsigned char)(k * volt + b); } else { Duty = 100; } return Duty; } void LED_Control(void) { if(keylock == 1) { LD1shouldFlash = 1; } else { LD1tick = 0; LED &= ~0x01; } if(fsetMode == PULS) { LD2shouldFlash = 1; } else { LD2tick = 0; LED &= ~0x02; } if(fsetMode == VOLT) { LD3shouldFlash = 1; } else { LD3tick = 0; LED &= ~0x04; } if(uwFrequency_T2CH2 > FH) { LED |= 0x08; } else { LED &= ~0x08; } if(adc2 * 3.3 / 4096 > AH) { LED |= 0x10; } else { LED &= ~0x10; } if(Temperature > TH) { LED |= 0x20; } else { LED &= ~0x20; } } /* USER CODE END 4 */ /** * @brief This 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 */ __disable_irq(); while (1) { } /* USER CODE END Error_Handler_Debug */ } #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 CODE BEGIN 6 */ /* 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) */ /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */

四、完成效果

五、总结

本篇文章只是为了存放我的代码,所以看不懂很正常,如果需要代码可以找我私信。

你可能感兴趣的:(蓝桥杯,stm32,职场和发展)