Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of Serial_HelloWorld_Mbed by
Revision 2:1e1b79549cfe, committed 2014-10-22
- Comitter:
- shiyilei
- Date:
- Wed Oct 22 07:20:00 2014 +0000
- Parent:
- 1:560b8ced44df
- Commit message:
- *Desvription: use the uart to control the led1; *'1' :turn on the light;; *'0':turn off the light;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 560b8ced44df -r 1e1b79549cfe main.cpp --- a/main.cpp Sun Sep 21 05:44:05 2014 +0000 +++ b/main.cpp Wed Oct 22 07:20:00 2014 +0000 @@ -1,10 +1,45 @@ +/********************************************** +*file: uart Control the light +*Creator: JacobShi +*Time:2014/10/22 +*Desvription: use the uart to control the led1 +*'1' :turn on the light; +*'0':turn off the light; + *******************************************/ #include "mbed.h" - -Serial pc(USBTX, USBRX); // tx, rx - -int main() { - pc.printf("Hello World!\n\r"); - while(1) { - pc.putc(pc.getc() + 1); // echo input back to terminal +Serial uart0(USBTX,USBRX); +DigitalOut myled1(LED1); +char databuffer[3]; +char dataready; +void uart_interrupt_process(); +Ticker flipper; +int main(void) +{ + + dataready=0; + myled1=0; + uart0.baud(115200); + uart0.format(8,SerialBase::None,1); + uart0.printf("Hello World"); + uart0.attach(&uart_interrupt_process,SerialBase::RxIrq ); + while(1) + { + if(dataready) + { + dataready=0; + switch(databuffer[0]) + { + case 0x31: myled1=0; break; + case 0x32: myled1=1; break; + default: myled1=0; break; + } + } } + +} + +void uart_interrupt_process() +{ + databuffer[0]=uart0.getc(); + dataready=1; } \ No newline at end of file