TEST serial port
Dependencies: mbed
main.cpp@0:ff659d8bffe7, 2015-01-14 (annotated)
- Committer:
- BrunoV
- Date:
- Wed Jan 14 18:02:31 2015 +0000
- Revision:
- 0:ff659d8bffe7
TEST SERIAL PORT (SUCCESS)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
BrunoV | 0:ff659d8bffe7 | 1 | #include "mbed.h" |
BrunoV | 0:ff659d8bffe7 | 2 | |
BrunoV | 0:ff659d8bffe7 | 3 | //------------------------------------ |
BrunoV | 0:ff659d8bffe7 | 4 | // Hyperterminal configuration |
BrunoV | 0:ff659d8bffe7 | 5 | // 9600 bauds, 8-bit data, no parity |
BrunoV | 0:ff659d8bffe7 | 6 | //------------------------------------ |
BrunoV | 0:ff659d8bffe7 | 7 | |
BrunoV | 0:ff659d8bffe7 | 8 | Serial pc(USBTX, USBRX); |
BrunoV | 0:ff659d8bffe7 | 9 | |
BrunoV | 0:ff659d8bffe7 | 10 | DigitalOut myled(LED1); |
BrunoV | 0:ff659d8bffe7 | 11 | DigitalOut LedExterne(D7); |
BrunoV | 0:ff659d8bffe7 | 12 | |
BrunoV | 0:ff659d8bffe7 | 13 | int main() |
BrunoV | 0:ff659d8bffe7 | 14 | { |
BrunoV | 0:ff659d8bffe7 | 15 | int i = 1; |
BrunoV | 0:ff659d8bffe7 | 16 | pc.printf("Hello World !\n"); |
BrunoV | 0:ff659d8bffe7 | 17 | pc.baud(9600); |
BrunoV | 0:ff659d8bffe7 | 18 | pc.format(8, SerialBase::None, 1); |
BrunoV | 0:ff659d8bffe7 | 19 | |
BrunoV | 0:ff659d8bffe7 | 20 | while(1) { |
BrunoV | 0:ff659d8bffe7 | 21 | wait(1); |
BrunoV | 0:ff659d8bffe7 | 22 | pc.printf("This program runs since %d seconds.\n", i++); |
BrunoV | 0:ff659d8bffe7 | 23 | pc.printf("\n"); |
BrunoV | 0:ff659d8bffe7 | 24 | myled = !myled; |
BrunoV | 0:ff659d8bffe7 | 25 | LedExterne =! LedExterne; |
BrunoV | 0:ff659d8bffe7 | 26 | char c = pc.getc(); |
BrunoV | 0:ff659d8bffe7 | 27 | if ( c=='a') |
BrunoV | 0:ff659d8bffe7 | 28 | { |
BrunoV | 0:ff659d8bffe7 | 29 | LedExterne =0; |
BrunoV | 0:ff659d8bffe7 | 30 | } |
BrunoV | 0:ff659d8bffe7 | 31 | if ( c=='b') |
BrunoV | 0:ff659d8bffe7 | 32 | { |
BrunoV | 0:ff659d8bffe7 | 33 | LedExterne = 1 ; |
BrunoV | 0:ff659d8bffe7 | 34 | } |
BrunoV | 0:ff659d8bffe7 | 35 | |
BrunoV | 0:ff659d8bffe7 | 36 | } |
BrunoV | 0:ff659d8bffe7 | 37 | } |