蓝桥杯嵌入式2023年第十四届省赛主观题解析

1  题目

2  代码

/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "adc.h"
#include "rtc.h"
#include "tim.h"
#include "gpio.h"/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "stdio.h"
#include "string.h"
#include "lcd.h"
/* USER CODE END Includes *//* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
double v;
char buf1[20],buf2[20],buf3[20],buf4[20],buf5[20],buf6[20],buf7[20],buf8[20],buf9[20],buf10[20],buf11[20],buf12[20],buf13[20];
struct keys{int state;int step;int cnt;int cnt2;
}key[5];
double f=250,duty=0.2;
int N;
uint32_t OCcnt=0;
int state;
int start,end,R=1,K=1,TR=1,TK=1;
double V,f7,cnt,hmax,lmax;
int time,SR;
RTC_TimeTypeDef sTime = {0};
RTC_DateTypeDef sDate = {0};
RTC_AlarmTypeDef sAlarm = {0};
/* 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);
/* USER CODE BEGIN PFP */
void getADC()
{HAL_ADC_Start(&hadc2);v=HAL_ADC_GetValue(&hadc2)*3.3/4096;
}
void LED_Close()
{HAL_GPIO_WritePin(GPIOD,GPIO_PIN_2,GPIO_PIN_SET);HAL_GPIO_WritePin(GPIOC,GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15,GPIO_PIN_SET);HAL_GPIO_WritePin(GPIOD,GPIO_PIN_2,GPIO_PIN_RESET);
}
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{if(htim->Instance==TIM3&&htim->Channel==HAL_TIM_ACTIVE_CHANNEL_2){cnt=HAL_TIM_ReadCapturedValue(&htim3,TIM_CHANNEL_2);f7=1000000/cnt;__HAL_TIM_SetCounter(&htim3,0);HAL_TIM_IC_Start_IT(&htim3,TIM_CHANNEL_1);}
}
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{if(htim->Instance==TIM1){key[1].state=HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_0);key[2].state=HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_1);key[3].state=HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_2);key[4].state=HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0);switch(key[1].step){case 0:{if(key[1].state==GPIO_PIN_RESET){key[1].step=1;}}break;case 1:{if(key[1].state==GPIO_PIN_RESET){key[1].step=2;key[1].cnt++;LCD_Clear(White);if(key[1].cnt%3==0){LCD_DisplayStringLine(Line1,(uint8_t*)buf1);LCD_DisplayStringLine(Line3,(uint8_t*)buf2);LCD_DisplayStringLine(Line4,(uint8_t*)buf3);LCD_DisplayStringLine(Line5,(uint8_t*)buf4);}if(key[1].cnt%3==1){LCD_DisplayStringLine(Line1,(uint8_t*)buf5);LCD_SetBackColor(Green);LCD_ClearLine(Line3);LCD_DisplayStringLine(Line3,(uint8_t*)buf6);LCD_SetBackColor(White);LCD_DisplayStringLine(Line4,(uint8_t*)buf7);}if(key[1].cnt%3==2){LCD_DisplayStringLine(Line1,(uint8_t*)buf8);LCD_DisplayStringLine(Line3,(uint8_t*)buf9);LCD_DisplayStringLine(Line4,(uint8_t*)buf10);LCD_DisplayStringLine(Line5,(uint8_t*)buf11);}}else{key[1].step=0;}}break;case 2:{if(key[1].state==GPIO_PIN_SET){key[1].step=0;}}break;}switch(key[2].step){case 0:{if(key[2].state==GPIO_PIN_RESET&&key[1].cnt%3!=2){key[2].step=1;}}break;case 1:{if(key[2].state==GPIO_PIN_RESET){key[2].step=2;if(key[1].cnt%3==0){if(state==1){end=uwTick;if(end-start>=1000*5){state=0;}}if(state==0){key[2].cnt++;}}if(key[1].cnt%3==1){key[2].cnt2++;}}else{key[2].step=0;}}break;case 2:{if(key[2].state==GPIO_PIN_SET){key[2].step=0;}}break;}switch(key[3].step){case 0:{if(key[3].state==GPIO_PIN_RESET){key[3].step=1;}}break;case 1:{if(key[3].state==GPIO_PIN_RESET){key[3].step=2;if(key[2].cnt2%2==0){TR++;if(TR>10) TR=1;sprintf(buf6,"     R=%d",TR);LCD_ClearLine(Line3);LCD_DisplayStringLine(Line3,(uint8_t*)buf6);}else{TK++;if(TK>10) TK=1;sprintf(buf7,"     K=%d",TK);LCD_ClearLine(Line4);LCD_DisplayStringLine(Line4,(uint8_t*)buf7);}}else{key[3].step=0;}}break;case 2:{if(key[3].state==GPIO_PIN_SET){key[3].step=0;}}break;}if(key[1].cnt%3==1){switch(key[4].step){case 0:{if(key[4].state==GPIO_PIN_RESET){key[4].step=1;}}break;case 1:{if(key[4].state==GPIO_PIN_RESET){key[4].step=2;if(key[2].cnt2%2==0){TR--;if(TR<=0) TR=10;sprintf(buf6,"     R=%d",TR);LCD_ClearLine(Line3);LCD_DisplayStringLine(Line3,(uint8_t*)buf6);}else{TK--;if(TK<=0) TK=10;sprintf(buf7,"     K=%d",TK);LCD_ClearLine(Line4);LCD_DisplayStringLine(Line4,(uint8_t*)buf7);}}else{key[4].step=0;}}break;case 2:{if(key[4].state==GPIO_PIN_SET){key[4].step=0;}}break;}}if(key[1].cnt%3==0){switch(key[4].step){case 0:{if(key[4].state==GPIO_PIN_RESET){key[4].step=1;time=0;}}break;case 1:{if(key[4].state==GPIO_PIN_RESET){key[4].step=2;}else{key[4].step=0;}}break;case 2:{if(key[4].state==GPIO_PIN_RESET){time++;}if(key[4].state==GPIO_PIN_SET){if(time>200){SR=1;}else{SR=0;}key[4].step=0;}}break;}}}if(htim->Instance==TIM4){V=f7*2*3.14*R/100/K;sprintf(buf4,"     V=%.1lf",V);sprintf(buf3,"     P=%.0lf%%",duty*100);if(key[1].cnt%3==0){LCD_ClearLine(Line4);LCD_ClearLine(Line5);LCD_DisplayStringLine(Line5,(uint8_t*)buf4);LCD_DisplayStringLine(Line4,(uint8_t*)buf3);HAL_GPIO_WritePin(GPIOD,GPIO_PIN_2,GPIO_PIN_SET);HAL_GPIO_WritePin(GPIOC,GPIO_PIN_8,GPIO_PIN_RESET);HAL_GPIO_WritePin(GPIOD,GPIO_PIN_2,GPIO_PIN_RESET);}if(key[1].cnt%3!=0){HAL_GPIO_WritePin(GPIOD,GPIO_PIN_2,GPIO_PIN_SET);HAL_GPIO_WritePin(GPIOC,GPIO_PIN_8,GPIO_PIN_SET);HAL_GPIO_WritePin(GPIOD,GPIO_PIN_2,GPIO_PIN_RESET);}if(key[1].cnt%3!=1){R=TR;K=TK;key[2].cnt2=0;}if(key[2].cnt%2==0){if(V>lmax){lmax=V;sprintf(buf11,"     NL=%.1lf",lmax);}}if(key[2].cnt%2==1){if(V>hmax){hmax=V;sprintf(buf10,"     NH=%.1lf",hmax);}}if(key[1].cnt%3==2){LCD_ClearLine(Line3);LCD_ClearLine(Line4);LCD_ClearLine(Line5);LCD_DisplayStringLine(Line5,(uint8_t*)buf11);LCD_DisplayStringLine(Line4,(uint8_t*)buf10);LCD_DisplayStringLine(Line3,(uint8_t*)buf9);}if(SR==1){HAL_GPIO_WritePin(GPIOD,GPIO_PIN_2,GPIO_PIN_SET);HAL_GPIO_WritePin(GPIOC,GPIO_PIN_10,GPIO_PIN_RESET);HAL_GPIO_WritePin(GPIOD,GPIO_PIN_2,GPIO_PIN_RESET);}else{HAL_GPIO_WritePin(GPIOD,GPIO_PIN_2,GPIO_PIN_SET);HAL_GPIO_WritePin(GPIOC,GPIO_PIN_10,GPIO_PIN_SET);HAL_GPIO_WritePin(GPIOD,GPIO_PIN_2,GPIO_PIN_RESET);}if(key[1].cnt%3==1){LCD_ClearLine(Line3);LCD_ClearLine(Line4);LCD_SetBackColor(Green);if(key[2].cnt2%2==0){LCD_ClearLine(Line3);LCD_DisplayStringLine(Line3,(uint8_t*)buf6);LCD_SetBackColor(White);LCD_DisplayStringLine(Line4,(uint8_t*)buf7);}else{LCD_ClearLine(Line4);LCD_DisplayStringLine(Line4,(uint8_t*)buf7);LCD_SetBackColor(White);LCD_DisplayStringLine(Line3,(uint8_t*)buf6);}}}if(htim->Instance==TIM6){if(f>125&&f<250){HAL_GPIO_WritePin(GPIOD,GPIO_PIN_2,GPIO_PIN_SET);HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_9);HAL_GPIO_WritePin(GPIOD,GPIO_PIN_2,GPIO_PIN_RESET);}else{HAL_GPIO_WritePin(GPIOD,GPIO_PIN_2,GPIO_PIN_SET);HAL_GPIO_WritePin(GPIOC,GPIO_PIN_9,GPIO_PIN_SET);HAL_GPIO_WritePin(GPIOD,GPIO_PIN_2,GPIO_PIN_RESET);}}
}
void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim)
{if(htim->Instance==TIM2&&htim->Channel==HAL_TIM_ACTIVE_CHANNEL_2){OCcnt=__HAL_TIM_GetCompare(&htim2,TIM_CHANNEL_2);if(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_1)==GPIO_PIN_RESET){__HAL_TIM_SetCompare(&htim2,TIM_CHANNEL_2,OCcnt+f*(1-duty));}else{__HAL_TIM_SetCompare(&htim2,TIM_CHANNEL_2,OCcnt+f*duty);}}
}
void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc)
{HAL_RTC_GetDate(hrtc,&sDate,RTC_FORMAT_BIN);HAL_RTC_GetTime(hrtc,&sTime,RTC_FORMAT_BIN);sprintf(buf13,"   TIME:%02d-%02d-%02d",sTime.Hours,sTime.Minutes,sTime.Seconds);sprintf(buf12,"   DATE:%02d-%02d-%02d",sDate.Year,sDate.Month,sDate.Date);LCD_ClearLine(Line8);LCD_ClearLine(Line9);LCD_DisplayStringLine(Line8,(uint8_t*)buf13);LCD_DisplayStringLine(Line9,(uint8_t*)buf12);
}
/* 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_ADC2_Init();MX_TIM3_Init();MX_TIM4_Init();MX_RTC_Init();MX_TIM6_Init();/* USER CODE BEGIN 2 */LCD_Init();LED_Close();LCD_Clear(White);LCD_SetBackColor(White);LCD_SetTextColor(Black);HAL_TIM_Base_Start_IT(&htim1);HAL_TIM_Base_Start_IT(&htim4);HAL_TIM_Base_Start_IT(&htim6);HAL_TIM_OC_Start_IT(&htim2,TIM_CHANNEL_2);HAL_TIM_PWM_Start(&htim2,TIM_CHANNEL_2);HAL_TIM_IC_Start_IT(&htim3,TIM_CHANNEL_2);HAL_TIM_IC_Start_IT(&htim3,TIM_CHANNEL_1);__HAL_TIM_SetCompare(&htim2,TIM_CHANNEL_2,500);sprintf(buf1,"        DATA");sprintf(buf2,"     M=L");sprintf(buf8,"        RECD");sprintf(buf5,"        PARA");sprintf(buf6,"     R=1");sprintf(buf7,"     K=1");sprintf(buf10,"     NH=0.0");LCD_DisplayStringLine(Line1,(uint8_t*)buf1);LCD_DisplayStringLine(Line3,(uint8_t*)buf2);LCD_DisplayStringLine(Line4,(uint8_t*)buf3);LCD_DisplayStringLine(Line5,(uint8_t*)buf4);/* USER CODE END 2 *//* Infinite loop *//* USER CODE BEGIN WHILE */while (1){/* USER CODE END WHILE *//* USER CODE BEGIN 3 */getADC();if(SR==0){if(v>=1&&v<=3) duty=0.375*v-0.275;if(v<1) duty=0.1;if(v>3) duty=0.85;}if(key[1].cnt%3==0&&key[2].cnt%2==1&&state==0){N++;state=1;start=uwTick;for(int i=4000;i<=8000;i+=100){f=1000000/i;HAL_Delay(100);}sprintf(buf2,"     M=H");LCD_ClearLine(Line3);LCD_DisplayStringLine(Line3,(uint8_t*)buf2);}if(key[1].cnt%3==0&&key[2].cnt%2==0&&key[2].cnt>0&&state==0){N++;state=1;start=uwTick;for(int i=8000;i>=4000;i-=100){f=1000000/i;HAL_Delay(100);}sprintf(buf2,"     M=L");LCD_ClearLine(Line3);LCD_DisplayStringLine(Line3,(uint8_t*)buf2);}sprintf(buf9,"     N=%d",N);}/* USER CODE END 3 */
}

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

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

