Serial Communication
Dependencies: mbed
Fork of Nucleo_serial_menu by
main.cpp@9:6992eccf476e, 2017-10-20 (annotated)
- Committer:
- soulx
- Date:
- Fri Oct 20 03:12:39 2017 +0000
- Revision:
- 9:6992eccf476e
- Parent:
- 4:fde2463b2846
- Child:
- 10:af00e881b81e
delete case 0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
soulx | 0:f4e546303b4e | 1 | #include "mbed.h" |
soulx | 0:f4e546303b4e | 2 | |
soulx | 0:f4e546303b4e | 3 | //------------------------------------ |
soulx | 0:f4e546303b4e | 4 | // Hyperterminal configuration |
soulx | 0:f4e546303b4e | 5 | // 9600 bauds, 8-bit data, no parity |
soulx | 0:f4e546303b4e | 6 | //------------------------------------ |
soulx | 0:f4e546303b4e | 7 | |
Pitiwut | 4:fde2463b2846 | 8 | Serial pc(D8, D2); |
soulx | 2:87127bdc7e93 | 9 | |
soulx | 0:f4e546303b4e | 10 | DigitalOut myled(LED1); |
soulx | 0:f4e546303b4e | 11 | |
soulx | 0:f4e546303b4e | 12 | int main() |
soulx | 0:f4e546303b4e | 13 | { |
soulx | 0:f4e546303b4e | 14 | |
soulx | 0:f4e546303b4e | 15 | uint8_t state_menu=0; |
soulx | 0:f4e546303b4e | 16 | uint8_t state_show=0; |
soulx | 0:f4e546303b4e | 17 | uint8_t state_exit =0; |
soulx | 0:f4e546303b4e | 18 | uint8_t data; |
soulx | 0:f4e546303b4e | 19 | |
soulx | 0:f4e546303b4e | 20 | myled = 0; |
Pitiwut | 3:8134f6d1ca47 | 21 | pc.printf("Hello World !\n\n"); |
soulx | 0:f4e546303b4e | 22 | while(1) { |
soulx | 0:f4e546303b4e | 23 | if(state_show == 0) { |
Pitiwut | 3:8134f6d1ca47 | 24 | pc.printf("************\n"); |
Pitiwut | 3:8134f6d1ca47 | 25 | pc.printf(" Menu \n"); |
Pitiwut | 3:8134f6d1ca47 | 26 | pc.printf("************\n"); |
soulx | 0:f4e546303b4e | 27 | pc.printf("1.LED Test\n"); |
soulx | 0:f4e546303b4e | 28 | pc.printf("2.Print Test\n"); |
soulx | 0:f4e546303b4e | 29 | state_show =1; |
soulx | 0:f4e546303b4e | 30 | } |
soulx | 0:f4e546303b4e | 31 | if(pc.readable()) { |
soulx | 0:f4e546303b4e | 32 | data = pc.getc(); |
soulx | 0:f4e546303b4e | 33 | pc.printf("\n"); |
soulx | 0:f4e546303b4e | 34 | state_show =0; |
soulx | 0:f4e546303b4e | 35 | state_exit =0; |
soulx | 0:f4e546303b4e | 36 | |
soulx | 0:f4e546303b4e | 37 | switch(data) { |
soulx | 0:f4e546303b4e | 38 | case '1': |
soulx | 0:f4e546303b4e | 39 | do { |
Pitiwut | 4:fde2463b2846 | 40 | if(state_menu == 0) { |
Pitiwut | 4:fde2463b2846 | 41 | pc.printf("LED Test\n"); |
Pitiwut | 4:fde2463b2846 | 42 | pc.printf("a.LED ON\n"); |
Pitiwut | 4:fde2463b2846 | 43 | pc.printf("s.LED OFF\n"); |
Pitiwut | 4:fde2463b2846 | 44 | pc.printf("x.Exit\n"); |
Pitiwut | 4:fde2463b2846 | 45 | state_menu = 1; |
Pitiwut | 4:fde2463b2846 | 46 | } |
Pitiwut | 4:fde2463b2846 | 47 | |
soulx | 0:f4e546303b4e | 48 | if(pc.readable()) { |
soulx | 0:f4e546303b4e | 49 | data = pc.getc(); |
soulx | 0:f4e546303b4e | 50 | pc.printf("\n"); |
soulx | 0:f4e546303b4e | 51 | state_menu=0; |
soulx | 0:f4e546303b4e | 52 | |
soulx | 0:f4e546303b4e | 53 | switch(data) { |
soulx | 0:f4e546303b4e | 54 | |
soulx | 0:f4e546303b4e | 55 | case 'a': |
soulx | 2:87127bdc7e93 | 56 | myled = 1; |
soulx | 0:f4e546303b4e | 57 | break; |
soulx | 0:f4e546303b4e | 58 | |
soulx | 0:f4e546303b4e | 59 | case 's': |
soulx | 2:87127bdc7e93 | 60 | myled =0; |
soulx | 2:87127bdc7e93 | 61 | |
soulx | 2:87127bdc7e93 | 62 | break; |
soulx | 2:87127bdc7e93 | 63 | |
soulx | 2:87127bdc7e93 | 64 | case 'x': |
soulx | 0:f4e546303b4e | 65 | state_exit =1; |
soulx | 0:f4e546303b4e | 66 | |
soulx | 0:f4e546303b4e | 67 | break; |
soulx | 0:f4e546303b4e | 68 | |
soulx | 0:f4e546303b4e | 69 | default: |
soulx | 2:87127bdc7e93 | 70 | pc.printf("plz select a or s\n"); |
soulx | 2:87127bdc7e93 | 71 | pc.printf("\n\n"); |
soulx | 0:f4e546303b4e | 72 | break; |
soulx | 0:f4e546303b4e | 73 | } |
soulx | 0:f4e546303b4e | 74 | } |
soulx | 0:f4e546303b4e | 75 | } while(state_exit ==0); |
Pitiwut | 4:fde2463b2846 | 76 | |
Pitiwut | 3:8134f6d1ca47 | 77 | pc.printf("\n"); |
soulx | 0:f4e546303b4e | 78 | break; |
soulx | 0:f4e546303b4e | 79 | |
soulx | 0:f4e546303b4e | 80 | case '2': |
soulx | 0:f4e546303b4e | 81 | |
soulx | 0:f4e546303b4e | 82 | do { |
soulx | 0:f4e546303b4e | 83 | if(state_menu == 0) { |
Pitiwut | 3:8134f6d1ca47 | 84 | pc.printf("Print Test\n"); |
Pitiwut | 3:8134f6d1ca47 | 85 | pc.printf("a.Print -Hello-\n"); |
Pitiwut | 3:8134f6d1ca47 | 86 | pc.printf("s.Print -Bye Bye-\n"); |
soulx | 0:f4e546303b4e | 87 | pc.printf("x.Exit\n"); |
soulx | 0:f4e546303b4e | 88 | state_menu = 1; |
soulx | 0:f4e546303b4e | 89 | } |
soulx | 2:87127bdc7e93 | 90 | if(pc.readable()) { |
soulx | 0:f4e546303b4e | 91 | data = pc.getc(); |
soulx | 0:f4e546303b4e | 92 | pc.printf("\n"); |
soulx | 0:f4e546303b4e | 93 | state_menu=0; |
soulx | 2:87127bdc7e93 | 94 | |
soulx | 2:87127bdc7e93 | 95 | switch(data) { |
soulx | 2:87127bdc7e93 | 96 | |
soulx | 2:87127bdc7e93 | 97 | case 'a': |
Pitiwut | 3:8134f6d1ca47 | 98 | pc.printf("--> Hello <-- \n\n"); |
soulx | 2:87127bdc7e93 | 99 | |
soulx | 2:87127bdc7e93 | 100 | break; |
soulx | 2:87127bdc7e93 | 101 | |
soulx | 2:87127bdc7e93 | 102 | case 's': |
Pitiwut | 3:8134f6d1ca47 | 103 | pc.printf("--> Bye Bye <-- \n\n"); |
soulx | 2:87127bdc7e93 | 104 | |
soulx | 2:87127bdc7e93 | 105 | break; |
soulx | 2:87127bdc7e93 | 106 | |
soulx | 2:87127bdc7e93 | 107 | case 'x': |
soulx | 2:87127bdc7e93 | 108 | state_exit =1; |
soulx | 2:87127bdc7e93 | 109 | |
soulx | 2:87127bdc7e93 | 110 | |
soulx | 2:87127bdc7e93 | 111 | break; |
soulx | 0:f4e546303b4e | 112 | |
soulx | 0:f4e546303b4e | 113 | default: |
soulx | 0:f4e546303b4e | 114 | pc.printf("plz select a or s\n"); |
Pitiwut | 3:8134f6d1ca47 | 115 | pc.printf("\n"); |
soulx | 0:f4e546303b4e | 116 | break; |
soulx | 0:f4e546303b4e | 117 | |
soulx | 2:87127bdc7e93 | 118 | } |
soulx | 0:f4e546303b4e | 119 | } |
soulx | 2:87127bdc7e93 | 120 | } while(state_exit ==0); |
Pitiwut | 3:8134f6d1ca47 | 121 | pc.printf("\n"); |
soulx | 0:f4e546303b4e | 122 | break; |
soulx | 0:f4e546303b4e | 123 | |
soulx | 0:f4e546303b4e | 124 | |
soulx | 2:87127bdc7e93 | 125 | default: |
soulx | 2:87127bdc7e93 | 126 | pc.printf("plz select 1 or 2 only\n"); |
Pitiwut | 3:8134f6d1ca47 | 127 | pc.printf("\n"); |
soulx | 2:87127bdc7e93 | 128 | break; |
soulx | 0:f4e546303b4e | 129 | } |
soulx | 0:f4e546303b4e | 130 | } |
soulx | 0:f4e546303b4e | 131 | } |
soulx | 0:f4e546303b4e | 132 | } |