短文1Today I need to prepare a new firmware routine for an STM32F103 microcontroller. The goal is to trigger an LED when a button is pressed. However, we must not use simple polling because the CPU has many other tasks to handle. We will use an external interrupt line instead. First, I enable the clock for GPIO Port A and Port C through the RCC_APB2ENR register. Then, I configure PA0 as a floating input. The button is connected to this pin with an external pull-up resistor. Therefore, when the button is pressed, the pin level goes from high to low. We want to capture this falling edge. In the NVIC (Nested Vectored Interrupt Controller), we must enable the corresponding interrupt channel. The EXTI (External Interrupt/Event Controller) controller allows us to select the trigger condition. We set the falling edge sensitivity in the EXTI_FTSR register. We also unmask the specific line by writing to EXTI_IMR. Inside the interrupt service routine (ISR), we check the pending bit in the EXTI_PR register. If it is set, we know that the EXTI0 event has occurred. We then toggle the LED connected to PC13 by writing to the GPIOC_ODR register. After servicing the hardware, it is essential to clear the pending bit. Otherwise, the CPU will immediately re-enter the handler, causing an infinite loop. While the main program executes a delay loop or sleep mode (WFI instruction), the interrupt can wake up the core. This approach is efficient and saves power. The current consumption is significantly reduced compared to continuous polling. Finally, I compile the code and flash the device. The LED responds instantly to the button action.(嵌入式贴合词汇)routine — a new firmwareroutinetrigger — totriggeran LEDhandle — tasks tohandleexternal — anexternalinterruptline — interruptlineregister — RCC_APB2ENRregisterlevel — pinlevelgoes from high to lowcapture — tocapturethis falling edgefalling — fallingedge sensitivityedge — fallingedgeenable — enablethe corresponding interruptchannel — interruptchannelcontroller — EXTIcontrollerunmask — unmaskthe specific linespecific — thespecificlineinterrupt — Inside theinterruptservice routineservice — interruptserviceroutinepending — check thependingbitbit — pendingbitevent — EXTI0eventhas occurredtoggle — togglethe LEDservicing — Afterservicingthe hardwarehardware — servicing thehardwareclear — clearthe pending bithandler — re-enter thehandlerinfinite — aninfinitelooploop — loopexecutes — programexecutesdelay — delayloopsleep — sleepmodemode — sleepmodewake — wakeup the corecore — wake up thecorecompile — Icompilethe codeflash — flashthe device(高频通用词汇)prepare — I need toprepareHowever — However, we must notinstead — insteadfloating — as afloatinginputconnected — button isconnectedTherefore — Therefore, when the button is pressedhigh — goes fromhighto lowcorresponding — thecorrespondinginterruptselect — allows us toselectcondition — triggerconditionsensitivity — edgesensitivityoccurred — hasoccurredessential — it isessentialOtherwise — Otherwise, the CPUefficient — isefficientpower — savespowercurrent — Thecurrentconsumptionsignificantly — significantlyreducedcompared — comparedto continuouscontinuous — compared tocontinuousinstantly — respondsinstantlyaction — buttonaction