搭建Grafana+Prometheus监控Spring Boot应用

Spring项目改造 maven依赖 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId> </dependency><dependency><groupId>io.micrometer</groupId><artif…

Ubuntu 20.04.06 PCL C++学习记录(二十一)【切记使用rm * -rf前先确认是否是对应文件夹】

[TOC]PCL中点云分割模块的学习 学习背景 参考书籍&#xff1a;《点云库PCL从入门到精通》以及官方代码PCL官方代码链接,&#xff0c;PCL版本为1.10.0&#xff0c;CMake版本为3.16&#xff0c;测试点云下载地址 学习内容 根据欧几里得距离和需要保持的用户可自定义条件对点进…

spring02:DI(依赖注入)

spring02&#xff1a;DI&#xff08;依赖注入&#xff09; 文章目录 spring02&#xff1a;DI&#xff08;依赖注入&#xff09;前言&#xff1a;一、构造器注入二、set注入&#xff1a;1. Student类&#xff1a;2. Address类&#xff1a;3. beans.xml&#xff1a;4. MyTest&…

最新mysql8.3 保姆级 主从复制搭建教程

mysql 主从复制搭建 服务器配置表 机器ip操作系统主机192.168.31.25华为openEuler-22.03-LTS-SP3从机192.168.31.184华为openEuler-22.03-LTS-SP3从机192.168.31.228华为openEuler-22.03-LTS-SP3 1、在3台机器上安装独立的 mysql 1.1 创建myql文件夹用来存放mysql包 mkdir…

