蓝桥杯嵌入式

/* 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 "tim.h"
#include "gpio.h"
#include "stdio.h"
#include "string.h"
#include "lcd.h"
#include "i2c_hal.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

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

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
void lcd_action(void);
uint8_t i2c_read(uint8_t ad);
void i2c_write(uint8_t ad,uint8_t info);
void led_action(void);
void pwm_action(void);
void i2c_action(void);
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */
unsigned char key_number=0,key_caton=0;
uint8_t flash_place=1;
char fash_lcd[30];
char timer_lcd[30];
char timer_lcd1[30],timer_lcd2[30],timer_lcd3[30];
uint8_t colok[4]={0,1,55};
unsigned char count_timer1=0,timer1=0;
unsigned char flag=0,count_timer2=0,timer2=0;
unsigned char lcd_stste=3;
int number=-1;
int cun=1;
unsigned char count_timer3=0;
unsigned char read_ture=1;
uint8_t  colk0,colk1,colk2,colk3,colk4,colk5;
/* 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_TIM1_Init();
  MX_TIM3_Init();
  MX_TIM16_Init();
  LCD_Init();
  I2CInit();
  /* USER CODE BEGIN 2 */
HAL_TIM_Base_Start_IT(&htim1);
HAL_TIM_Base_Start_IT(&htim3);
HAL_TIM_PWM_Start(&htim16,TIM_CHANNEL_1);
  /* USER CODE END 2 */
LCD_Clear(Black);//White
  /* Infinite loop */

  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */
	lcd_action();
	led_action();
	pwm_action();
	i2c_action();
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}
void lcd_action(void)
{
	sprintf(fash_lcd,"  NO %d              ",flash_place);
	sprintf(timer_lcd,"      %02d:%02d:%02d      ",colok[0],colok[1],colok[2]);
//	sprintf(timer_lcd1,"      %02d           ",colok[0]);
//	sprintf(timer_lcd2,"         %02d         ",colok[1]);
//	sprintf(timer_lcd3,"            %02d    ",colok[2]);
	colk0=colok[0]/10+'0';
	colk1=colok[0]%10+'0';
	colk2=colok[1]/10+'0';
	colk3=colok[1]%10+'0';
	colk4=colok[2]/10+'0';
	colk5=colok[2]%10+'0';
	LCD_SetTextColor(GRAY);
	LCD_SetBackColor(Black);
	LCD_DisplayStringLine(Line0,(u8 *)"                            ");
	LCD_DisplayStringLine(Line1,(u8 *)"                            ");
	LCD_DisplayStringLine(Line2,(u8 *)fash_lcd);
	LCD_DisplayStringLine(Line3,(u8 *)"                            ");
	LCD_SetTextColor(White);
	if(number==2)
	{
//		LCD_DisplayStringLine(Line4,(u8 *)timer_lcd3);	
		LCD_DisplayChar(Line4,128,colk4);
		LCD_DisplayChar(Line4,112,colk5);
	}
	else if(number==1)
	{
//		LCD_DisplayStringLine(Line4,(u8 *)timer_lcd2);	
		LCD_DisplayChar(Line4,176,colk2);
		LCD_DisplayChar(Line4,160,colk3);
	}
	else if(number==0)
	{
//		LCD_DisplayStringLine(Line4,(u8 *)timer_lcd1);	
		LCD_DisplayChar(Line4,224,colk0);
		LCD_DisplayChar(Line4,208,colk1);
	}
	LCD_SetTextColor(GRAY);
	HAL_Delay(10);
	LCD_DisplayStringLine(Line4,(u8 *)timer_lcd);
	LCD_DisplayStringLine(Line5,(u8 *)"                            ");
	if(lcd_stste==2)
	LCD_DisplayStringLine(Line6,(u8 *)"       seting           ");
	else if(lcd_stste==0)
	LCD_DisplayStringLine(Line6,(u8 *)"       Running           ");
	else if(lcd_stste==1)
	LCD_DisplayStringLine(Line6,(u8 *)"       Pause           ");
	else if(lcd_stste==3)
	LCD_DisplayStringLine(Line6,(u8 *)"       Standy          ");	
	LCD_DisplayStringLine(Line7,(u8 *)"                            ");
	LCD_DisplayStringLine(Line8,(u8 *)"                            ");
	LCD_DisplayStringLine(Line9,(u8 *)"                            ");
}
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
	if(htim->Instance==TIM1)
	{
		switch(key_number)
		{
			case 0:
				if(!HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_0)|!HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_1)|!HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_2)|!HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0))
				{
					key_number=9;
				}
				break;
			case 9:
				if(!HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_0))
				{
					key_number=1;
					key_caton=1;
				}
				else if(!HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_1))
				{
					key_number=2;
					key_caton=1;
				}
				else if(!HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_2))
				{
					key_number=3;
					key_caton=1;
				}
				else if(!HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0))
				{
					key_number=4;
					key_caton=1;
				}else{key_number=0;}				
				break;
			case 1:
				if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_0))
				{
					key_number=0;
				}
				break;
			case 2:
				if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_1))
				{
					key_number=0;
				}
				break;
			case 3:
				if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_2))
				{
					key_number=0;
				}
				break;
			case 4:
				if(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0))
				{
					key_number=0;
				}
				break;
			default:break;
		}
		switch(key_number)
		{
			case 1:
				if(key_caton==1)
				{
					key_caton=0;
					flash_place++;
					read_ture=1;
					if(flash_place>=6)
					{
						flash_place=1;
					}
				}
				break;
			case 2:
				if(key_caton==1)
				{
					key_caton=0;
					number++;
					number=number%3;
					lcd_stste=2;
				}
				break;
			case 3:
				if(key_caton==1)
				{
					key_caton=0;
					if(number==0)
					{
						colok[number]++;
						colok[number]=colok[number]%24;
					}
					else
					{
						colok[number]++;
						colok[number]=colok[number]%60;
					}
				}
				break;
			case 4:
				if(key_caton==1)
				{
					key_caton=0;
				   lcd_stste++;
				 lcd_stste=lcd_stste%2;
				}
				break;
			default:break;
		}
		
		
		
		
		if(!key_caton&&(key_number==2))
		{
			timer2=0;
			key_caton=4;
			flag=1;
			count_timer2=0;
		}
		if(!key_caton&&(key_number==3))
		{
			timer2=0;
			key_caton=4;
			flag=1;
			count_timer2=0;
		}
		if(!key_caton&&(key_number==4))
		{
			timer2=0;
			key_caton=4;
			flag=1;
			count_timer2=0;
		}
		if((key_number==3)&&timer2)
		{
					if(number==0)
					{
						colok[number]++;
						colok[number]=colok[number]%24;
					}
					else
					{
						colok[number]++;
						colok[number]=colok[number]%60;
					}
		}
		if((key_number==4)&&timer2)
		{
			lcd_stste=3;
		}
	}
	
	
	
	if(htim->Instance==TIM3)
	{
		if(count_timer1<10)
		{
			count_timer1++;
		}
		else
		{
			count_timer1=0;
			timer1=1;
		}
		if(flag)
		{
			if(count_timer2<8)
			{
				count_timer2++;
			}
			else
			{
				count_timer2=0;
				timer2=1;
			}
		}
		
		if(lcd_stste==0)
		{
			count_timer3++;
			if(count_timer3>10)
			{
				count_timer3=0;
				colok[2]--;
				if(colok[2]<=0|colok[2]>60)
				{
					colok[2]=60;
					colok[1]--;
					if((colok[1]<=0|colok[1]>60)&&(colok[0]>=0))
					{
						colok[1]=60;
						colok[0]--;
						if(colok[0]>24)
						{
							colok[0]=23;
						}
					}
				}
			}
		}
	}
}
void i2c_action(void)
{
	
	if(read_ture)
	{
		read_ture=0;
		colok[0]=i2c_read(flash_place);
		colok[1]=i2c_read(flash_place*6);
		colok[2]=i2c_read(flash_place*7);
	}
	
	if((key_number==2)&&timer2)
	{
		lcd_stste=3;
		switch (cun)
		{
			case 0:
				i2c_write(flash_place,colok[0]);
				break;
			case 1:
				i2c_write(flash_place*6,colok[1]);
				break;
			case 2:
				i2c_write(flash_place*7,colok[2]);
				break;
			default:break;
		}
		cun++;
		cun=cun%3;
	}
}
void pwm_action(void)
{
	if(lcd_stste==0)
	__HAL_TIM_SetCompare(&htim16,TIM_CHANNEL_1,80);
	else
	__HAL_TIM_SetCompare(&htim16,TIM_CHANNEL_1,0);
}
void led_action(void)
{
	if(lcd_stste==0)
	{
		switch (count_timer1)
		{
			case 0:
				HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_8
							  |GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12, GPIO_PIN_SET);
				HAL_GPIO_WritePin(GPIOC,GPIO_PIN_8,GPIO_PIN_RESET);
				HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
				HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
				break;
			case 5:
				HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_8
							  |GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12, GPIO_PIN_SET);
				HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
				HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
				break;
		}
	}
	else
	{
		HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_8
							  |GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12, GPIO_PIN_SET);
		HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
		HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
	}
}
uint8_t i2c_read(uint8_t ad)
{
	uint8_t val;
	I2CStart();
	I2CSendByte(0xa0);
	I2CWaitAck();
	I2CSendByte(ad);
	I2CWaitAck();
	I2CStop();
	I2CStart();
	I2CSendByte(0xa1);
	I2CWaitAck();
	val = I2CReceiveByte();
	I2CWaitAck();
	I2CStop();
	
	return val;
}
void i2c_write(uint8_t ad,uint8_t info)
{
	I2CStart();
	I2CSendByte(0xa0);
	I2CWaitAck();
	I2CSendByte(ad);
	I2CWaitAck();
	I2CSendByte(info);
	I2CWaitAck();
	I2CStop();
}
/**
  * @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 */

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

