在线时间216 小时
UID2029919
ST金币593
蝴蝶豆0
注册时间2013-7-31
该用户从未签到
金牌会员
- 最后登录
- 2020-7-18
|
发表于 2014-12-16 21:22:54
|
显示全部楼层
#include "mbed.h"
DigitalOut led1(LED1);
DigitalOut led2(LED2);
Serial pc(USBTX, USBRX);
void callback() {
// Note: you need to actually read from the serial to clear the RX interrupt
printf("%c\n", pc.getc());
led2 = !led2;
}
int main() {
pc.attach(&callback);
while (1) {
led1 = !led1;
wait(0.5);
}
}
看这个例子,这是一个串口中断的,主函数使能中断 pc.attach(&callback);
callback就是中断服务函数,这是直接调用mbed API操作。 pc.getc()可以直接截取接收到的内容十分方便,建议去看看mbed 的库函数! |
|