语音识别(录音与语音播报)

语音识别&#xff08;录音与语音播报&#xff09; 简介 语音识别人工智能技术的应用领域非常广泛&#xff0c;常见的应用系统有&#xff1a;语音输入系统&#xff0c;相对于键盘输入方法&#xff0c;它更符合人的日常习惯&#xff0c;也更自然、更高效&#xff1b;语音控制系…

【用户案例】太美医疗基于Apache DolphinScheduler的应用实践

大家好&#xff0c;我叫杨佳豪&#xff0c;来自于太美医疗。今天我为大家分享的是Apache DolphinScheduler在太美医疗的应用实践。今天的分享主要分为四个部分&#xff1a; 使用历程及选择理由稳定性的改造功能定制与自动化部署运维巡检与优化 使用历程及选择理由 公司介绍 …

【Node.js】短链接

原文链接&#xff1a;Nodejs 第六十二章&#xff08;短链接&#xff09; - 掘金 (juejin.cn) 短链接是一种缩短长网址的方法&#xff0c;将原始的长网址转换为更短的形式。短链接的主要用途之一是在社交媒体平台进行链接分享。由于这些平台对字符数量有限制&#xff0c;长网址可…

MySQL-多表查询:多表查询分类、SQL99语法实现多表查询、UNION的使用、7种SQL JOINS的实现、SQL99语法新特性、多表查询SQL练习

