晚上才想起写一下,也是比较晚了。先把代码放上来。
各位好友尽请参考。
后面会给出
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* © Copyright (c) 2021 STMicroelectronics.
* All rights reserved.
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "function.h"
#include "lcd.h"
#include "stdio.h"
#include "string.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 ---------------------------------------------------------*/
TIM_HandleTypeDef htim3;
UART_HandleTypeDef huart1;
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_TIM3_Init(void);
static void MX_USART1_UART_Init(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
uint8_t CNBR, VNBR, DILE;
float CNBR_fee, VNBR_fee;
uint8_t mode;
uint8_t Got_Car;
Car_type Car_info[8];
Car_type Now_Car;
uint8_t arr[40];
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
uint8_t key, Save, i;
uint8_t ass[40];
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_TIM3_Init();
MX_USART1_UART_Init();
/* USER CODE BEGIN 2 */
HAL_TIM_PWM_Start(&htim3,TIM_CHANNEL_2);
TIM3->CCR2 = 0;
LCD_Init();
LCD_Clear(Black);
LCD_SetBackColor(Black);
LCD_SetTextColor(White);
GPIOC->ODR |= 0xff00;
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2,GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2,GPIO_PIN_RESET);
key = 0;
Save = 0;
CNBR_fee = 3.5;
VNBR_fee = 2.0;
CNBR = VNBR = 0;
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
Display();
key = KEY_Scan();
if(key) KEY_Handle(key);
HAL_UART_Receive_IT(&huart1,arr,24);
DILE = 8-CNBR-VNBR;
if(Got_Car)//收到车辆信息
{
Got_Car = 0;
Save = Confirm();
if(Save)
{
for(i = 0; i < 8; i++)
{
if(Car_info[i].NBR == Now_Car.NBR && strcmp((char *)Car_info[i].Name,(char *)Now_Car.Name) == 0)
{
Save = 0;
Output_A_Car(i);
break;
}
}
if(Save)
{
for(i = 0; i < 8; i++)
{
if(Car_info[i].NBR != 'C' && Car_info[i].NBR != 'V')
{
Save = 0;
Input_A_Car(i);
break;
}
}
}
}
else
{
sprintf((char *)ass,"ERROR");
HAL_UART_Transmit(&huart1, ass, sizeof(ass), 50);
}
}
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
/* LD1亮 */
if(DILE>0)
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_8, GPIO_PIN_RESET);
else
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_8, GPIO_PIN_SET);
GPIOC->ODR |= 0xfe00;
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2,GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2,GPIO_PIN_RESET);
}
/* USER CODE END 3 */
}
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {
0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {
0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {
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_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV2;
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();
}
/** Initializes the peripherals clocks
*/
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1;
PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
}
/**
* @brief TIM3 Initialization Function
* @param None
* @retval None
*/
static void MX_TIM3_Init(void)
{
/* USER CODE BEGIN TIM3_Init 0 */
/* USER CODE END TIM3_Init 0 */
TIM_ClockConfigTypeDef sClockSourceConfig = {
0};
TIM_MasterConfigTypeDef sMasterConfig = {
0};
TIM_OC_InitTypeDef sConfigOC = {
0};
/* USER CODE BEGIN TIM3_Init 1 */
/* USER CODE END TIM3_Init 1 */
htim3.Instance = TIM3;
htim3.Init.Prescaler = 80-1;
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
htim3.Init.Period = 499;
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim3) != HAL_OK)
{
Error_Handler();
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig) != HAL_OK)
{
Error_Handler();
}
if (HAL_TIM_PWM_Init(&htim3) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
sConfigOC.OCMode = TIM_OCMODE_PWM1;
sConfigOC.Pulse = 0;
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN TIM3_Init 2 */
/* USER CODE END TIM3_Init 2 */
HAL_TIM_MspPostInit(&htim3);
}
/**
* @brief USART1 Initialization Function
* @param None
* @retval None
*/
static void MX_USART1_UART_Init(void)
{
/* USER CODE BEGIN USART1_Init 0 */
/* USER CODE END USART1_Init 0 */
/* USER CODE BEGIN USART1_Init 1 */
/* USER CODE END USART1_Init 1 */
huart1.Instance = USART1;
huart1.Init.BaudRate = 9600;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart1.Init.ClockPrescaler = UART_PRESCALER_DIV1;
huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart1) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_SetTxFifoThreshold(&huart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_SetRxFifoThreshold(&huart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_DisableFifoMode(&huart1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN USART1_Init 2 */
/* USER CODE END USART1_Init 2 */
}
/**
* @brief GPIO Initialization Function
* @param None
* @retval None
*/
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {
0};
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOF_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_0
|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4
|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8
|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5|GPIO_PIN_8|GPIO_PIN_9, GPIO_PIN_RESET);
/*Configure GPIO pins : PC13 PC14 PC15 PC0
PC1 PC2 PC3 PC4
PC5 PC6 PC7 PC8
PC9 PC10 PC11 PC12 */
GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_0
|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4
|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8
|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/*Configure GPIO pin : PA0 */
GPIO_InitStruct.Pin = GPIO_PIN_0;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pins : PB0 PB1 PB2 */
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/*Configure GPIO pin : PA8 */
GPIO_InitStruct.Pin = GPIO_PIN_8;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pin : PD2 */
GPIO_InitStruct.Pin = GPIO_PIN_2;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
/*Configure GPIO pins : PB5 PB8 PB9 */
GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_8|GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
}
/* 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 */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
.c
#include "function.h"
#include "stdio.h"
#include "lcd.h"
#include "string.h"
uint8_t str[40];
uint8_t Month[] = {
0,31,28,31,30,31,30,31,31,30,31,30,31};
uint8_t app[40];
void Display(void)
{
if(mode == 0)
{
sprintf((char *)str," Para");
LCD_DisplayStringLine(Line2,str);
sprintf((char *)str," CNBR:%d",CNBR);
LCD_DisplayStringLine(Line4,str);
sprintf((char *)str," VNBR:%d",VNBR);
LCD_DisplayStringLine(Line6,str);
sprintf((char *)str," DILE:%d",DILE);
LCD_DisplayStringLine(Line8,str);
}
else if(mode == 1)
{
sprintf((char *)str," Data");
LCD_DisplayStringLine(Line2,str);
sprintf((char *)str," CNBR:%.2f",CNBR_fee);
LCD_DisplayStringLine(Line4,str);
sprintf((char *)str," VNBR:%.2f",VNBR_fee);
LCD_DisplayStringLine(Line6,str);
}
}
uint8_t KEY_Scan(void)
{
static uint8_t flag=1;//单独按键,防止连按
if(flag &&(KEY_B1 == 0 || KEY_B2 == 0 || KEY_B3 == 0 || KEY_B4== 0 ))
{
HAL_Delay(10);//消抖
flag = 0;
if (KEY_B1 == 0) return B1_Press;
else if (KEY_B2 == 0) return B2_Press;
else if (KEY_B3 == 0) return B3_Press;
else if (KEY_B4 == 0) return B4_Press;
}else if(KEY_B1 == KEY_B2 == KEY_B3 == KEY_B4 == 1) flag = 1;
return 0;
}
void KEY_Handle(uint8_t key)
{
static uint8_t output = 0;
if(key == B1_Press)
{
mode = !mode;
LCD_Clear(Black);
}
else if(key == B2_Press && mode == 1)
{
CNBR_fee += 0.5f;
VNBR_fee += 0.5f;
}
else if(key == B3_Press && mode == 1)
{
CNBR_fee -= 0.5f;
VNBR_fee -= 0.5f;
}
else if(key == B4_Press)
{
output = !output;
if(output)
TIM3->CCR2 = 100;
else
TIM3->CCR2 = 0;
}
}
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)//中断时间有要求所以不做过多处理
{
/*
CNBR:B001: 2 0 0 4 1 8 0 9 0 0 0 0
0123456789 10 11 12 13 14 15 16 17 18 19 20 21 22
*/
Now_Car.NBR = arr[0];
Now_Car.Name[0] = arr[5];
Now_Car.Name[1] = arr[6];
Now_Car.Name[2] = arr[7];
Now_Car.Name[3] = arr[8];
Now_Car.Year = (arr[10]-'0')*10+(arr[11]-'0');
Now_Car.Month = (arr[12]-'0')*10+(arr[13]-'0');
Now_Car.Day = (arr[14]-'0')*10+(arr[15]-'0');
Now_Car.Hour = (arr[16]-'0')*10+(arr[17]-'0');
Now_Car.Minute = (arr[18]-'0')*10+(arr[19]-'0');
Now_Car.Second = (arr[20]-'0')*10+(arr[21]-'0');
Got_Car = 1;
memset(arr,0,sizeof(arr));
}
uint8_t Confirm(void)
{
uint16_t Year;
if((Now_Car.NBR == 'C' || Now_Car.NBR == 'V') && Now_Car.Second < 60 && Now_Car.Minute < 60 && Now_Car.Hour < 23)
{
Year = 2000 + Now_Car.Year;
if(Now_Car.Month == 1 || Now_Car.Month == 3 || Now_Car.Month == 5 || Now_Car.Month == 7 || Now_Car.Month == 8 || Now_Car.Month == 10 || Now_Car.Month == 12)//如果月份1、3、5、7、8、10、12,天数小于32
{
if(Now_Car.Day > 31)
return 0;
}
else if(Now_Car.Month == 4 || Now_Car.Month == 6 || Now_Car.Month == 9 || Now_Car.Month == 11)//如果月份4、6、9、11,天数小于31
{
if(Now_Car.Day > 30)
return 0;
}
else if(Year % 400 == 0 || (Year % 4 == 0 && Year % 100 != 0))//判断年份是闰年
{
if(Now_Car.Day > 28)
return 0;
}
else
{
if(Now_Car.Day > 29)
return 0;
}
return 1;
}
else
return 0;
}
void Output_A_Car(uint8_t location)
{
float fee = 0;
uint16_t i;
uint32_t Second, Second_aim;
uint8_t time;
/* 以2000开始,计算从2000到该时间过的秒 */
for(i = 2000; i < 2000+Car_info[location].Year ; i++)
{
if(i % 400 == 0 || (i % 4 == 0 && i % 100 != 0))//判断年份是闰年
{
Second += 366*24*60*60;
}
else
Second += 365*24*60*60;
}
for(i = 1; i < Car_info[location].Month ; i++)
{
Second += Month[i];
if(i % 400 == 0 || (i % 4 == 0 && i % 100 != 0))//判断年份是闰年
{
Second++;
}
}
for(i = 1; i < Car_info[location].Day; i++)
{
Second += 24*60*60;
}
for(i = 1; i < Car_info[location].Hour; i++)
{
Second += 60*60;
}
for(i = 1; i < Car_info[location].Minute; i++)
{
Second += 60;
}
Second += Car_info[location].Second;
/* Second_aim */
for(i = 2000; i < 2000+Now_Car.Year ; i++)
{
if(i % 400 == 0 || (i % 4 == 0 && i % 100 != 0))//判断年份是闰年
{
Second_aim += 366*24*60*60;
}
else
Second_aim += 365*24*60*60;
}
for(i = 1; i < Now_Car.Month ; i++)
{
Second_aim += Month[i];
if(i % 400 == 0 || (i % 4 == 0 && i % 100 != 0))//判断年份是闰年
{
Second_aim++;
}
}
for(i = 1; i < Now_Car.Day; i++)
{
Second_aim += 24*60*60;
}
for(i = 1; i < Now_Car.Hour; i++)
{
Second_aim += 60*60;
}
for(i = 1; i < Now_Car.Minute; i++)
{
Second_aim += 60;
}
Second_aim += Now_Car.Second;
/* 秒数抓化成小时 */
time = (uint8_t)(Second_aim - Second)/60/60;
if((Second_aim - Second) > time*60*60)
{
time++;//余数补偿
}
// sprintf((char *)app,"%.2d%.2d%.2d%.2d%.2d%.2d%d\r\n",Car_info[location].Year, Car_info[location].Month,Car_info[location].Day
// ,Car_info[location].Hour,Car_info[location].Minute,Car_info[location].Second,Second);
// HAL_UART_Transmit(&huart1, app, sizeof(app), 200);
// sprintf((char *)app,"%.2d%.2d%.2d%.2d%.2d%.2d%d\r\n",Now_Car.Year, Now_Car.Month,Now_Car.Day
// ,Now_Car.Hour,Now_Car.Minute,Now_Car.Second,Second_aim);
// HAL_UART_Transmit(&huart1, app, sizeof(app), 200);
/* 计算费用 */
if(Now_Car.NBR == 'C')
{
fee = time*CNBR_fee;
CNBR--;
}
else
{
fee = time*VNBR_fee;
VNBR--;
}
sprintf((char *)app,"%cNBR:%.2d:%3.2f",Car_info[location].NBR,time,fee);
HAL_UART_Transmit(&huart1, app, sizeof(app), 0xfff);
/* 清除车辆信息 */
Car_info[location].NBR = '\0';
memset(Car_info[location].Name,0,sizeof(Car_info[location].Name));
Car_info[location].Year = 0;
Car_info[location].Month = 0;
Car_info[location].Day = 0;
Car_info[location].Hour = 0;
Car_info[location].Minute = 0;
Car_info[location].Second = 0;
}
void Input_A_Car(uint8_t location)
{
if(Now_Car.NBR == 'C')
CNBR++;
else
VNBR++;
Car_info[location].NBR = Now_Car.NBR;
strcpy((char *)Car_info[location].Name, (char *)Now_Car.Name);
Car_info[location].Year = Now_Car.Year;
Car_info[location].Month = Now_Car.Month;
Car_info[location].Day = Now_Car.Day;
Car_info[location].Hour = Now_Car.Hour;
Car_info[location].Minute = Now_Car.Minute;
Car_info[location].Second = Now_Car.Second;
}
.h
#ifndef __function_h
#define __function_h
#include "main.h"
#define KEY_B1 HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_0)
#define KEY_B2 HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_1)
#define KEY_B3 HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_2)
#define KEY_B4 HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0)
#define B1_Press 1
#define B2_Press 2
#define B3_Press 3
#define B4_Press 4
typedef struct{
char NBR;
uint8_t Name[4];
uint8_t Year;
uint8_t Month;
uint8_t Day;
uint8_t Hour;
uint8_t Minute;
uint8_t Second;
}Car_type;
extern uint8_t CNBR, VNBR ,DILE;
extern float CNBR_fee, VNBR_fee;
extern uint8_t mode;
extern uint8_t Got_Car;
extern Car_type Car_info[8];
extern Car_type Now_Car;
extern uint8_t arr[40];
extern UART_HandleTypeDef huart1;
void Display(void);
uint8_t KEY_Scan(void);
void KEY_Handle(uint8_t key);
uint8_t Confirm(void);
void Output_A_Car(uint8_t location);
void Input_A_Car(uint8_t location);
#endif
第一次参加模拟赛,嘿嘿,感jio还是不一样。
昨天完成了,一直没时间写,见谅,嘿嘿。
点个赞吧,最近都没赞了,心头拔凉拔凉的。┭┮﹏┭┮