当前位置:网站首页>Proteus仿真stm32f103R6Tx——外部中断控制LED亮灭(Cube MX+Keil5+proteus)
Proteus仿真stm32f103R6Tx——外部中断控制LED亮灭(Cube MX+Keil5+proteus)
2022-06-10 04:36:00 【Drawing Ting】
前言
为了熟悉使用proteus相关操作并结合HAL库进行代码编写,本文介绍通过外部中断控制LED亮灭,以及自己在探索阶段出现的一些问题与相关解决资料。部分基础操作与上一篇Proteus基础操作介绍基础部分介绍相同,本文将略去。如有表述不妥之处,还望指正。
Cube MX配置
SYS、RCC、Clock Configuration部分配置不再赘述
GPIO
PA1、PA2设置中断EXIT,下降沿Falling Edge,上拉电阻(Pull up)
PA4、PA5连接两个LED
NVIC
开启中断,如果不需要用到HAL-Delay等优先级会发生冲突的函数,则不需要设置此处优先级。
Keil5 代码编写
main.h
宏定义待设置端口位
/* Private defines -----------------------------------------------------------*/
/* USER CODE BEGIN Private defines */
#define key1_GPIO_Pin GPIO_PIN_1
#define key2_GPIO_Pin GPIO_PIN_2
/* USER CODE END Private defines */
gpio.c
/* USER CODE BEGIN 2 */
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
switch(GPIO_Pin)
{
case GPIO_PIN_1://进入PA1按键触发的中断
HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_4);break;//翻转PA4电平,LED由亮变灭或反之
case GPIO_PIN_2://进入PA2按键触发的中断
HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_5);break;//翻转PA5电平,LED由亮变灭或反之
default:break;
}
}
/* USER CODE END 2 */
proteus仿真
原理图如下
按下第一个开关,D1灭
再按一次:重新D1亮起。
另一个按键也能实现同样的功能。
其他可能的疑问
边栏推荐
- Network principle TCP
- 信息学奥赛一本通 1287:最低通行费 | OpenJudge NOI 2.6 7614:最低通行费
- Mindspire deletion and torch nn. Maxpool3d and torch nn. Avgpool3d benchmarking operator
- 5 minutes to learn how to set up local pypi source
- Gevent | use it asynchronously!
- Eight part essay ceiling! (PDF HD download)
- Email: analysis of wrong arrangement
- Crack the five myths of programmers, and new programmer 004 is officially launched!
- Installing mindinsight in the mindspire official website container does not work locally
- 如何用天气预警API接口进行快速开发
猜你喜欢
![[in depth learning] Introduction to pytorch to project practice (11): convolution layer](/img/19/18d6e94a1e0fa4a75b66cf8cd99595.png)
[in depth learning] Introduction to pytorch to project practice (11): convolution layer

Jenkinsclient | easy to use Jenkins client

超好用的 Chrome 插件!
Webcodecs解析GIF图

分布式数据对象:超级终端的'全局变量'

Celery | 任务队列神器

EasyRecovery数据恢复软件100%恢复的成功率

City / school / major, which is the most important when choosing a university| Daily anecdotes

这些编程语言老了,差不多死透了,年轻人不能碰
Webcodecs parsing GIF graph
随机推荐
信息学奥赛一本通 1279:【例9.23】橱窗布置(flower) | 洛谷 P1854 花店橱窗布置
Pysimplegui classic practice: how to read this Chinese character?
测试工程师提高质量的OKR该如何写?
2022.5.27-----leetcode. Interview 17.11
Acl2022 | the introduction of comparative learning to add negative samples to the generation process enables the model to effectively learn knowledge at different levels
S series · add data to the text file without adding duplicate values
在MindSpore官网容器内安装MindInsight不能在本地正常工作
信息学奥赛一本通 1287:最低通行费 | OpenJudge NOI 2.6 7614:最低通行费
S系列·在已作出的matplotlib图中新增图例
JDBC 入門示例
【深度学习】《PyTorch入门到项目实战》(十一):卷积层
2022.5.24-----leetcode. nine hundred and sixty-five
25. BOM事件
MindSpore【初学入门】教程在线运行时报错
[joint search set] sympodial plants (number of connected blocks)
Pampy | 超强的模式匹配工具
91. fence
497. 非重叠矩形中的随机点
Byte order, object class
Informatics Olympiad all in one 1287: minimum toll | openjudge noi 2.6 7614: minimum toll