当前位置:网站首页>蓝桥杯嵌入式学习总结(新版)
蓝桥杯嵌入式学习总结(新版)
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个脉冲
边栏推荐
- Database persistence
- [image enhancement] image defogging based on artificial multiple exposure fusion amef with matlab code
- Service interface test guide
- 【元胞自动机】基于元胞自动机实现高速公路收费站交通流问题附matlab代码
- Tetra - (4-pyridyl) porphyrin tpyp and metal complexes zntpyp/fetpyp/mntpyp/cutpyp/nitpyp/cotpyp/ptpyp/pdtpyp/cdtpyp (supplied by Qiyue porphyrin)
- When asked during the interview, can redis master-slave copy not answer? These 13 pictures let you understand thoroughly
- 5,10,15,20-tetraphenylporphyrin (TPP) and metal complexes fetpp/mntpp/cutpp/zntpp/nitpp/cotpp/pttpp/pdtpp/cdtpp supplied by Qiyue
- Analysis report on market demand and investment competitiveness of China's cyclohexanone industry (2022 Edition)
- Crosslinked metalloporphyrin based polyimide ppbpi-h) PPBP Mn; PBP-Fe; PPBPI-Fe-CR; Ppbpi Mn CR product - supplied by Qiyue
- Introduction to mapping in ES
猜你喜欢
Crosslinked porphyrin based polyimide ppbpi-2, ppbpi-1-cr and ppbpi-2-cr; Porous porphyrin based hyperbranched polyimide (ppbpi-1, ppbpi-2) supplied by Qiyue
PyTorch搭建CNN-LSTM混合模型实现多变量多步长时间序列预测(负荷预测)
Meso tetra (4-bromophenyl) porphyrin (tbpp); 5,10,15,20-tetra (4-methoxy-3-sulfonylphenyl) porphyrin [t (4-mop) ps4] supplied by Qiyue
Installation homebrew error summary
缓存使用
Shell programming - user information management
Rust中的过程宏
unity之EasyAR使用
C#实现给DevExpress中GridView表格指定列添加进度条显示效果——代码实现方式
Quickly find five channels for high-quality objects, quickly collect and avoid detours
随机推荐
MySQL'replace into'has a self incrementing ID of the pit. There is a problem with the backup opportunity
Tetradecanoxy tetraphenylporphyrin methacrylate mm-tpp-14c; Cetanoxy tetraphenyl porphyrin methacrylate mm-tpp-16c; Purple solid; Qiyue supply
专业课-代码题记录
Analyze 5 indicators of NFT project
web入门之 Promise API
Es string type (text vs keyword) selection
【元胞自动机】基于元胞自动机实现高速公路收费站交通流问题附matlab代码
MySQL basic usage 01
Parameter index out of range (0 < 1) (1> number of parameters, which is 0
Professional course - Code question record
Liquid crystal texture diagram of purple solid mm-tpp-10c methacrylic acid decanoxy tetraphenyl porphyrin and mm-tpp-12c methacrylic acid dodecanoxy tetraphenyl porphyrin - Qi Yue display
$a && $b = $c what???
5,10,15,20-tetra (4-methoxycarbonylphenyl) porphyrin tcmpp purple crystal; Meso-5,10,15,20-tetra (4-methoxyphenyl) porphyrin tmopp|zn[t (4-mop) p] and co[t (4-mop) p] complexes
【图像检测】基于Itti模型实现图像显著性检测附matlab代码
$a && $b = $c what???
shell 输入验证仅限字母数字
ES字符串类型(Text vs keyword)的选择
When asked during the interview, can redis master-slave copy not answer? These 13 pictures let you understand thoroughly
Development trends and prospects of acrylamide crystallization market in the world and China 2022-2027
Numpy learning challenge level 1 - Download and installation of numpy