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

news2024/11/23 5:09:05

文章目录

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

前言

一、题目

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

二、模块初始化

1.LCD这里不用配置,直接使用提供的资源包就行
2.ADC:开启ADCsingle-ended
3.LED:开启PC8-15,PD2输出模式就行了。
4.定时器:TIM3(按键消抖定时器):PSC:80-1,ARR:10000-1,TIM17(PWM输出定时器):PSC:80,ARR:65535,TIM2:80-1,ARR:0xffffffff
5.i2c:设置PB6,PB7为GPIO_Output模式即可
6.打开串口串行输出输入

三、代码实现

bsp组中共有:
在这里插入图片描述

interrupt.h:

#ifndef __INTERRUPT_H__
#define __INTERRUPT_H__

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

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

#endif

interrupt.c:

#include "interrupt.h"

struct keys key[4] = {0, 0, 0, 0, 0};

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef * htim)
{
	if(htim->Instance == TIM3)
	{
		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_time = 0;
						key[i].key_judge = 1;
					}
					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 <= 100)
						{
							key[i].single_flag = 1;
						}
						if(key[i].key_time > 100)
						{
							key[i].long_flag = 1;
						}
					}
					else
					{
						key[i].key_time++;
					}
					break;
				}
			}
		}
	}
}
/* Captured Values */
uint32_t uwIC2Value1_T2CH2 = 0;
uint32_t uwIC2Value2_T2CH2 = 0;
uint32_t uwLowCapture_T2CH2 = 0;
uint32_t uwHighCapture_T2CH2 = 0;
/* Capture index */
uint16_t uhCaptureIndex_T2CH2 = 0;

/* Frequency Value */
uint32_t uwFrequency_T2CH2 = 0;
double uwDuty_T2CH2 = 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();
				}
				uhCaptureIndex_T2CH2 = 2;
				uwIC2Value1_T2CH2 = uwIC2Value2_T2CH2;
				/* 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 / (uwHighCapture_T2CH2 + uwLowCapture_T2CH2);
				uwDuty_T2CH2 = uwHighCapture_T2CH2 * 100.0 / (uwHighCapture_T2CH2 + uwLowCapture_T2CH2);
				uhCaptureIndex_T2CH2 = 0;
			}
		}
	}
}

char RxBuffer[30];
unsigned char BufIndex = 0;
unsigned char Rxdat;

void HAL_UART_RxCpltCallback(UART_HandleTypeDef * huart)
{
	if(huart->Instance == USART1)
	{
		RxBuffer[BufIndex++] = Rxdat;
		HAL_UART_Receive_IT(huart, &Rxdat, 1);
	}
}

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 is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* 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 REC 2
#define REC_PA4 3
#define REC_PA5 4
#define MUL 0
#define DIV 1
/* 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 is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "adc.h"
#include "tim.h"
#include "usart.h"
#include "gpio.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "interrupt.h"
#include "lcd.h"
#include "stdio.h"
#include "i2c.h"
#include "dadc.h"
#include "stdlib.h"
#include "string.h"
#include "led.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 char eeprom_readData;
unsigned char eeprom_writeData;
char text[30];
extern uint32_t uwFrequency_T2CH2;
extern double uwDuty_T2CH2;
double PA4_Volt[1024] = {0}, PA5_Volt[1024] = {0};
unsigned char DisplayMode;
unsigned char REC_DisplayMode = REC_PA4;
unsigned char X = 1;
unsigned char Y = 1;
unsigned char outputMode = MUL;
unsigned int N_PA4;
unsigned int N_PA5;
double A_PA4 = 0;
double A_PA5 = 0;
double T_PA4 = 0;
double T_PA5 = 0;
double SUM_PA4 = 0;
double SUM_PA5 = 0;
double H_PA4 = 0;
double H_PA5 = 0;
extern char RxBuffer[30];
extern unsigned char BufIndex;
extern unsigned char Rxdat;
unsigned char ScanMode;
unsigned char LED;
unsigned int LEDtick;
/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP */
void DisposeKey(void);
void LCD_Disp(void);
void Rx_Proc(void);
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_ADC2_Init();
  MX_TIM2_Init();
  MX_TIM17_Init();
  MX_USART1_UART_Init();
  MX_TIM3_Init();
  /* USER CODE BEGIN 2 */
	LCD_Init();
	LCD_Clear(Black);
	LCD_SetBackColor(Black);
	LCD_SetTextColor(White);
	getDualADC(&hadc2);
	HAL_Delay(2);
	getDualADC(&hadc2);
	HAL_TIM_Base_Start_IT(&htim3);
	HAL_TIM_IC_Start_IT(&htim2, TIM_CHANNEL_2);
	
	if(eeprom_read(2) == 0x83 && eeprom_read(3) == 0x84 && eeprom_read(4) == 0x85) //²»ÊǵÚÒ»´Î
	{
		X = eeprom_read(1);
		Y = eeprom_read(0);
	}
	else
	{
		eeprom_write(1, X);
		HAL_Delay(10);
		eeprom_write(0, Y);
		HAL_Delay(10);
		eeprom_write(2, 0x83);
		HAL_Delay(10);
		eeprom_write(3, 0x84);
		HAL_Delay(10);
		eeprom_write(4, 0x85);
	}
	__HAL_TIM_SET_PRESCALER(&htim17, 80000000 / 100 / (uwFrequency_T2CH2 * X));
	HAL_TIM_PWM_Start_IT(&htim17, TIM_CHANNEL_1);
	HAL_UART_Receive_IT(&huart1, &Rxdat, 1);
	LED_Disp(0x00);
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
		if(BufIndex != 0)
		{
			unsigned char temp = BufIndex;
			HAL_Delay(1);
			if(temp == BufIndex)
				Rx_Proc();
		}
		DisposeKey();
		LCD_Disp();
		LED_Control();
		LED_Disp(LED);