第9届

/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2022 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 "dma.h"
#include "tim.h"
#include "gpio.h"
#include "lcd.h"
#include "stdio.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

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

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
void uper_limit(void);
void lower_limit(void);
void colour(void);
void compare_lower_uper(void);
uint8_t keyboarsd(uint8_t mode);
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */
int set=1;
int set_contents=1;	
int set_colour=0;
uint8_t key_number=0;
uint8_t key_caton=0;
 char tt[30];
 char limit[30];
 char sx[30];
 char xx[30];
 char sx_alert[30];
 char xx_alert[30];
 uint16_t uper_alert[2]={0};
uint16_t lower_alert[2]={0};
uint16_t uper[2]={0};
uint16_t lower[2]={0};
uint16_t adc_compare[4]={0};
uint16_t ADCnumber[2]={0};
/* 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_DMA_Init();
  MX_ADC2_Init();
  MX_TIM1_Init();
  LCD_Init();
  HAL_TIM_Base_Start_IT(&htim1);
  /* USER CODE BEGIN 2 */
  HAL_ADC_Start_DMA(&hadc2,(uint32_t *)ADCnumber,1);
	LCD_Clear(White);
  /* USER CODE END 2 */
  uper[0]=240;
  lower[0]=120;
  uper_alert[0]=1;
  lower_alert[0]=2;
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
	  HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
    /* USER CODE END WHILE */
		if(set)
		  {
		  set_colour=0;
		  sprintf(tt, "    v=%.2f  v          ", ADCnumber[0]*3.3/4096);
		  adc_compare[0]=ADCnumber[0]*330/4096;
		  LCD_SetBackColor(White);
		  LCD_SetTextColor(Black);
		  compare_lower_uper();
		  LCD_DisplayStringLine(Line0, (uint8_t *)"                    ");
		  LCD_DisplayStringLine(Line1, (uint8_t *)"        Main        ");
		  LCD_DisplayStringLine(Line2, (uint8_t *)"                    ");
		  LCD_DisplayStringLine(Line3, (uint8_t *)"                    ");
		  LCD_DisplayStringLine(Line4, (uint8_t *)tt);
		  LCD_DisplayStringLine(Line5, (uint8_t *)"                    ");
		  LCD_DisplayStringLine(Line6, (uint8_t *)"                    ");
		  LCD_DisplayStringLine(Line7, (uint8_t *)limit);
		  LCD_DisplayStringLine(Line8, (uint8_t *)"                    ");
		  LCD_DisplayStringLine(Line9, (uint8_t *)"                    ");
		  uper_limit();
		  lower_limit();
		  }
	  else
		  {
			set_colour=1;
		  sprintf(sx, "   Max Volt:%.2fV       ", uper[0]*3.3/330);
		  sprintf(xx, "   Min Volt:%.2fV       ", lower[0]*3.3/330);
	      sprintf(sx_alert, "   Upper: LD%d       ", uper_alert[0]);
		  sprintf(xx_alert, "   Lower: LD%d       ", lower_alert[0]);
		  LCD_SetBackColor(White);
		  LCD_SetTextColor(Black);
		  LCD_DisplayStringLine(Line0, (uint8_t *)"                    ");
		  LCD_DisplayStringLine(Line1, (uint8_t *)"       Setting      ");
		  LCD_DisplayStringLine(Line2, (uint8_t *)"                    ");
		  LCD_DisplayStringLine(Line3, (uint8_t *)sx);
		  LCD_DisplayStringLine(Line4, (uint8_t *)xx);
		  LCD_DisplayStringLine(Line5, (uint8_t *)sx_alert);
		  LCD_DisplayStringLine(Line6, (uint8_t *)xx_alert);
		  LCD_DisplayStringLine(Line7, (uint8_t *)"                    ");
		  LCD_DisplayStringLine(Line8, (uint8_t *)"                    ");
		  LCD_DisplayStringLine(Line9, (uint8_t *)"                    ");
		  colour();
		  }

    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

void colour(void)
{
	if(set_colour)
	{
		switch (set_contents)
		{
		case 1:
			LCD_SetBackColor(Yellow);
			LCD_DisplayStringLine(Line3, (uint8_t *)"                    ");
			break;
		case 2:
			LCD_SetBackColor(Yellow);
			LCD_DisplayStringLine(Line4, (uint8_t *)"                    ");
			break;
		case 3:
			LCD_SetBackColor(Yellow);
			LCD_DisplayStringLine(Line5, (uint8_t *)"                    ");
			break;
		case 4:
			LCD_SetBackColor(Yellow);
			LCD_DisplayStringLine(Line6, (uint8_t *)"                    ");
			break;
		}
	}
}

	
/**
  * @brief System Clock Configuration
  * @retval None
  */
	
void compare_lower_uper(void)
{
			  if(adc_compare[0]>uper[0]) 
		  {
			  adc_compare[3]=1;
			  sprintf(limit, "   Status: Upper      ");
			  
		  }
		  else 
		  {
			  adc_compare[3]=0;
			  sprintf(limit, "   Status: Normal      ");
		  }
		  if(adc_compare[0]<lower[0]) 
		  {
		  adc_compare[4]=1;
		  sprintf(limit, "   Status: Lower      ");  
		  }
		  else 
		  {
			  adc_compare[4]=0;	 
		  }
}

