当前位置:网站首页>蓝桥杯嵌入式学习总结(新版)
蓝桥杯嵌入式学习总结(新版)
2022-06-26 07:11:00 【Yinzz2】
1.LED
GPIO_output level 设置为 high
void led_show(uint16_t led,uint8_t state)
{
if(state == 1)
{
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_All,GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOC,led<<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
{
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_All,GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOC,led<<8,GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOD,GPIO_PIN_2,GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOD,GPIO_PIN_2,GPIO_PIN_RESET);
}
}2.KEY
GPIO输入设置为上拉,三行式按键消抖具体上其他博客了解
_Bool key_flag=0;
unsigned char Trg;
unsigned char Cont;
void key_read(void)
{
unsigned char ReadData = (KEYPORT)^0xff;
Trg = ReadData & ( ReadData ^ Cont );
Cont = ReadData;
}
//具体用法搜索三行式消抖
//inter.h
#ifndef _INTER_H_
#define _INTER_H_
#include "main.h"
#define KB1 HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_0)
#define KB2 HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_1)
#define KB3 HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_2)
#define KB4 HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0)
#define KEYPORT KB1 | (KB2 << 1) | (KB3 << 2) | (KB4 << 3) | 0xf0
void key_read(void);
extern unsigned char Trg;
extern unsigned char Cont;
extern _Bool key_flag;
#endif
//在主函数上记得加上
HAL_TIM_Base_Start_IT(&htim3);
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef * htim)
{
static uint16_t key_count =0;
if(htim->Instance == TIM3)
{
key_count++;
if(key_count==10)
{
key_count=0;
key_flag=1;
}
}
}
//定时器1ms触发一次,key_count为10时,相当于0.1s令key_flag置一
3.PWM输出
主要是在Cubemx开启选择 PWM Generation CH1 自己按照需求设置Period,Prescaler和Pulse
//主函数上加入 HAL_TIM_PWM_Start(&htim16,TIM_CHANNEL_1);
//设置占空比 __HAL_TIM_SetCompare(&htim16,TIM_CHANNEL_1,pa6duty);
//相当于一个周期内设置了pa6duty个脉冲数
//设置频率 __HAL_TIM_SetAutoreload(&htim16,2000-1);
//相当于设置一个周期内有2000个脉冲边栏推荐
- 一文分析EventBus-事件总线的使用方法和实现原理
- The difference between insert ignore and insert into
- MySQL
- ES cluster_block_exception read_only_allow_delete问题
- China's Ni MH battery industry development overview analysis and investment trend forecast report 2022 Edition
- Thymeleaf中使用二维数组[[]]报错:Could not parse as expression
- Research Report on China's surfactant market demand and future investment opportunities 2022
- 一项听起来大胆,并且非常牛逼的操作——复刻一个 Netflix
- 网络io,磁盘io
- China polyimide film market demand and future investment risk outlook report 2022-2027
猜你喜欢

Procedure macros in rust

Tetra - (4-pyridyl) porphyrin tpyp and metal complexes zntpyp/fetpyp/mntpyp/cutpyp/nitpyp/cotpyp/ptpyp/pdtpyp/cdtpyp (supplied by Qiyue porphyrin)
![[feature extraction] feature selection of target recognition information based on sparse PCA with Matlab source code](/img/79/053e185f96aab293fde54578c75276.png)
[feature extraction] feature selection of target recognition information based on sparse PCA with Matlab source code

【特征提取】基于稀疏PCA实现目标识别信息特征选择附matlab源码

. Net 20th anniversary! Microsoft sends a document to celebrate
![[cellular automata] Based on cellular automata, realize the traffic flow problem of expressway toll station, with matlab code](/img/6c/488be82a720635333eea90adcc388f.png)
[cellular automata] Based on cellular automata, realize the traffic flow problem of expressway toll station, with matlab code

ZRaQnHYDAe

Calculate division in Oracle - solve the error report when the divisor is zero

Professional course - Code question record

【图像融合】基于耦合特征学习的多模式医学图像融合附matlab代码
随机推荐
China's Ni MH battery industry development overview analysis and investment trend forecast report 2022 Edition
How to publish function computing (FC) through cloud effect
Cache usage
ES cluster_block_exception read_only_allow_delete问题
Operation mode and investment planning report of China's financial warehousing industry during the "14th five year plan" period 2022-2027
【图像分割】基于最大主曲率实现视网膜眼底图像中的血管提取附matlab代码
【元胞自动机】基于元胞自动机实现高速公路收费站交通流问题附matlab代码
es 中 mapping 简介
How to open an account in flush? Is it safe to open an account online?
Cocoscreator plays spine animation
[image detection] image target size measurement system based on morphology with matlab code
异地北京办理居住证详细材料
Analyze 5 indicators of NFT project
Crosslinked metalloporphyrin based polyimide ppbpi-h) PPBP Mn; PBP-Fe; PPBPI-Fe-CR; Ppbpi Mn CR product - supplied by Qiyue
China imported wine circulation and investment market survey and Future Development Trend Outlook report 2022-2027
i3wm 获取window class
3D porphyrin MOF (mof-p5) / 3D porphyrin MOF (mof-p4) / 2D cobalt porphyrin MOF (ppf-1-co) / 2D porphyrin COF (POR COF) / supplied by Qiyue
同花顺究竟如何开户,网上开户是否安全么?
Development trends and prospects of acrylamide crystallization market in the world and China 2022-2027
MATLAB线性规划模型学习笔记