![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
中断的使用
Revision 0:342ef23c88ad, committed 2018-04-11
- Comitter:
- heroistired
- Date:
- Wed Apr 11 07:06:27 2018 +0000
- Commit message:
- ?????
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Apr 11 07:06:27 2018 +0000 @@ -0,0 +1,19 @@ +#include "mbed.h" + +//演示定时器中断如何使用 + +Ticker toggle_led_ticker; //声明一个 Ticker 对象 + +DigitalOut led1(LED1); + +void toggle_led() { //中断子程序,在平衡车和无人机的项目中,控制算法就写在中断子程序中:获取陀螺仪数据,根据陀螺仪数据通过PID算法得到电机的控制量(占空比和方向),在输出到单片机管脚 + led1 = !led1; +} + +int main() { + // Init the ticker with the address of the function (toggle_led) to be attached and the interval (100 ms) + toggle_led_ticker.attach(&toggle_led, 0.1); //指定Ticker 对象的回调函数也就是中断子程序以及 中断的时间间隔即每隔多久执行一次,一般0.02或0.01即可 + while (true) { + // Do other things... + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Apr 11 07:06:27 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/994bdf8177cb \ No newline at end of file