void lower_limit(void)
{
	if(adc_compare[4])
	  {
		  switch(lower_alert[0])
		  {
			  case 1:
				  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_8
					  |GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12, GPIO_PIN_SET);
					HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_8);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
					HAL_Delay(200);
					HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_8);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
					HAL_Delay(200);
					break;
			  case 2:
				  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_8
					  |GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12, GPIO_PIN_SET);
					HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_9);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
					HAL_Delay(200);
					HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_9);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
					HAL_Delay(200);
					break;
			  case 3:
				  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_8
					  |GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12, GPIO_PIN_SET);
					HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_10);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
					HAL_Delay(200);
					HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_10);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
					HAL_Delay(200);
					break;
			  case 4:
				  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_8
					  |GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12, GPIO_PIN_SET);
					HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_11);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
					HAL_Delay(200);
					HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_11);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
					HAL_Delay(200);
					break;
			  case 5:
				  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_8
					  |GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12, GPIO_PIN_SET);
					HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_12);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
					HAL_Delay(200);
					HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_12);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
					HAL_Delay(200);
					break;
			  case 6:
				  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_8
					  |GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12, GPIO_PIN_SET);
					HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_13);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
					HAL_Delay(200);
					HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_13);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
					HAL_Delay(200);
					break;
			  case 7:
				  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_8
					  |GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12, GPIO_PIN_SET);
					HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_14);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
					HAL_Delay(200);
					HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_14);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
					HAL_Delay(200);
					break;
			  case 8:
				  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_8
					  |GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12, GPIO_PIN_SET);
					HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_15);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
					HAL_Delay(200);
					HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_15);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
					HAL_Delay(200);
					break;
		  }
	  }
}
void uper_limit(void)
{
	if(adc_compare[3])
	  {
		  switch(uper_alert[0])
		  {
			  case 1:
				  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_8
					  |GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12, GPIO_PIN_SET);
					HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_8);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
					HAL_Delay(200);
					HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_8);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
					HAL_Delay(200);
					break;
			  case 2:
				  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_8
					  |GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12, GPIO_PIN_SET);
					HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_9);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
					HAL_Delay(200);
					HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_9);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
					HAL_Delay(200);
					break;
			  case 3:
				  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_8
					  |GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12, GPIO_PIN_SET);
					HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_10);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
					HAL_Delay(200);
					HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_10);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
					HAL_Delay(200);
					break;
			  case 4:
				  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_8
					  |GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12, GPIO_PIN_SET);
					HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_11);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
					HAL_Delay(200);
					HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_11);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
					HAL_Delay(200);
					break;
			  case 5:
				  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_8
					  |GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12, GPIO_PIN_SET);
					HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_12);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
					HAL_Delay(200);
					HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_12);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
					HAL_Delay(200);
					break;
			  case 6:
				  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_8
					  |GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12, GPIO_PIN_SET);
					HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_13);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
					HAL_Delay(200);
					HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_13);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
					HAL_Delay(200);
					break;
			  case 7:
				  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_8
					  |GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12, GPIO_PIN_SET);
					HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_14);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
					HAL_Delay(200);
					HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_14);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
					HAL_Delay(200);
					break;
			  case 8:
				  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_8
					  |GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12, GPIO_PIN_SET);
					HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_15);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
					HAL_Delay(200);
					HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_15);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
					HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
					HAL_Delay(200);
					break;
		  }
	  }
}

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
	{
				static uint16_t i=0;
				i++;
			switch(key_number)
			{
				case 0:
					if(HAL_GPIO_ReadPin (GPIOB,GPIO_PIN_0)==0||HAL_GPIO_ReadPin (GPIOB,GPIO_PIN_1)==0||HAL_GPIO_ReadPin (GPIOB,GPIO_PIN_2)==0||HAL_GPIO_ReadPin (GPIOA,GPIO_PIN_0)==0)
					{
						key_number=9;
					}
					break;
				case 9:
					if(HAL_GPIO_ReadPin (GPIOB,GPIO_PIN_0)==0)
					{
						key_number=1;
						key_caton=1;
					}
					else if(HAL_GPIO_ReadPin (GPIOB,GPIO_PIN_1)==0)
					{
						key_number=2;
						key_caton=1;
					}
					else if(HAL_GPIO_ReadPin (GPIOB,GPIO_PIN_2)==0)
					{
						key_number=3;
						key_caton=1;
					}
					else if(HAL_GPIO_ReadPin (GPIOA,GPIO_PIN_0)==0)
					{
						key_number=4;
						key_caton=1;
					}
					else 
					{
						key_number=0;
					}
					break;
				case 1:
					
					if(HAL_GPIO_ReadPin (GPIOB,GPIO_PIN_0)==1)
					{
						key_number=0;
					}
						break;
				case 2:
					if(HAL_GPIO_ReadPin (GPIOB,GPIO_PIN_1)==1)
					{
						key_number=0;
					}
					break;
				case 3:
					if(HAL_GPIO_ReadPin (GPIOB,GPIO_PIN_2)==1)
					{
						key_number=0;
					}
					break;
				case 4:
					if(HAL_GPIO_ReadPin (GPIOA,GPIO_PIN_0)==1)
					{
						key_number=0;
					}
					break;
				default :break;
						
			}
	
		  if(key_number)
		  {
			  switch (key_number)
			  {
				  case 1:
					  if(key_caton)
					  {
					  key_caton=0;
						set++;
						if(set>1) set=0;
					  }
						break;
				  case 2:
					  if(set==0)
					  {
						  if(key_caton)
						  {
							key_caton=0;
							set_contents++;

							if(set_contents>4) set_contents=1;
							}
						}
						break;
				  case 3:
					  if(set==0)
					  {
						  if(key_caton)
						  {
							key_caton=0;
							switch (set_contents)
							{
								case 1:
									uper[0]=uper[0]+30;
									if(uper[0]>330) uper[0]=0;
									break;
								case 2:
									lower[0]=lower[0]+30;
									if(lower[0]>330) lower[0]=0;
									break;
								case 3:
									uper_alert[0]++;
									if(uper_alert[0]==lower_alert[0]) uper_alert[0]++;
									if(uper_alert[0]>8) uper_alert[0]=0;
									break;
								case 4:
									lower_alert[0]++;
									if(uper_alert[0]==lower_alert[0]) lower_alert[0]++;
									if(lower_alert[0]>8) lower_alert[0]=0;
									break;
								}
							}
						}
						break;
				  case 4:
					  if(set==0)
					  {
						  if(key_caton)
						  {
							 key_caton=0;
						switch (set_contents)
						{
							case 1:
								uper[0]=uper[0]-30;
								if(uper[0]==0) uper[0]=330;
								break;
							case 2:
								lower[0]=lower[0]-30;
								if((lower[0]==0)) lower[0]=330;
								break;
							case 3:
								uper_alert[0]--;
								if(uper_alert[0]==lower_alert[0]) uper_alert[0]--;
								if(uper_alert[0]==0) uper_alert[0]=8;
								break;
							case 4:
								lower_alert[0]--;
								if(uper_alert[0]==lower_alert[0]) lower_alert[0]--;
								if(lower_alert[0]==0) lower_alert[0]=8;
								break;
							}
						}
						}
						break;
				default:break;
			  }
		  }
	  
		  HAL_TIM_Base_Start_IT(&htim1);
	}
uint8_t keyboarsd(uint8_t mode)
{
	static uint8_t key_up=1;
	if(mode) key_up=1;
	if(key_up&&(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0)==0||HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_0)==0||HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_1)==0||HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_2)==0))
	{
		HAL_Delay(10);
		key_up=0;
		if(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0)==0) return 4;
		if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_0)==0) return 1;
		if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_1)==0) return 2;
		if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_2)==0) return 3;
			
	}else if(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0)==1&&HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_0)==1&&HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_1)==1&&HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_2)==1) key_up=1;
	return 0;
}

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

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

第10届