//		sprintf(text, "%.2f%%", uwDuty_T2CH2);
//		LCD_DisplayStringLine(Line1, text);
//		sprintf(text, "%dHz", uwFrequency_T2CH2);
//		LCD_DisplayStringLine(Line2, text);
//		sprintf(text, "%.2f", adc2_in17_AO1 * 3.3 / 4096);
//		LCD_DisplayStringLine(Line3, text);
//		sprintf(text, "%.2f", adc2_in13_AO2 * 3.3 / 4096);
//		LCD_DisplayStringLine(Line4, text);
  }
  /* 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)
	{
		LCD_Clear(Black);
		DisplayMode++;
		DisplayMode %= 3;
		key[0].single_flag = 0;
	}
	if(key[1].single_flag)
	{
		if(DisplayMode==PARA)
		{
			X++;
			if(X==5)
				X = 1;
			if(outputMode == MUL)
				__HAL_TIM_SET_PRESCALER(&htim17, 80000000 / 100 / (uwFrequency_T2CH2 * X));
			else
				__HAL_TIM_SET_PRESCALER(&htim17, 80000000 / 100 / (uwFrequency_T2CH2 / X));
			eeprom_write(1, X);
		}
		key[1].single_flag = 0;
	}
	if(key[2].single_flag)
	{
		if(DisplayMode==PARA)
		{
			Y++;
			if(Y==5)
				Y = 1;
			eeprom_write(0, Y);
		}
		key[2].single_flag = 0;
	}
	if(key[3].single_flag)
	{
		if(DisplayMode == DATA)
		{
			getDualADC(&hadc2);
			if(N_PA4 + 1 <= 1000)
			{
				PA4_Volt[N_PA4] = adc2_in17_AO1 * 3.3 / 4096;
				N_PA4++;
				A_PA4 = PA4_Volt[0];
				for(unsigned int i = 0; i < N_PA4; i++)
				{
					if(A_PA4 < PA4_Volt[i])
					{
						A_PA4 = PA4_Volt[i];
					}
				}
				T_PA4 = PA4_Volt[0];
				for(unsigned int i = 0; i < N_PA4; i++)
				{
					if(T_PA4 > PA4_Volt[i])
					{
						T_PA4 = PA4_Volt[i];
					}
				}
				SUM_PA4 = 0;
				for(unsigned int i = 0; i < N_PA4; i++)
				{
					SUM_PA4 += PA4_Volt[i];
				}
				H_PA4 = SUM_PA4 / N_PA4;
			}
			else
			{
				for(unsigned int i = 0; i < 999; i++)
				{
					PA4_Volt[i] = PA4_Volt[i+1];
				}
				PA4_Volt[999] = adc2_in17_AO1 * 3.3 / 4096;
				A_PA4 = PA4_Volt[0];
				for(unsigned int i = 0; i < 1000; i++)
				{
					if(A_PA4 < PA4_Volt[i])
					{
						A_PA4 = PA4_Volt[i];
					}
				}
				T_PA4 = PA4_Volt[0];
				for(unsigned int i = 0; i < 1000; i++)
				{
					if(T_PA4 > PA4_Volt[i])
					{
						T_PA4 = PA4_Volt[i];
					}
				}
				SUM_PA4 = 0;
				for(unsigned int i = 0; i < 1000; i++)
				{
					SUM_PA4 += PA4_Volt[i];
				}
				H_PA4 = SUM_PA4 / N_PA4;
			}
			if(N_PA5 + 1 <= 1000)
			{
				PA5_Volt[N_PA5] = adc2_in13_AO2 * 3.3 / 4096;
				N_PA5++;
				A_PA5 = PA5_Volt[0];
				for(unsigned int i = 0; i < N_PA5; i++)
				{
					if(A_PA5 < PA5_Volt[i])
					{
						A_PA5 = PA5_Volt[i];
					}
				}
				T_PA5 = PA5_Volt[0];
				for(unsigned int i = 0; i < N_PA5; i++)
				{
					if(T_PA5 > PA5_Volt[i])
					{
						T_PA5 = PA5_Volt[i];
					}
				}
				SUM_PA5 = 0;
				for(unsigned int i = 0; i < N_PA5; i++)
				{
					SUM_PA5 += PA5_Volt[i];
				}
				H_PA5 = SUM_PA5 / N_PA5;
			}
			else
			{
				for(unsigned int i = 0; i < 999; i++)
				{
					PA5_Volt[i] = PA5_Volt[i+1];
				}
				PA5_Volt[999] = adc2_in13_AO2 * 3.3 / 4096;
				A_PA5 = PA5_Volt[0];
				for(unsigned int i = 0; i < 1000; i++)
				{
					if(A_PA5 < PA5_Volt[i])
					{
						A_PA5 = PA5_Volt[i];
					}
				}
				T_PA5 = PA5_Volt[0];
				for(unsigned int i = 0; i < 1000; i++)
				{
					if(T_PA5 > PA5_Volt[i])
					{
						T_PA5 = PA5_Volt[i];
					}
				}
				SUM_PA5 = 0;
				for(unsigned int i = 0; i < 1000; i++)
				{
					SUM_PA5 += PA5_Volt[i];
				}
				H_PA5 = SUM_PA5 / N_PA5;
			}
		}
		if(DisplayMode == PARA)
		{
			outputMode = !outputMode; 
			if(outputMode == MUL)
				__HAL_TIM_SET_PRESCALER(&htim17, 80000000 / 100 / (uwFrequency_T2CH2 * X));
			else
				__HAL_TIM_SET_PRESCALER(&htim17, 80000000 / 100 / (uwFrequency_T2CH2 / X));
		}
		if(DisplayMode == REC)
		{
			if(REC_DisplayMode == REC_PA4)
				REC_DisplayMode = REC_PA5;
			else if(REC_DisplayMode == REC_PA5)
				REC_DisplayMode = REC_PA4;
		}
		key[3].single_flag = 0;
	}
	if(key[3].long_flag)
	{
		if(DisplayMode == REC)
		{
			if(REC_DisplayMode == REC_PA4)
			{
				for(unsigned int i = 0; i < 1000; i++)
				{
					PA4_Volt[i] = 0;
				}
				N_PA4 = 0;
				A_PA4 = 0;
				T_PA4 = 0;
				H_PA4 = 0;
			}
			if(REC_DisplayMode == REC_PA5)
			{
				for(unsigned int i = 0; i < 1000; i++)
				{
					PA5_Volt[i] = 0;
				}
				N_PA5 = 0;
				A_PA5 = 0;
				T_PA5 = 0;
				H_PA5 = 0;
			}
		}
		key[3].long_flag = 0;
	}
}

void LCD_Disp(void)
{
	if(DisplayMode == DATA)
	{
		LCD_DisplayStringLine(Line1, "        DATA ");
		if(N_PA4 >= 1 && N_PA5 >= 1)
		{
			sprintf(text, "     PA4=%.2f", PA4_Volt[N_PA4 - 1]);
			LCD_DisplayStringLine(Line3, text);
			sprintf(text, "     PA5=%.2f", PA5_Volt[N_PA5 - 1]);
			LCD_DisplayStringLine(Line4, text);
		}
		else
		{
			sprintf(text, "     PA4=%.2f", PA4_Volt[0]);
			LCD_DisplayStringLine(Line3, text);
			sprintf(text, "     PA5=%.2f", PA5_Volt[0]);
			LCD_DisplayStringLine(Line4, text);
		}
		sprintf(text, "     PA1=%d     ", uwFrequency_T2CH2);
		LCD_DisplayStringLine(Line5, text);
	}
	if(DisplayMode == PARA)
	{
		LCD_DisplayStringLine(Line1, "        PARA");
		sprintf(text, "     X=%d", X);
		LCD_DisplayStringLine(Line3, text);
		sprintf(text, "     Y=%d", Y);
		LCD_DisplayStringLine(Line4, text);
	}
	if(DisplayMode == REC)
	{
		if(REC_DisplayMode == REC_PA4)
		{
			LCD_DisplayStringLine(Line1, "        REC-PA4");
			sprintf(text, "     N=%d", N_PA4);
			LCD_DisplayStringLine(Line3, text);
			sprintf(text, "     A=%.2f", A_PA4);
			LCD_DisplayStringLine(Line4, text);
			sprintf(text, "     T=%.2f", T_PA4);
			LCD_DisplayStringLine(Line5, text);
			sprintf(text, "     H=%.2f", H_PA4);
			LCD_DisplayStringLine(Line6, text);
		}
		if(REC_DisplayMode == REC_PA5)
		{
			LCD_DisplayStringLine(Line1, "        REC-PA5");
			sprintf(text, "     N=%d", N_PA5);
			LCD_DisplayStringLine(Line3, text);
			sprintf(text, "     A=%.2f", A_PA5);
			LCD_DisplayStringLine(Line4, text);
			sprintf(text, "     T=%.2f", T_PA5);
			LCD_DisplayStringLine(Line5, text);
			sprintf(text, "     H=%.2f", H_PA5);
			LCD_DisplayStringLine(Line6, text);
		}
	}
}

int fputc(int ch, FILE *f)
{
	HAL_UART_Transmit(&huart1, (unsigned char *)&ch, 1, HAL_MAX_DELAY);
	return ch;
}

void Rx_Proc(void)
{
	if(BufIndex == 1)
	{
		if(RxBuffer[0] == 'X')
			printf("X:%d\r\n", X);
		else if(RxBuffer[0] == 'Y')
			printf("Y:%d\r\n", Y);
		else if(RxBuffer[0] == '#')
		{
			LCD_Clear(Black);
			ScanMode = !ScanMode;
			if(ScanMode) //反向
			{
				LCD_WriteReg(R1, 0x0100); //垂直对称翻转
				LCD_WriteReg(R96, 0xA700); //水平对称翻转
			}
			else //正向
			{
				LCD_WriteReg(R1, 0x0000);
				LCD_WriteReg(R96, 0x2700);
			}

		}
	}
	if(BufIndex == 3)
	{
		if(RxBuffer[0] == 'P' && RxBuffer[1] == 'A')
		{
			if(RxBuffer[2] == '1')
				printf("PA1:%d\r\n", uwFrequency_T2CH2);
			else if(RxBuffer[2] == '4')
			{
				if(N_PA4)
				{
					printf("PA4:%.2f\r\n", PA4_Volt[N_PA4 - 1]);
				}
				else
				{
					printf("PA4:%.2f\r\n", PA4_Volt[0]);
				}
			}
			else if(RxBuffer[2] == '5')
			{
				if(N_PA4)
				{
					printf("PA5:%.2f\r\n", PA5_Volt[N_PA5 - 1]);
				}
				else
				{
					printf("PA5:%.2f\r\n", PA5_Volt[0]);
				}
			}
		}
	}
	memset(RxBuffer, 0, 30);
	BufIndex = 0;
}

void LED_Control(void)
{
	if(uwTick - LEDtick >= 100)
	{
		LEDtick = uwTick;
		if(PA4_Volt[N_PA4-1] > PA5_Volt[N_PA5-1] * Y)
		{
			LED ^= 0x04;
		}
	}
	if(outputMode == MUL)
	{
		LED |= 0x01;
		LED &= ~0x02;
	}
	else
	{
		LED &= ~0x01;
		LED |= 0x02;
	}
	if(ScanMode == 0)
	{
		LED |= 0x08;
	}
	else
	{
		LED &= ~0x08;
	}
}

/* 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 */

