我也是个老古董了,虽然知道有Nucleo这个东西,像Arduino,以前有个民间的Maple,也有51 Duino.但是这个还是没试过.Blink的语法跟Arduino不太一样,如例子:
#include "mbed.h"
DigitalOut myled(LED1);
int main() {
while(1) {
myled = 1; // LED is ON
wait(0.2); // 200 ms
myled = 0; // LED is OFF
wait(1.0); // 1 sec
}
}
编译后生成一个东西,要丢到U盘,类似OpenSDA.
丢进去,就等于编程这货了.
还支持右键,然后导出到Keil.
导出后,发现有库耶.
然后发现打开编译就报翔了.后来发现原来是Keil V5工程不行,打开时候可不要选了Keil V5 Update.因为我是Keil V5,无解了,不升级无法Debug工程.改改工程,加:
#include "mbed.h"
Ticker toggle_led_ticker;
DigitalOut led1(LED1);
void toggle_led() {
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);
while (true) {
// Do other things...
}
}
我们打开一个串口例子:
#include "mbed.h"
Serial pc(SERIAL_TX, SERIAL_RX);
DigitalOut myled(LED1);
int main() {
int i = 1;
pc.printf("Hello World !
");
while(1) {
wait(1);
pc.printf("This program runs since %d seconds.
", i++);
myled = !myled;
}
}
打开左侧,有串口库,双击进入,看到库介绍.
此处设置波特率:
于是我们程序就可以这么做了:
#include "mbed.h"
Serial pc(SERIAL_TX, SERIAL_RX);
DigitalOut myled(LED1);
int main()
{
int i = 1;
pc.baud(115200);
pc.printf("Hello World !
");
while(1) {
wait(1);
pc.printf("This program runs since %d seconds.", i++);
myled = !myled;
}
}
这时候,就是115200bps了.
话说该赞一个,这个Nucleo的仿真器,改用F103RBT6做[不是C8T6],多了串口仿真和U盘下载功能.