/* 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 "dma.h"
#include "tim.h"
#include "gpio.h"
#include "lcd.h"
#include "stdio.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

/* USER CODE END Includes */
uint16_t adc[2]={0};
uint8_t key_number=0;
uint8_t key_caton=0;
int adc_pwm_compare=10;
int view_set=1,view=1;
int mode_exist=1,mode=1;
int pwm6=10;
int pwm7=10;
char percent='%';
char pa6[30];	
char pa7[30];
char view_adc[30];
char view_mode[30];
/* 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 */

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
void mode_effect(void);
void pwm_set(void);
/* USER CODE BEGIN PFP */

/* 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_TIM3_Init();
  MX_DMA_Init();
  MX_TIM17_Init();
  MX_ADC2_Init();
  MX_TIM1_Init();
  LCD_Init();
  /* USER CODE BEGIN 2 */
   HAL_ADC_Start_DMA(&hadc2,(uint32_t *)adc,1);
   HAL_TIM_Base_Start_IT(&htim1);
   HAL_TIM_PWM_Start(&htim3,TIM_CHANNEL_1);
   HAL_TIM_PWM_Start(&htim17,TIM_CHANNEL_1);
  /* USER CODE END 2 */
   LCD_Clear(Black);
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
	  HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
    /* USER CODE END WHILE */
    if(view_set)
	{
		sprintf(view_adc,"    V : %.2f V    ",adc[0]*3.3/4096);
		mode_effect();
		HAL_GPIO_WritePin(GPIOC,GPIO_PIN_9,GPIO_PIN_RESET);
		HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
		HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
		LCD_SetTextColor(White);
		LCD_SetBackColor(Black);
		LCD_DisplayStringLine(Line0,(uint8_t *)"      D a t a       ");
		LCD_DisplayStringLine(Line1,(uint8_t *)"               ");
		LCD_DisplayStringLine(Line2,(uint8_t *)view_adc);
		LCD_DisplayStringLine(Line3,(uint8_t *)"               ");
		LCD_DisplayStringLine(Line4,(uint8_t *)"               ");
		LCD_DisplayStringLine(Line5,(uint8_t *)view_mode);
		LCD_DisplayStringLine(Line6,(uint8_t *)"               ");
		LCD_DisplayStringLine(Line7,(uint8_t *)"               ");	
		LCD_DisplayStringLine(Line8,(uint8_t *)"               ");	
		LCD_DisplayStringLine(Line9,(uint8_t *)"               ");	
		
	}
	else
	{
		mode_effect();
		HAL_GPIO_WritePin(GPIOC,GPIO_PIN_9,GPIO_PIN_SET);
		HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
		HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
		LCD_SetTextColor(White);
		LCD_SetBackColor(Black);
		LCD_DisplayStringLine(Line0,(uint8_t *)"      P a r a       ");
		LCD_DisplayStringLine(Line1,(uint8_t *)"               ");
		LCD_DisplayStringLine(Line2,(uint8_t *)"               ");
		LCD_DisplayStringLine(Line3,(uint8_t *)pa6);
		LCD_DisplayStringLine(Line4,(uint8_t *)"               ");
		LCD_DisplayStringLine(Line5,(uint8_t *)pa7);
		LCD_DisplayStringLine(Line6,(uint8_t *)"               ");
		LCD_DisplayStringLine(Line7,(uint8_t *)"               ");	
		LCD_DisplayStringLine(Line8,(uint8_t *)"               ");	
		LCD_DisplayStringLine(Line9,(uint8_t *)"               ");	
	}
	pwm_set();
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

/**
  * @brief System Clock Configuration
  * @retval None
  */


void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
	switch (key_number)
	{
		case 0:
			if(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0)==0||HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_0)==0||HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_1)==0||HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_2)==0)
			{
				key_number=9;
			}
			break;
		case 9:
			if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_0)==0)
			{
				key_number=1;
				key_caton=1;
			}
			else if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_1)==0)
			{
				key_number=2;
				key_caton=1;
			}
			else if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_2)==0)
			{
				key_number=3;
				key_caton=1;
			}
			else if(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0)==0)
			{
				key_number=4;
				key_caton=1;
			}
			else
			{
				key_number=0;
			}
			break;
		case 1:
			if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_0)==1)
			{
				key_number=0;
			}
			break;
		case 2:
			if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_1)==1)
			{
				key_number=0;
			}
			break;
		case 3:
			if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_2)==1)
			{
				key_number=0;
			}
			break;
		case 4:
			if(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0)==1)
			{
				key_number=0;
			}
			break;
		default :break;
	} 

	
	if(key_number)
	{
		switch (key_number)
		{
			case 1:
               if(key_caton)
			   {
				   key_caton=0;
				   view++;
				   view_set=view%2;
			   }
				break;
			case 2:
				if(key_caton)
				{
					if(!mode_exist)
					{
						if(view_set==0)
						{
							key_caton=0;
							pwm6+=10;
							if(pwm6==100) pwm6=10;
						}
					}
				}
				break;
			case 3:
				if(key_caton)
				{
					if(!mode_exist)
					{
						if(view_set==0)
						{
							key_caton=0;
							pwm7+=10;
							if(pwm7==100) pwm7=10;
						}
					}
				}
				break;
			case 4:
				if(key_caton)
				{
					key_caton=0;
					mode++;
					mode_exist=mode%2;
				}
				break;
			default:break;
		}
	}
	HAL_TIM_Base_Start_IT(&htim1);
}
void pwm_set(void)
{
	if(mode_exist)
	{
		adc_pwm_compare=adc[0]*100/4096;
		sprintf(pa6,"   P A 6 : %d %c    ",adc_pwm_compare,percent);
		sprintf(pa7,"   P A 7 : %d %c    ",adc_pwm_compare,percent);
		__HAL_TIM_SetCompare(&htim3,TIM_CHANNEL_1,adc_pwm_compare);
		__HAL_TIM_SetCompare(&htim17,TIM_CHANNEL_1,adc_pwm_compare);
	}
	else
	{
		sprintf(pa6,"   P A 6 : %d %c    ",pwm6,percent);
		sprintf(pa7,"   P A 7 : %d %c    ",pwm7,percent);
		__HAL_TIM_SetCompare(&htim3,TIM_CHANNEL_1,pwm6);
		__HAL_TIM_SetCompare(&htim17,TIM_CHANNEL_1,pwm7);
	}
}
void mode_effect(void)
{
	if(mode_exist)
	{
		HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_8
                          |GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12, GPIO_PIN_SET);
		HAL_GPIO_WritePin(GPIOC,GPIO_PIN_8,GPIO_PIN_RESET);
		HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
		HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
		sprintf(view_mode,"  M o d e : A U T O   ");
	}
	else
	{ 
		HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_8
                          |GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12, GPIO_PIN_SET);
		HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
		HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
		sprintf(view_mode,"  M o d e : M A N U   ");
	}
}
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 */

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

第11届


/* 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 "tim.h"
#include "usart.h"
#include "gpio.h"
#include "lcd.h"
#include "stdio.h"
#include "string.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
uint8_t key_number=0;
uint8_t key_caton=0;
uint8_t rx[100];
int view=1,pwm_mode=1;
int cnbr_number=0,vnbr_number=0,idle_number=8;
int cnbr_number1=0,vnbr_number1=0;
int cnbr_price=7,vnbr_price=4;
int uart_hour,uart_mony;
char cnbr_data[30];
char vnbr_data[30];
char idle_data[30];
char cnbr_para[30];
char vnbr_para[30];
char cnbr_car[100];
char vnbr_car[100];
char uart_send[50];
char aa[13];
char bb[13];
char uart_error[30]="Error\r\n";
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
struct usart_receive
{
	unsigned char year;
	unsigned char month;
	unsigned char day;
	unsigned char hour;
	unsigned char minute;
	unsigned char second;
};
struct usart_receive CNBR[50]={0};
struct usart_receive VNBR[50]={0};
unsigned char compare_year,compare_month,compare_day,compare_hour,compare_minute,compare_second;
/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/

/* USER CODE BEGIN PV */

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
void pwm_set(void);
void uart_claer(void);
void URAT_RECEIVE(void);
void uart_transmit_claer(void);
void led(void);
/* USER CODE BEGIN PFP */