四、完成效果

蓝桥杯嵌入式第十三届国赛试题实现效果

五、总结

本篇文章只是为了存放我的代码,所以看不懂很正常,如果需要代码可以找我私信。
十三届考了LCD翻转是从未有过的,我是看了第十三届蓝桥杯嵌入式国赛真题(基于HAL库的巨简代码+超级详解)才明白的,大家也可以学习一下链接中文章的写法。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/560363.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

从前序与中序遍历序列构造二叉树(java)

从前序与中序遍历序列构造二叉树 leetcode 105 题-原题链接题目描述解题思路往期经典二叉树递归题目&#xff1a; leetcode 105 题-原题链接 从前序与中序遍历序列构造二叉树 题目描述 给定两个整数数组 preorder 和 inorder &#xff0c;其中 preorder 是二叉树的先序遍历&a…

【论文阅读系列】NWD-Based Model | 小目标检测新范式,抛弃IoU-Based暴力涨点(登顶SOTA) 计算机视觉

NWD-Based Model | 小目标检测新范式&#xff0c;抛弃IoU-Based暴力涨点(登顶SOTA) 计算机视觉 参考&#xff1a;博客1 知乎2 在这里进行纪录分享&#xff0c;这是有用的资料&#xff0c;避免之后再寻找相当麻烦。 小目标检测是一个非常具有挑战性的问题&#xff0c;因为小目…

