*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 mbed official

Committer:
shiyilei
Date:
Wed Oct 22 07:20:00 2014 +0000
Revision:
2:1e1b79549cfe
Parent:
1:560b8ced44df
*Desvription: use the uart to control the led1; *'1' :turn on the light;; *'0':turn off the light;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shiyilei 2:1e1b79549cfe 1 /**********************************************
shiyilei 2:1e1b79549cfe 2 *file: uart Control the light
shiyilei 2:1e1b79549cfe 3 *Creator: JacobShi
shiyilei 2:1e1b79549cfe 4 *Time:2014/10/22
shiyilei 2:1e1b79549cfe 5 *Desvription: use the uart to control the led1
shiyilei 2:1e1b79549cfe 6 *'1' :turn on the light;
shiyilei 2:1e1b79549cfe 7 *'0':turn off the light;
shiyilei 2:1e1b79549cfe 8 *******************************************/
mbed_official 0:879aa9d0247b 9 #include "mbed.h"
shiyilei 2:1e1b79549cfe 10 Serial uart0(USBTX,USBRX);
shiyilei 2:1e1b79549cfe 11 DigitalOut myled1(LED1);
shiyilei 2:1e1b79549cfe 12 char databuffer[3];
shiyilei 2:1e1b79549cfe 13 char dataready;
shiyilei 2:1e1b79549cfe 14 void uart_interrupt_process();
shiyilei 2:1e1b79549cfe 15 Ticker flipper;
shiyilei 2:1e1b79549cfe 16 int main(void)
shiyilei 2:1e1b79549cfe 17 {
shiyilei 2:1e1b79549cfe 18
shiyilei 2:1e1b79549cfe 19 dataready=0;
shiyilei 2:1e1b79549cfe 20 myled1=0;
shiyilei 2:1e1b79549cfe 21 uart0.baud(115200);
shiyilei 2:1e1b79549cfe 22 uart0.format(8,SerialBase::None,1);
shiyilei 2:1e1b79549cfe 23 uart0.printf("Hello World");
shiyilei 2:1e1b79549cfe 24 uart0.attach(&uart_interrupt_process,SerialBase::RxIrq );
shiyilei 2:1e1b79549cfe 25 while(1)
shiyilei 2:1e1b79549cfe 26 {
shiyilei 2:1e1b79549cfe 27 if(dataready)
shiyilei 2:1e1b79549cfe 28 {
shiyilei 2:1e1b79549cfe 29 dataready=0;
shiyilei 2:1e1b79549cfe 30 switch(databuffer[0])
shiyilei 2:1e1b79549cfe 31 {
shiyilei 2:1e1b79549cfe 32 case 0x31: myled1=0; break;
shiyilei 2:1e1b79549cfe 33 case 0x32: myled1=1; break;
shiyilei 2:1e1b79549cfe 34 default: myled1=0; break;
shiyilei 2:1e1b79549cfe 35 }
shiyilei 2:1e1b79549cfe 36 }
mbed_official 0:879aa9d0247b 37 }
shiyilei 2:1e1b79549cfe 38
shiyilei 2:1e1b79549cfe 39 }
shiyilei 2:1e1b79549cfe 40
shiyilei 2:1e1b79549cfe 41 void uart_interrupt_process()
shiyilei 2:1e1b79549cfe 42 {
shiyilei 2:1e1b79549cfe 43 databuffer[0]=uart0.getc();
shiyilei 2:1e1b79549cfe 44 dataready=1;
mbed_official 0:879aa9d0247b 45 }