/* 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_TIM1_Init();
  MX_TIM3_Init();
  MX_USART1_UART_Init();
  LCD_Init();
  HAL_UART_Receive_IT(&huart1,rx,22);
  /* USER CODE BEGIN 2 */
  HAL_TIM_Base_Start_IT(&htim1);
  HAL_TIM_PWM_Start(&htim3,TIM_CHANNEL_2);
  /* USER CODE END 2 */
	LCD_Clear(Black);
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
	HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
    /* USER CODE END WHILE */
	if(view)
	{
		sprintf(cnbr_data,"   CNBR:%d           ",cnbr_number);
		sprintf(vnbr_data,"   VNBR:%d           ",vnbr_number);
		sprintf(idle_data,"   IDLE:%d           ",idle_number);
		LCD_SetTextColor(White);
		LCD_SetBackColor(Black);
		LCD_DisplayStringLine(Line0,(u8*)"                    ");
		LCD_DisplayStringLine(Line1,(u8*)"       Data         ");
		LCD_DisplayStringLine(Line2,(u8*)"                    ");
		LCD_DisplayStringLine(Line3,(u8*)"                    ");
		LCD_DisplayStringLine(Line4,(u8*)cnbr_data);
		LCD_DisplayStringLine(Line5,(u8*)"                    ");
		LCD_DisplayStringLine(Line6,(u8*)vnbr_data);
		LCD_DisplayStringLine(Line7,(u8*)"                    ");
		LCD_DisplayStringLine(Line8,(u8*)idle_data);
	}
	else
	{
		sprintf(cnbr_para,"   CNBR:%.2f           ",cnbr_price/2.0);
		sprintf(vnbr_para,"   VNBR:%.2f           ",vnbr_price/2.0);
		LCD_SetTextColor(White);
		LCD_SetBackColor(Black);
		LCD_DisplayStringLine(Line0,(u8*)"                    ");
		LCD_DisplayStringLine(Line1,(u8*)"       Para         ");
		LCD_DisplayStringLine(Line2,(u8*)"                    ");
		LCD_DisplayStringLine(Line3,(u8*)"                    ");
		LCD_DisplayStringLine(Line4,(u8*)cnbr_para);
		LCD_DisplayStringLine(Line5,(u8*)"                    ");
		LCD_DisplayStringLine(Line6,(u8*)vnbr_para);
		LCD_DisplayStringLine(Line7,(u8*)"                    ");
		LCD_DisplayStringLine(Line8,(u8*)"                    ");
	}
	URAT_RECEIVE();
	pwm_set();
	led();
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

//HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
/按键
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
	switch(key_number)
	{
		case 0:
			if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_0)==0||HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_1)==0||HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_2)==0||HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0)==0)
			{
				key_number=9;
			}
			break;
		case 9:
			if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_0)==0)
			{
				key_number=1;
				key_caton=1;
			}
			else if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_1)==0)
			{
				key_number=2;
				key_caton=1;
			}
			else if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_2)==0)
			{
				key_number=3;
				key_caton=1;
			}
			else if(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0)==0)
			{
				key_number=4;
				key_caton=1;
			}
			else
			{
				key_number=0;
			}
			break;
		case 1:
			if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_0))
			{
				key_number=0;
			}
			break;
		case 2:
			if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_1))
			{
				key_number=0;
			}
			break;
		case 3:
			if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_2))
			{
				key_number=0;
			}
			break;
		case 4:
			if(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0))
			{
				key_number=0;
			}
			break;
		default:break;
	}
	switch(key_number)
	{
		case 1:
			if(key_caton)
			{
				key_caton=0;
				view=!view;
			}
			break;
		case 2:
			if(view==0)
			{
			if(key_caton)
			{
				key_caton=0;
				cnbr_price++;
				vnbr_price++;
			}
	     	}
			break;
		case 3:
			if(view==0)
			{
			if(key_caton)
			{
				key_caton=0;
				cnbr_price--;
				vnbr_price--;
			}
			}
			break;
		case 4:
			if(key_caton)
			{
				key_caton=0;
				pwm_mode=!pwm_mode;
			}
			break;
		default:break;
	}
	HAL_TIM_Base_Start_IT(&htim1);
}
/串口中断
//void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
//{
//	int x,y;
//	uint8_t error=1;
//	if((rx[1]!='\0')&&(rx[2]!='\0'))
//	{
//		for( x=0;x<25;x++)
//		{
//			if(rx[x]=='C')
//			{
//				if((rx[x+1]=='N')&&(rx[x+2]=='B')&&(rx[x+3]=='R'))
//				{
//					int book=1;
//					error=0;//正确车型
//					if(cnbr_number1)//是否有车辆进入过
//					{
//						for(y=0;y<cnbr_number1;y++)
//						{
//							if((cnbr_car[0+y*4]==rx[x+5])&&(cnbr_car[1+y*4]==rx[x+6])&&(cnbr_car[2+y*4]==rx[x+7])&&(cnbr_car[3+y*4]==rx[x+8]))
//							{
//								book=0;
//								compare_year=(rx[x+10]-'0')*10+(rx[x+11]-'0');
//								compare_month=(rx[x+12]-'0')*10+(rx[x+13]-'0');
//								compare_day=(rx[x+14]-'0')*10+(rx[x+15]-'0');
//								compare_hour=(rx[x+16]-'0')*10+(rx[x+17]-'0');
//								compare_minute=(rx[x+18]-'0')*10+(rx[x+19]-'0');
//								compare_second=(rx[x+20]-'0')*10+(rx[x+21]-'0');//出车的时间
//								aa[0]=cnbr_car[0+y*4];
//								aa[1]=cnbr_car[1+y*4];
//								aa[2]=cnbr_car[2+y*4];
//								aa[3]=cnbr_car[3+y*4];//串口传输车牌号aa数组
//								if((CNBR[y].minute!=compare_minute)||(compare_second!=CNBR[y].second))//判断时间小于小时部分的决定
//								{
//									uart_hour=(compare_day-CNBR[y].day)*24+compare_hour-CNBR[y].hour+1;
//								}
//								else
//								{
//									uart_hour=(compare_day-CNBR[y].day)*24+compare_hour-CNBR[y].hour;
//								}
//								uart_mony=uart_hour*cnbr_price;//计算出钱
//								sprintf(uart_send, "CNBR:");
//								sprintf(&uart_send[5],aa);
//								sprintf(bb,":%d:%.2f\r\n",uart_hour,uart_mony/2.0);
//								sprintf(&uart_send[9],bb);//组和部分
								HAL_UART_Transmit(&huart1,(unsigned char*)uart_send,strlen(uart_send),1000);//发送部分
