使用stm32cbeMX配置STM32F103ZE详细步骤,按键KEY1按下,4个LED灯依次点亮;按键KEY2按下,4个LED灯不断闪烁。LED灯分别连接到PA0~PA3,将KEY1连接到PB0引脚,将KEY2连接到PB1引脚。
时间: 2024-03-16 16:44:40 浏览: 55
好的,我会为您提供配置STM32F103ZE的详细步骤!
1. 打开STM32CubeMX软件,新建一个工程,选择STM32F103ZE型号,点击“Start Project”按钮。
2. 在“Pinout & Configuration”选项卡中,将PA0~PA3的模式设置为GPIO输出,PB0和PB1的模式设置为GPIO输入。
3. 在“Configuration”选项卡中,将System Core Clock设置为72MHz,使其与STM32F103ZE芯片的主频相匹配。
4. 在“NVIC Settings”选项卡中,开启EXTI0和EXTI1的中断。
5. 在“Project Manager”选项卡中,生成代码并打开工程。
6. 在工程中添加以下代码:
```
#include "stm32f10x.h"
void EXTI0_IRQHandler(void)
{
if (EXTI_GetITStatus(EXTI_Line0) != RESET) {
GPIO_SetBits(GPIOA, GPIO_Pin_0);
for (int i = 1; i <= 3; i++) {
GPIO_SetBits(GPIOA, GPIO_Pin_i);
Delay(500);
GPIO_ResetBits(GPIOA, GPIO_Pin_i);
}
EXTI_ClearITPendingBit(EXTI_Line0);
}
}
void EXTI1_IRQHandler(void)
{
if (EXTI_GetITStatus(EXTI_Line1) != RESET) {
while(1) {
GPIO_SetBits(GPIOA, GPIO_Pin_All);
Delay(500);
GPIO_ResetBits(GPIOA, GPIO_Pin_All);
Delay(500);
}
EXTI_ClearITPendingBit(EXTI_Line1);
}
}
void Delay(uint32_t nCount)
{
for (uint32_t i = 0; i < nCount; i++);
}
int main(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
EXTI_InitStructure.EXTI_Line = EXTI_Line0;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
EXTI_InitStructure.EXTI_Line = EXTI_Line1;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
while (1) {
}
}
```
7. 编译并下载程序到STM32F103ZE芯片中。
8. 将KEY1连接到PB0引脚,将KEY2连接到PB1引脚,将LED灯连接到PA0~PA3引脚。
9. 按下KEY1,4个LED灯依次点亮;按下KEY2,4个LED灯不断闪烁。
希望这个步骤能够帮助您完成STM32F103ZE的配置,如果您还有其他问题,欢迎您继续提问!
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)