STM32单片机LED灯按键中断显示 proteus仿真
上周做的用LED灯按键中断显示
从此个实验中可以学习中断的使用,用的是标准库函数
粗略的显示了一下,有些不足,希望大家能够给予指导并相互学习。
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
- //#include "main.h"
- #include "stm32f10x.h"
- void LED_Config(void);
- void KEY_Config(void);
- void NVIC_Configuration(void);
- void EXTI9_5_IRQHandler(void);
- int main(void)
- {
- NVIC_Configuration();
- LED_Config();
- KEY_Config();
- GPIO_ResetBits(GPIOB,GPIO_Pin_8);
- while(1)
- {
-
- }
- }
- void LED_Config(void)
- {
-
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- }
- void KEY_Config(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- EXTI_InitTypeDef EXTI_InitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
-
- GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource6);
- EXTI_InitStructure.EXTI_Line = EXTI_Line6;
- EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
- EXTI_InitStructure.EXTI_LineCmd = ENABLE;
- EXTI_Init(&EXTI_InitStructure);
- }
- void NVIC_Configuration(void)
- {
-
- NVIC_InitTypeDef NVIC_InitStructure;
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
- NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- }
- void EXTI9_5_IRQHandler(void)
- {
- if(EXTI_GetITStatus(EXTI_Line6) != RESET)
- {
- GPIO_WriteBit(GPIOB, GPIO_Pin_8,
- (BitAction)((1-GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_8))));
- EXTI_ClearITPendingBit(EXTI_Line6);
- }
- }
复制代码
所有资料51hei提供下载:
按键中断LED.7z
(286.54 KB, 下载次数: 145)
|