//								cnbr_car[0+y*4]='\0';
//								cnbr_car[1+y*4]='\0';
//								cnbr_car[2+y*4]='\0';
//								cnbr_car[3+y*4]='\0';
//								CNBR[y].year='\0';
//								CNBR[y].month='\0';
//								CNBR[y].day='\0';
//								CNBR[y].hour='\0';
//								CNBR[y].minute='\0';
//								CNBR[y].second='\0';
//								cnbr_number--;//显示的cnbr
//								idle_number++;//车的个数
//							}
//						}
//					}
//					if(book)//存进去的
//					{
//						cnbr_car[0+cnbr_number1*4]=rx[x+5];
//						cnbr_car[1+cnbr_number1*4]=rx[x+6];
//						cnbr_car[2+cnbr_number1*4]=rx[x+7];
//						cnbr_car[3+cnbr_number1*4]=rx[x+8];
//						CNBR[cnbr_number1].year=(rx[x+10]-'0')*10+(rx[x+11]-'0');
//						CNBR[cnbr_number1].month=(rx[x+12]-'0')*10+(rx[x+13]-'0');
//						CNBR[cnbr_number1].day=(rx[x+14]-'0')*10+(rx[x+15]-'0');
//						CNBR[cnbr_number1].hour=(rx[x+16]-'0')*10+(rx[x+17]-'0');
//						CNBR[cnbr_number1].minute=(rx[x+18]-'0')*10+(rx[x+19]-'0');
//						CNBR[cnbr_number1].second=(rx[x+20]-'0')*10+(rx[x+21]-'0');
//						cnbr_number1++;
//						cnbr_number++;//显示的cnbr
//						idle_number--;//车的个数
//					}
//				}
//			}
//			else if(rx[x]=='V')
//			{
//				if((rx[x+1]=='N')&&(rx[x+2]=='B')&&(rx[x+3]=='R'))
//				{
//					int book=1;
//					error=0;//正确车型
//					if(vnbr_number1)//是否有车辆进入过
//					{
//						for(y=0;y<vnbr_number1;y++)
//						{
//							if((vnbr_car[0+y*4]==rx[x+5])&&(vnbr_car[1+y*4]==rx[x+6])&&(vnbr_car[2+y*4]==rx[x+7])&&(vnbr_car[3+y*4]==rx[x+8]))
//							{
//								book=0;
//								compare_year=(rx[x+10]-'0')*10+(rx[x+11]-'0');
//								compare_month=(rx[x+12]-'0')*10+(rx[x+13]-'0');
//								compare_day=(rx[x+14]-'0')*10+(rx[x+15]-'0');
//								compare_hour=(rx[x+16]-'0')*10+(rx[x+17]-'0');
//								compare_minute=(rx[x+18]-'0')*10+(rx[x+19]-'0');
//								compare_second=(rx[x+20]-'0')*10+(rx[x+21]-'0');//出车的时间
//								aa[0]=vnbr_car[0+y*4];
//								aa[1]=vnbr_car[1+y*4];
//								aa[2]=vnbr_car[2+y*4];
//								aa[3]=vnbr_car[3+y*4];//串口传输车牌号aa数组
//								if((VNBR[y].minute!=compare_minute)||(compare_second!=VNBR[y].second))//判断时间小于小时部分的决定
//								{
//									uart_hour=(compare_day-VNBR[y].day)*24+compare_hour-VNBR[y].hour+1;
//								}
//								else
//								{
//									uart_hour=(compare_day-VNBR[y].day)*24+compare_hour-VNBR[y].hour;
//								}
//								uart_mony=uart_hour*vnbr_price;//计算出钱
//								sprintf(uart_send, "VNBR:");
//								sprintf(&uart_send[5],aa);
//								sprintf(bb,":%d:%.2f\r\n",uart_hour,uart_mony/2.0);
//								sprintf(&uart_send[9],bb);//组和部分
								HAL_UART_Transmit(&huart1,(unsigned char*)uart_send,strlen(uart_send),1000);//发送部分
//								vnbr_car[0+y*4]='\0';
//								vnbr_car[1+y*4]='\0';
//								vnbr_car[2+y*4]='\0';
//								vnbr_car[3+y*4]='\0';
//								VNBR[y].year='\0';
//								VNBR[y].month='\0';
//								VNBR[y].day='\0';
//								VNBR[y].hour='\0';
//								VNBR[y].minute='\0';
//								VNBR[y].second='\0';
//								vnbr_number--;//显示的cnbr
//								idle_number++;//车的个数
//							}
//						}
//					}
//					if(book)//存进去的
//					{
//						vnbr_car[0+vnbr_number1*4]=rx[x+5];
//						vnbr_car[1+vnbr_number1*4]=rx[x+6];
//						vnbr_car[2+vnbr_number1*4]=rx[x+7];
//						vnbr_car[3+vnbr_number1*4]=rx[x+8];
//						VNBR[vnbr_number1].year=(rx[x+10]-'0')*10+(rx[x+11]-'0');
//						VNBR[vnbr_number1].month=(rx[x+12]-'0')*10+(rx[x+13]-'0');
//						VNBR[vnbr_number1].day=(rx[x+14]-'0')*10+(rx[x+15]-'0');
//						VNBR[vnbr_number1].hour=(rx[x+16]-'0')*10+(rx[x+17]-'0');
//						VNBR[vnbr_number1].minute=(rx[x+18]-'0')*10+(rx[x+19]-'0');
//						VNBR[vnbr_number1].second=(rx[x+20]-'0')*10+(rx[x+21]-'0');
//						vnbr_number1++;
//						vnbr_number++;//显示的cnbr
//						idle_number--;//车的个数
//					}
//				}
//			}
//		}
//		if(error)
//		{
			HAL_UART_Transmit(&huart1,(unsigned char*)uart_error,strlen(uart_error),1000);
//			 sprintf(uart_send,uart_error);
//		}
//		HAL_UART_Transmit(&huart1,(unsigned char*)uart_send,strlen(uart_send),1000);//发送部分
//		uart_claer();
//		}	
//	 HAL_UART_Receive_IT(&huart1,rx,22);
//}