多表查询 1. 一个案例引发的多表连接1.1 案例说明1.2 笛卡尔积&#xff08;或交叉连接&#xff09;的理解1.3 案例分析与问题解决 2. 多表查询分类讲解分类1&#xff1a;等值连接 vs 非等值连接等值连接非等值连接 分类2&#xff1a;自连接 vs 非自连接分类3&#xff1a;内连接…

OSPF防环文档

OPSF在区域内会产生俩类LSA&#xff1a;Router LSA &#xff0c;Network LSA 路由器以自己为树根构建最短路径树 &#xff0c;这里的最短路径树按两步形 成&#xff0c;第一步&#xff0c;仅考虑路由器和传输网络之间的连接。通过 Dijkstra 算法&#xff0c;根据链路状态数据…

doss攻击为什么是无解的?

这个让Google、亚马逊等实力巨头公司也无法避免的攻击。可以这么说&#xff0c;是目前最强大、最难防御的攻击之一&#xff0c;属于世界级难题&#xff0c;并且没有解决办法。 Doss攻击的原理不复杂&#xff0c;就是利用大量肉鸡仿照真实用户行为&#xff0c;使目标服务器资源…

解析大语言模型训练三阶段

大语言模型的训练过程一般包括3个阶段&#xff1a;预训练&#xff08;Pre-training&#xff09;、SFT&#xff08;有监督的微调&#xff0c;Supervised-Finetuning&#xff09;以及RLHF&#xff08;基于人类反馈的强化学习&#xff0c;Reinforcement Learning from Human Feedb…