监控易:信创工程,几十万台终端设备桌面集中监控运维方案​

监控易&#xff1a;信创工程&#xff0c;几十万台终端设备桌面集中监控运维方案 从2019年开始,我国因国际国内形势的迫切要求,在信息和网络安全方面启动 “安全可靠工程”,全面深入推进信创运维及相关产品国产化。时至今日&#xff0c;已取得令世人瞩目的成果。 过去&#xff…

learn_C_deep_14 (条件编译的基本使用与理解)

目录 条件编译 1.条件编译如何使用&#xff1f; 2.为何要有条件编译? 3. 条件编译都在哪些地方用? 条件编译 1.条件编译如何使用&#xff1f; C语言的条件编译是一种在程序编译时根据条件选择不同代码段进行编译的技术。条件编译可以用于实现代码跨平台&#xff0c;开启…

C++小知识点(auto关键字)

&#x1f339;作者:云小逸 &#x1f4dd;个人主页:云小逸的主页 &#x1f4dd;Github:云小逸的Github &#x1f91f;motto:要敢于一个人默默的面对自己&#xff0c;强大自己才是核心。不要等到什么都没有了&#xff0c;才下定决心去做。种一颗树&#xff0c;最好的时间是十年前…

猿创征文|Spring系列框架之面向切面编程AOP