void URAT_RECEIVE(void)
{
	int x,y;
	uint8_t error=1;
	HAL_UART_Receive_IT(&huart1,rx,22);
	if((rx[1]!='\0')&&(rx[2]!='\0'))
	{
		for( x=0;x<25;x++)
		{
			if(rx[x]=='C')
			{
				if((rx[x+1]=='N')&&(rx[x+2]=='B')&&(rx[x+3]=='R'))
				{
					int book=1;
					error=0;//正确车型
					if(cnbr_number1)//是否有车辆进入过
					{
						for(y=0;y<cnbr_number1;y++)
						{
							if((cnbr_car[0+y*4]==rx[x+5])&&(cnbr_car[1+y*4]==rx[x+6])&&(cnbr_car[2+y*4]==rx[x+7])&&(cnbr_car[3+y*4]==rx[x+8]))
							{
								book=0;
								compare_year=(rx[x+10]-'0')*10+(rx[x+11]-'0');
								compare_month=(rx[x+12]-'0')*10+(rx[x+13]-'0');
								compare_day=(rx[x+14]-'0')*10+(rx[x+15]-'0');
								compare_hour=(rx[x+16]-'0')*10+(rx[x+17]-'0');
								compare_minute=(rx[x+18]-'0')*10+(rx[x+19]-'0');
								compare_second=(rx[x+20]-'0')*10+(rx[x+21]-'0');//出车的时间
								aa[0]=cnbr_car[0+y*4];
								aa[1]=cnbr_car[1+y*4];
								aa[2]=cnbr_car[2+y*4];
								aa[3]=cnbr_car[3+y*4];//串口传输车牌号aa数组
								if((CNBR[y].minute!=compare_minute)||(compare_second!=CNBR[y].second))//判断时间小于小时部分的决定
								{
									uart_hour=(compare_day-CNBR[y].day)*24+compare_hour-CNBR[y].hour+1;
								}
								else
								{
									uart_hour=(compare_day-CNBR[y].day)*24+compare_hour-CNBR[y].hour;
								}
								uart_mony=uart_hour*cnbr_price;//计算出钱
								sprintf(uart_send, "CNBR:");
								sprintf(&uart_send[5],aa);
								sprintf(bb,":%d:%.2f\r\n",uart_hour,uart_mony/2.0);
								sprintf(&uart_send[9],bb);//组和部分
								HAL_UART_Transmit(&huart1,(unsigned char*)uart_send,strlen(uart_send),1000);//发送部分
								memset(&cnbr_car[y*4],'$',4);
								CNBR[y].year='\0';
								CNBR[y].month='\0';
								CNBR[y].day='\0';
								CNBR[y].hour='\0';
								CNBR[y].minute='\0';
								CNBR[y].second='\0';
								cnbr_number--;//显示的cnbr
								idle_number++;//车的个数
							}
						}
					}
					if(book)//存进去的
					{
						cnbr_car[0+cnbr_number1*4]=rx[x+5];
						cnbr_car[1+cnbr_number1*4]=rx[x+6];
						cnbr_car[2+cnbr_number1*4]=rx[x+7];
						cnbr_car[3+cnbr_number1*4]=rx[x+8];
						CNBR[cnbr_number1].year=(rx[x+10]-'0')*10+(rx[x+11]-'0');
						CNBR[cnbr_number1].month=(rx[x+12]-'0')*10+(rx[x+13]-'0');
						CNBR[cnbr_number1].day=(rx[x+14]-'0')*10+(rx[x+15]-'0');
						CNBR[cnbr_number1].hour=(rx[x+16]-'0')*10+(rx[x+17]-'0');
						CNBR[cnbr_number1].minute=(rx[x+18]-'0')*10+(rx[x+19]-'0');
						CNBR[cnbr_number1].second=(rx[x+20]-'0')*10+(rx[x+21]-'0');
						cnbr_number1++;
						cnbr_number++;//显示的cnbr
						idle_number--;//车的个数
					}
				}
			}
			else if(rx[x]=='V')
			{
				if((rx[x+1]=='N')&&(rx[x+2]=='B')&&(rx[x+3]=='R'))
				{
					int book=1;
					error=0;//正确车型
					if(vnbr_number1)//是否有车辆进入过
					{
						for(y=0;y<vnbr_number1;y++)
						{
							if((vnbr_car[0+y*4]==rx[x+5])&&(vnbr_car[1+y*4]==rx[x+6])&&(vnbr_car[2+y*4]==rx[x+7])&&(vnbr_car[3+y*4]==rx[x+8]))
							{
								book=0;
								compare_year=(rx[x+10]-'0')*10+(rx[x+11]-'0');
								compare_month=(rx[x+12]-'0')*10+(rx[x+13]-'0');
								compare_day=(rx[x+14]-'0')*10+(rx[x+15]-'0');
								compare_hour=(rx[x+16]-'0')*10+(rx[x+17]-'0');
								compare_minute=(rx[x+18]-'0')*10+(rx[x+19]-'0');
								compare_second=(rx[x+20]-'0')*10+(rx[x+21]-'0');//出车的时间
								aa[0]=vnbr_car[0+y*4];
								aa[1]=vnbr_car[1+y*4];
								aa[2]=vnbr_car[2+y*4];
								aa[3]=vnbr_car[3+y*4];//串口传输车牌号aa数组
								if((VNBR[y].minute!=compare_minute)||(compare_second!=VNBR[y].second))//判断时间小于小时部分的决定
								{
									uart_hour=(compare_day-VNBR[y].day)*24+compare_hour-VNBR[y].hour+1;
								}
								else
								{
									uart_hour=(compare_day-VNBR[y].day)*24+compare_hour-VNBR[y].hour;
								}
								uart_mony=uart_hour*vnbr_price;//计算出钱
								sprintf(uart_send, "VNBR:");
								sprintf(&uart_send[5],aa);
								sprintf(bb,":%d:%.2f\r\n",uart_hour,uart_mony/2.0);
								sprintf(&uart_send[9],bb);//组和部分
								HAL_UART_Transmit(&huart1,(unsigned char*)uart_send,strlen(uart_send),1000);//发送部分
								memset(&vnbr_car[y*4],'$',4);
								VNBR[y].year='\0';
								VNBR[y].month='\0';
								VNBR[y].day='\0';
								VNBR[y].hour='\0';
								VNBR[y].minute='\0';
								VNBR[y].second='\0';
								vnbr_number--;//显示的cnbr
								idle_number++;//车的个数
							}
						}
					}
					if(book)//存进去的
					{
						vnbr_car[0+vnbr_number1*4]=rx[x+5];
						vnbr_car[1+vnbr_number1*4]=rx[x+6];
						vnbr_car[2+vnbr_number1*4]=rx[x+7];
						vnbr_car[3+vnbr_number1*4]=rx[x+8];
						VNBR[vnbr_number1].year=(rx[x+10]-'0')*10+(rx[x+11]-'0');
						VNBR[vnbr_number1].month=(rx[x+12]-'0')*10+(rx[x+13]-'0');
						VNBR[vnbr_number1].day=(rx[x+14]-'0')*10+(rx[x+15]-'0');
						VNBR[vnbr_number1].hour=(rx[x+16]-'0')*10+(rx[x+17]-'0');
						VNBR[vnbr_number1].minute=(rx[x+18]-'0')*10+(rx[x+19]-'0');
						VNBR[vnbr_number1].second=(rx[x+20]-'0')*10+(rx[x+21]-'0');
						vnbr_number1++;
						vnbr_number++;//显示的cnbr
						idle_number--;//车的个数
					}
				}
			}
		}
		if(error)
		{
			HAL_UART_Transmit(&huart1,(unsigned char*)uart_error,strlen(uart_error),1000);
//	        sprintf(uart_send,uart_error);
		}
		uart_claer();
	}
	else
	{
		HAL_Delay(100);
	}
//	HAL_UART_Transmit(&huart1,(unsigned char*)uart_send,strlen(uart_send),1000);//发送部分
//	uart_transmit_claer();
}
void led(void)
{
	if(idle_number>0)
	{
		HAL_GPIO_WritePin(GPIOC,GPIO_PIN_8, GPIO_PIN_RESET);
		HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
		HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
	}
}
void uart_claer(void)
{
	unsigned int z=0;
	for(z=0;z<50;z++)
	{
		rx[z]='\0';
	}
}
void pwm_set(void)
{
	int x;
	if(pwm_mode)
	{
		x=0;
		HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_8
                          |GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12, GPIO_PIN_SET);
		HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
		HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
		__HAL_TIM_SetCompare(&htim3,TIM_CHANNEL_2,x);
	}
	else
	{
		x=20;
	    HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_8
                          |GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12, GPIO_PIN_SET);
		HAL_GPIO_WritePin(GPIOC,GPIO_PIN_9, GPIO_PIN_RESET);
		HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
		HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
		__HAL_TIM_SetCompare(&htim3,TIM_CHANNEL_2,x);
	}
}

void uart_transmit_claer(void)
{
	unsigned int z=0;
	for(z=0;z<50;z++)
	{
		uart_send[z]='\0';
	}
}
/**
  * @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 */

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

12届