Mac的终端配置

Mac的终端配置 参考教程包管理工具 - Homebrew出现的问题用虚拟环境解决方案&#xff1a;直接将解释器的路径放过去错误方法&#xff1a;用find查找到虚拟环境安装的路径&#xff0c;其链接的是brew安装的python路径 编辑器没有报错&#xff0c;但是运行过程中仍然找不到pandas…

【动态规划-线性dp】【蓝桥杯备考训练】:乌龟棋、最长上升子序列、最长公共子序列、松散子序列、最大上升子序列和【已更新完成】

目录 1、乌龟棋 2、最长上升子序列 3、最长公共子序列 4、松散子序列 5、最大上升子序列和 1、乌龟棋 小明过生日的时候&#xff0c;爸爸送给他一副乌龟棋当作礼物。 乌龟棋的棋盘只有一行&#xff0c;该行有 N 个格子&#xff0c;每个格子上一个分数&#xff08;非负整…

【Springboot开发】后端代码基础框架

前言&#xff1a;主要介绍最基础的springboot开发架构 目录 1. overall2. 配置文件2.1 YAML2.2 properties2.3 配置文件加载顺序2.4 多配置文件 3. 代码包3.1 infrastructure3.1.1 persistence 3.2 application3.2.1 dto3.2.2 converter3.2.3 service 3.3 api3.3.1 vo3.3.2 req…

Django交易商场

Hello&#xff0c;我是小恒不会java 最近学习django&#xff0c;写了一个demo,学到了不少东西。 我在GitHub上开源了&#xff0c;提示‘自行查看代码&#xff0c;维护&#xff0c;运行’。 最近有事&#xff0c;先发布代码了&#xff0c;我就随缘维护更新吧 介绍&#xff1a; 定…

Harmony鸿蒙南向驱动开发-MIPI CSI

CSI&#xff08;Camera Serial Interface&#xff09;是由MIPI联盟下Camera工作组指定的接口标准。CSI-2是MIPI CSI第二版&#xff0c;主要由应用层、协议层、物理层组成&#xff0c;最大支持4通道数据传输、单线传输速度高达1Gb/s。 物理层支持HS&#xff08;High Speed&…

随机过程-BS定理

随机偏微分方程相比普通偏微分方程具有额外的随机项&#xff0c;反映了其描述的现象具有随机性质

华为 2024 届校园招聘-硬件通⽤/单板开发——第一套(部分题目分享,完整版带答案,共十套)

华为 2024 届校园招聘-硬件通⽤/单板开发——第一套 部分题目分享&#xff0c;完整版带答案(有答案和解析&#xff0c;答案非官方&#xff0c;未仔细校正&#xff0c;仅供参考&#xff09;&#xff08;共十套&#xff09;获取&#xff08;WX:didadidadidida313&#xff0c;加我…

贪心算法|860.柠檬水找零

力扣题目链接 class Solution { public:bool lemonadeChange(vector<int>& bills) {int five 0, ten 0, twenty 0;for (int bill : bills) {// 情况一if (bill 5) five;// 情况二if (bill 10) {if (five < 0) return false;ten;five--;}// 情况三if (bill …

基于ubuntu22.04系统安装nvidia A100驱动与NVLink启用

1、官方仓库 针对驱动包下载认准nvidia官网 dpkg -i nvidia-driver-local-repo-ubuntu2204-550.54.15_1.0-1_amd64.deb apt update apt search nvidia-driver-5502、安装 根据步骤1apt search nvidia-driver-550查出版本&#xff1a;此驱动包封在nvidia-driver-local-repo-ub…