mbed STM32 定时器中断示例
你可以使用 mbed Ticker API 为你的 mbed 应用程序添加定时器中断。此示例将使用基于 Ticker 的定时器中断每秒切换 LED 一次,例如在 STM32F429I-DISCO 板上:
mbed-timer.cpp
#include <mbed.h>
DigitalOut led1(LED1);
Ticker ticker;
/**
* 此函数将每秒运行一次
*/
void timerTick() {
// 切换 LED
led1 = !led1;
}
int main() {
ticker.attach(timerTick, 1.0 /* seconds */);
// 你在主循环中做什么不重要
while(1) {
}
}If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow