*Desvription: use the uart to control the led1 *'1' :turn on the light; *'0':turn off the light;
Dependencies: mbed
Fork of Serial_HelloWorld_Mbed by
Diff: main.cpp
- Revision:
- 2:1e1b79549cfe
- Parent:
- 1:560b8ced44df
--- 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