⭐️前面的话⭐️ 本篇文章将介绍一种特别重要的思想&#xff0c;AOP&#xff08;Aspect Oriented Programming&#xff09;&#xff0c;即面向切面编程&#xff0c;可以说是OOP&#xff08;Object Oriented Programming&#xff0c;面向对象编程&#xff09;的补充和完善。 …

Springcloud1---->Zuul网关

目录 简介加入zuul后的架构快速入门添加Zuul依赖编写zuul启动类编写zuul配置文件编写路由规则 面向服务的路由添加Eureka客户端依赖开启Eureka客户端发现功能添加Eureka配置&#xff0c;获取服务信息修改映射配置&#xff0c;通过服务名称获取 简化的路由配置过滤器使用场景自定…

这个 堆排序详解过程 我能吹一辈子!!!

文章目录 堆排序的概念堆的分类堆排序的算法思想堆排序的实现 堆排序的概念 堆是一种叫做完全二叉树的数据结构&#xff0c;可分为大根堆、小根堆&#xff0c;而堆排序就是基于这种结构产生的一种排序的算法。 堆的分类 大根堆&#xff1a;每个节点的值都大于或者等于它的左…

SpringBoot 读取 yml 文件属性值常用法总结

开发过程中有一些常量配置一般会写在application.yml文件中&#xff0c;而Spring Boot读取yml文件的主要方式有以下几种: 一、使用Value注解 在bean的属性上使用Value注解,直接读取yml中的值,如: 但这里面写法也有一些情况&#xff1a;其实这种写法对于 String 字符串其实没有…

计算机网络考试周极限复习--1