/* 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 "tim.h"
#include "usart.h"
#include "gpio.h"
#include "lcd.h"
#include "stdio.h"
#include "string.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

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

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
void lcd_action(void);
void led_action(void);
void pwm_action(void);
void uart_action(void);
void uart_rx(void);
void uart_tx(void);
void right(void);
/* USER CODE BEGIN PFP */
int view=1;
char bi[30],b2[30],b3[30];
uint8_t rx;
char uart_recive[30];
unsigned char uart_point=0;
unsigned char lcd_suo[4]="@@@";
int key_suo[4]={-1,-1,-1},MI_MA[4]={1,2,3};
unsigned char key_number=0,key_caton=0;
unsigned char key_down1=0,key_down2=0,key_down3=0;
char b1_lcd[30],b3_lcd[30],b2_lcd[30];
unsigned char cout_timer=0,time_5s=0,flag=0;
unsigned char pwm_set=1;
unsigned char ereor=0;
unsigned char cout_timer1=0;
/* 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_TIM1_Init();
  MX_TIM2_Init();
  MX_TIM3_Init();
  MX_USART1_UART_Init();
  LCD_Init();
  /* USER CODE BEGIN 2 */
	LCD_Clear(Black);
	HAL_TIM_Base_Start_IT(&htim1);
	HAL_TIM_Base_Start_IT(&htim3);
	HAL_TIM_PWM_Start(&htim2,TIM_CHANNEL_2);
	HAL_UART_Receive_IT(&huart1,&rx, 1);
  /* USER CODE END 2 */
	HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_8
                          |GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12, GPIO_PIN_SET);
	HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
	HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */
	 led_action(); 
	 lcd_action(); 
	  right();
	 pwm_action();
	 uart_action();
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
	uart_recive[uart_point++]=rx;
	HAL_UART_Receive_IT(&huart1,&rx, 1);
}
void right(void)
{
	if(time_5s)
	{
		time_5s=0;
		view=1;
		pwm_set=1;
	}
	if(ereor==3)
	{
		ereor=0;
		flag=2;
	}
}
void lcd_action(void)
{
	if(view)
	{
		if(key_down1)
			sprintf(b1_lcd,"    B1:%d          ",key_suo[0]);
		else sprintf(b1_lcd,"    B1:%c              ",lcd_suo[0]);
		if(key_down2)
	    	sprintf(b2_lcd,"    B2:%d          ",key_suo[1]);
		else sprintf(b2_lcd,"    B2:%c              ",lcd_suo[1]);
		if(key_down3)
			sprintf(b3_lcd,"    B3:%d          ",key_suo[2]);
		else sprintf(b3_lcd,"    B3:%c              ",lcd_suo[2]);
		LCD_SetTextColor(White);
		LCD_SetBackColor(Black);
		LCD_DisplayStringLine(Line0, (u8 *)"                    ");
		LCD_DisplayStringLine(Line1, (u8 *)"       PSD          ");
		LCD_DisplayStringLine(Line2, (u8 *)"                    ");
		LCD_DisplayStringLine(Line3, (u8 *)"                    ");
		LCD_DisplayStringLine(Line4, (u8 *)b1_lcd);
		LCD_DisplayStringLine(Line5, (u8 *)b2_lcd);
		LCD_DisplayStringLine(Line6, (u8 *)b3_lcd);
		LCD_DisplayStringLine(Line7, (u8 *)"                    ");
		LCD_DisplayStringLine(Line8, (u8 *)"                    ");
		LCD_DisplayStringLine(Line9, (u8 *)"                    ");
	}
	else
	{
		LCD_SetTextColor(White);
		LCD_SetBackColor(Black);
		LCD_DisplayStringLine(Line0, (u8 *)"                    ");
		LCD_DisplayStringLine(Line1, (u8 *)"       STA          ");
		LCD_DisplayStringLine(Line2, (u8 *)"                    ");
		LCD_DisplayStringLine(Line3, (u8 *)"                    ");
		LCD_DisplayStringLine(Line4, (u8 *)"    F:2000HZ        ");
		LCD_DisplayStringLine(Line5, (u8 *)"    D:10%           ");
		LCD_DisplayStringLine(Line6, (u8 *)"                    ");
		LCD_DisplayStringLine(Line7, (u8 *)"                    ");
		LCD_DisplayStringLine(Line8, (u8 *)"                    ");
		LCD_DisplayStringLine(Line9, (u8 *)"                    ");
	}
}
void led_action(void)
{
	if(flag==1)
	{
		HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_8
                          |GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12, GPIO_PIN_SET);
		HAL_GPIO_WritePin(GPIOC, GPIO_PIN_8, GPIO_PIN_RESET);
		HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
		HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
	}
	else if(flag==2)
	{
		HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_8
                          |GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12, GPIO_PIN_SET);
		HAL_GPIO_WritePin(GPIOC, GPIO_PIN_9, GPIO_PIN_RESET);
		HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
		HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
	}
	else
	{
		HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_8
                          |GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12, GPIO_PIN_SET);
		HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
		HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
	}
}
void pwm_action(void)
{
	if(pwm_set)
	{
		__HAL_TIM_SET_AUTORELOAD(&htim2,99);
		__HAL_TIM_SET_COMPARE(&htim2,TIM_CHANNEL_2,50);
	}
	else
	{
		__HAL_TIM_SET_AUTORELOAD(&htim2,49);
		__HAL_TIM_SET_COMPARE(&htim2,TIM_CHANNEL_2,5);
	}
}
void uart_action(void)
{
	if(uart_point!=0)
	{
		HAL_Delay(20);
		uart_rx();
		memset(uart_recive,0,30);
	}
	uart_tx();
}
void uart_rx(void)
{
	int x;
	uart_point=0;
	for(x=0;x<30;x++)
	{
		if(uart_recive[0]==(MI_MA[0]+'0'))
		{
			if(uart_recive[1]==(MI_MA[1]+'0'))
			{
				if(uart_recive[2]==(MI_MA[2]+'0'))
				{
					MI_MA[0]=uart_recive[4]-'0';
					MI_MA[1]=uart_recive[5]-'0';
					MI_MA[2]=uart_recive[6]-'0';
				}
			}
		}
	}
}
void uart_tx(void)
{
	
}
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
	if(htim->Instance==TIM1)
	{
		switch(key_number)
		{
			case 0:
				if(!HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_0)||!HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_1)||!HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_2)||!HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0))
				{
					key_number=9;
				}
				break;
			case 9:
				if(!HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_0))
				{
					key_number=1;
					key_caton=1;
				}else if(!HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_1))
				{
					key_number=2;
					key_caton=1;
				}else if(!HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_2))
				{
					key_number=3;
					key_caton=1;
				}else if(!HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0))
				{
					key_number=4;
					key_caton=1;
				}else
				{
					key_number=0;
				}
				break;
			case 1:
				if(HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_0))
				{
					key_number=0;
				}
				break;
			case 2:
				if(HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_1))
				{
					key_number=0;
				}
				break;
			case 3:
				if(HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_2))
				{
					key_number=0;
				}
				break;
			case 4:
				if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0))
				{
					key_number=0;
				}
				break;
			default:break;
		}
		switch(key_number)
		{
			case 1:
				if(key_caton)
				{
					key_caton=0;
					key_down1=1;
					key_suo[0]++;
					key_suo[0]=key_suo[0]%10;
				}
				break;
			case 2:
				if(key_caton)
				{
					key_caton=0;
					key_down2=1;
					key_suo[1]++;
					key_suo[1]=key_suo[1]%10;
				}
				break;
			case 3:
				if(key_caton)
				{
					key_caton=0;
					key_down3=1;
					key_suo[2]++;
					key_suo[2]=key_suo[2]%10;
				}
				break;
			case 4:
				if(key_caton)
				{
					key_caton=0;
					key_down1=0;
					key_down2=0;
					key_down3=0;
					if((MI_MA[0]==key_suo[0])&&(MI_MA[1]==key_suo[1])&&(MI_MA[2]==key_suo[2]))
					{
						flag=1;
						view=0;
						pwm_set=0;
					}
					else
					{
						ereor++;
					}
					key_suo[0]=-1;
					key_suo[1]=-1;
					key_suo[2]=-1;
				}
				break;
			default:break;
		}
	}
	if(htim->Instance==TIM3)
	{
		if(flag==1)
		{
			if(cout_timer<50)
			{
				cout_timer++;
			}
			else
			{
				cout_timer=0;
				flag=0;
				time_5s=1;
			}
		}
		
		if(flag==2)
		{
			if(cout_timer1<50)
			{
				cout_timer1++;
			}
			else
			{
				cout_timer1=0;
				flag=0;	
			}
		}
	}
}

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

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

13届


上面主要是逻辑自己写的代码,其他都是软件自己生成;完整程序加3212756914QQ

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值