#include"stm32f10x.h"
void LED_GPIO_Config()
{
/*Define a GPIO_InitTypeDef type structure*/
GPIO_InitTypeDef GPIO_InitStructure;
/*Turn on the peripheral clock of GPIOB*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
/*Select the GPIOB pin to control*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
/*Set pin mode to general push-pull output*/
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
/*Set the pin rate to 50MHz*/
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
/*Call library function to initialize GPIOB*/
GPIO_Init(GPIOB, &GPIO_InitStructure);
/*Turn off the LED light*/
GPIO_SetBits(GPIOB, GPIO_Pin_5);
}
void EXTI_PC5_Config()
{
static void NVIC_Configuration();
/*Define a GPIO_InitTypeDef type structure*/
GPIO_InitTypeDef GPIO_InitStructure;
/*Define a structure of type EXTI_InitTypeDef*/
EXTI_InitTypeDef EXTI_InitStructure;
/*Turn on GPIOC peripheral clock and AFIO clock*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO, ENABLE);
/*Configure NVIC(PC5)*/
NVIC_Configuration();
/*EXTI GPIO(PC5) line configuration*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; /*Set pull-up input*/
GPIO_Init(GPIOC, &GPIO_InitStructure); /*Call library function to initialize GPIOC*/
/*EXTI line (PE5) mode configuration*/
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource5);
EXTI_InitStructure.EXTI_Line = EXTI_Line5;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; /*Falling edge interrupt*/
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
}
static void NVIC_Configuration()
{
/*Define a structure of type NVIC_InitTypeDef*/
NVIC_InitTypeDef NVIC_InitStructure;
/*Configure one bit for preemption priority*/
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
/*Configure P[A|B|C|D|E]5 as interrupt source*/
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 Delay(uint32_t uCount)
{
for(;uCount>0;uCount--);
}
void EXTI9_5_IRQHandler()
{
if(EXTI_GetITStatus(EXTI_Line5) != RESET) /*Ensure whether EXTI Line interrupt has occurred*/
{
/*Debounce*/
Delay(1000);
/*LED inversion*/
GPIO_WriteBit(GPIOB, GPIO_Pin_5, (BitAction)((~GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_5))));
/* Clear interrupt flag */
EXTI_ClearITPendingBit(EXTI_Line5);
}
}
int main(void)
{
/* Initialize LED */
LED_GPIO_Config();
/*EXTI line configuration*/
EXTI_PC5_Config();
GPIO_SetBits(GPIOB, GPIO_Pin_5);/*置高*/
while(1);
}
Previous article:STM32 interrupt mode to detect key presses
Next article:STM32_Button control LED polling
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- Why can't I find the management option in the Download Center?
- How to calculate the saturation of an inductor with a magnetic core? Is there a calculation formula for reference?
- What is the difference between the PLL input clock (1) the clock generated by the XTH crystal oscillator and (2) the clock input from the XTH pin PD00?
- Summary: GigaDevice GD32F350 Innovation Design Competition Participants' Shared Content
- Good stuff for beginners - How to find MSP430 program examples on TI's official website
- MicroPython's GNSS parser micropyGPS
- Please explain the pulse signal code at the bottom that generates a clock cycle every 0.5s
- Project file production and burning
- 【Iprober 520 current probe】Closed magnetic circuit measurement
- [GD32L233C] + 7. Using ds18b20 temperature sensor under RTthread