第一章 时延 因特网协议栈和OSI参考模型 应用层&#xff1a;报文 HTTP&#xff08;提供了Web文档的请求和传送&#xff09;&#xff0c;SMP&#xff08;提供了电子邮件报文的传送&#xff09;&#xff0c; FTP&#xff08;它提供两个端系统之间的文件传送&#xff09; 运输…

【线下|05.27】|StarRocks Friends 杭州站

StarRocks & Friends 是由 StarRocks 社区发起的城市线下 meetup&#xff0c;旨在联合社区与行业的专家小伙伴们分享基于 StarRocks 的最佳实践、大数据分析的前沿技术和 StarRocks 生态融合等热门话题。 不远千里奔赴&#xff0c;只为与你相聚。这个夏天&#xff0c;让我们…

Python大火,零基础还能学习么?

Python近段时间一直涨势迅猛&#xff0c;在各大编程排行榜中崭露头角&#xff0c;得益于它多功能性和简单易上手的特性&#xff0c;让它可以在很多不同的工作中发挥重大作用。 正因如此&#xff0c;目前几乎所有大中型互联网企业都在使用 Python 完成各种各样的工作&#xff0…

广义状态平均无线电能传输系统建模

关于WPT系统建模的一些笔记&#xff0c;在 CSDN 学到很多&#xff0c;现分享给大家&#xff0c;之前有看到过一篇博文&#xff0c; 内容语焉不详&#xff0c;对读者也很不客气&#xff0c;希望这篇博文对大家有用&#xff01; Hierarchical multiobjective H-infinity robust …

Midjourney8种风格介绍+使用场景(3)

引言 我相信大家都或多或少玩过Midjourney&#xff0c;但是要形成自己独特的个人IP&#xff0c;那么有必要知晓画作的一些基础知识&#xff0c;如果你没有时间实践&#xff0c;没有关系&#xff0c;我来操作&#xff0c;定期分享画作相关知识&#xff0c;既简单又方便&#xff…

Systrace系列4 —— SystemServer 解读

本文主要是对 SystemServer 进行简单介绍,介绍了 SystemServer 中几个比较重要的线程,由于 Input 和 Binder 比较重要,所以单独拿出来讲,在这里就没有再涉及到。 窗口动画 Systrace 中的 SystemServer 一个比较重要的地方就是窗口动画,由于窗口归 SystemServer 来管,那么…

CentOS离线配置Java环境

CentOS离线配置Java环境 环境&#xff1a; 操作系统&#xff1a;Linux-CentOS 7Java版本&#xff1a;JDK17远程连接工具&#xff1a;MobaXterm 1.JDK下载 官网下载&#xff1a;https://www.oracle.com/cn/java/technologies/downloads/#java17 ​ 因为MobaXterm自带Sftp&am…

【python csv、Excel、json】零基础也能轻松掌握的学习路线与参考资料

CSV、Excel、JSON 是常用的数据存储格式&#xff0c;分别在不同的场景下有其特点和应用。下面将从以下几个方面进行比较&#xff1a;格式、特点、应用场景和优秀实践。 1.格式 CSV&#xff08;Comma-Separated Values&#xff0c;逗号分隔值&#xff09;格式是一种以纯文本形…

Contrastive Triplet Center Loss

Contrastive Loss background&#xff1a; 最直接的想法是我们假设存在一个损失函数&#xff0c;它满足如下的基本准则 近似样本之间的距离越小越好不似样本之间的距离越大越好 相似样本的坐标被放的越来越远&#xff0c;不似样本之间的距离越来越大&#xff0c;但训练的目标…

V神透露以太坊发展规划 未来十年,zkS将与区块链一样重要

作为加密世界&#xff0c;除中本聪外颇为“传奇”的人物&#xff0c;以太坊联合创始人V神眼光向来毒辣&#xff0c;在加密领域、区块链产业取得诸多“卓著”成绩。 在近期举行的EDCON 2023盛会上&#xff0c;V神透露了以太坊2.0的最新进展和未来规划&#xff0c;以及他对以太坊…

MySQL之索引初步

1. 索引概念 数据库是⽤来存储数据&#xff0c;在互联⽹应⽤中数据库中存储的数据可能会很多(⼤数据)&#xff0c; 数据表中数据的查询速度会随着数据量的增⻓而逐渐变慢 &#xff0c;从⽽导致响应⽤户请求的速度变慢——⽤户体验差&#xff0c;我们如何提⾼数据库的查询效率呢…