Serial_command
Dependencies: mbed
main.cpp@0:6ed167046340, 2015-11-16 (annotated)
- Committer:
- NorNick
- Date:
- Mon Nov 16 17:03:38 2015 +0000
- Revision:
- 0:6ed167046340
Finish
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
NorNick | 0:6ed167046340 | 1 | #include "mbed.h" |
NorNick | 0:6ed167046340 | 2 | |
NorNick | 0:6ed167046340 | 3 | //------------------------------------ |
NorNick | 0:6ed167046340 | 4 | // Hyperterminal configuration |
NorNick | 0:6ed167046340 | 5 | // 9600 bauds, 8-bit data, no parity |
NorNick | 0:6ed167046340 | 6 | //------------------------------------ |
NorNick | 0:6ed167046340 | 7 | |
NorNick | 0:6ed167046340 | 8 | Serial pc(SERIAL_TX, SERIAL_RX); |
NorNick | 0:6ed167046340 | 9 | |
NorNick | 0:6ed167046340 | 10 | //Serial pc(D8, D2); |
NorNick | 0:6ed167046340 | 11 | |
NorNick | 0:6ed167046340 | 12 | DigitalIn Sw(D3); |
NorNick | 0:6ed167046340 | 13 | |
NorNick | 0:6ed167046340 | 14 | BusOut ledSet(D4, D9, D5, D11, D12, D13, D14, D15); |
NorNick | 0:6ed167046340 | 15 | |
NorNick | 0:6ed167046340 | 16 | Timer t; |
NorNick | 0:6ed167046340 | 17 | |
NorNick | 0:6ed167046340 | 18 | int main() |
NorNick | 0:6ed167046340 | 19 | { |
NorNick | 0:6ed167046340 | 20 | |
NorNick | 0:6ed167046340 | 21 | uint8_t state_menu=0; |
NorNick | 0:6ed167046340 | 22 | uint8_t state_show=0; |
NorNick | 0:6ed167046340 | 23 | uint8_t state_exit =0; |
NorNick | 0:6ed167046340 | 24 | uint8_t data; |
NorNick | 0:6ed167046340 | 25 | int timer_delay1=200,timer_delay2=400,timer_delay3=600,timer_delay4=800; |
NorNick | 0:6ed167046340 | 26 | t.start(); |
NorNick | 0:6ed167046340 | 27 | ledSet = 0; |
NorNick | 0:6ed167046340 | 28 | pc.printf("Hello Nucleo !\n"); |
NorNick | 0:6ed167046340 | 29 | while(1) { |
NorNick | 0:6ed167046340 | 30 | if(state_show == 0) { |
NorNick | 0:6ed167046340 | 31 | pc.printf("Menu\n"); |
NorNick | 0:6ed167046340 | 32 | pc.printf("1.LED Test\n"); |
NorNick | 0:6ed167046340 | 33 | pc.printf("2.Switch Test\n"); |
NorNick | 0:6ed167046340 | 34 | state_show =1; |
NorNick | 0:6ed167046340 | 35 | } |
NorNick | 0:6ed167046340 | 36 | if(pc.readable()) { |
NorNick | 0:6ed167046340 | 37 | data = pc.getc(); |
NorNick | 0:6ed167046340 | 38 | pc.printf("\n"); |
NorNick | 0:6ed167046340 | 39 | state_show =0; |
NorNick | 0:6ed167046340 | 40 | state_exit =0; |
NorNick | 0:6ed167046340 | 41 | |
NorNick | 0:6ed167046340 | 42 | switch(data) { |
NorNick | 0:6ed167046340 | 43 | case '1': |
NorNick | 0:6ed167046340 | 44 | /*Bew Style*/ |
NorNick | 0:6ed167046340 | 45 | do { |
NorNick | 0:6ed167046340 | 46 | if(state_menu == 0) { |
NorNick | 0:6ed167046340 | 47 | pc.printf("LED Test\n"); |
NorNick | 0:6ed167046340 | 48 | pc.printf("a.LED ModeI\n"); |
NorNick | 0:6ed167046340 | 49 | pc.printf("d.LED ModeII\n"); |
NorNick | 0:6ed167046340 | 50 | pc.printf("s.Exit\n"); |
NorNick | 0:6ed167046340 | 51 | state_menu = 1; |
NorNick | 0:6ed167046340 | 52 | } |
NorNick | 0:6ed167046340 | 53 | if(pc.readable()) { |
NorNick | 0:6ed167046340 | 54 | data = pc.getc(); |
NorNick | 0:6ed167046340 | 55 | pc.printf("\n"); |
NorNick | 0:6ed167046340 | 56 | //state_menu=0; |
NorNick | 0:6ed167046340 | 57 | |
NorNick | 0:6ed167046340 | 58 | switch(data) { |
NorNick | 0:6ed167046340 | 59 | |
NorNick | 0:6ed167046340 | 60 | case 'a': |
NorNick | 0:6ed167046340 | 61 | pc.printf("LED ModeI ON.\n"); |
NorNick | 0:6ed167046340 | 62 | pc.printf("LED Test\n"); |
NorNick | 0:6ed167046340 | 63 | pc.printf("a.LED ModeI\n"); |
NorNick | 0:6ed167046340 | 64 | pc.printf("d.LED ModeII\n"); |
NorNick | 0:6ed167046340 | 65 | pc.printf("s.Exit\n"); |
NorNick | 0:6ed167046340 | 66 | while(1){ |
NorNick | 0:6ed167046340 | 67 | if(pc.readable()==0){ |
NorNick | 0:6ed167046340 | 68 | if(t.read_ms() <timer_delay1) { |
NorNick | 0:6ed167046340 | 69 | ledSet = 0xAA; |
NorNick | 0:6ed167046340 | 70 | } else if(t.read_ms() <timer_delay2) { |
NorNick | 0:6ed167046340 | 71 | ledSet = 0x55; |
NorNick | 0:6ed167046340 | 72 | } else { |
NorNick | 0:6ed167046340 | 73 | t.reset(); |
NorNick | 0:6ed167046340 | 74 | } |
NorNick | 0:6ed167046340 | 75 | } |
NorNick | 0:6ed167046340 | 76 | else{ |
NorNick | 0:6ed167046340 | 77 | break; |
NorNick | 0:6ed167046340 | 78 | } |
NorNick | 0:6ed167046340 | 79 | } |
NorNick | 0:6ed167046340 | 80 | |
NorNick | 0:6ed167046340 | 81 | break; |
NorNick | 0:6ed167046340 | 82 | |
NorNick | 0:6ed167046340 | 83 | case 'd': |
NorNick | 0:6ed167046340 | 84 | pc.printf("LED ModeII ON.\n"); |
NorNick | 0:6ed167046340 | 85 | pc.printf("LED Test\n"); |
NorNick | 0:6ed167046340 | 86 | pc.printf("a.LED ModeI\n"); |
NorNick | 0:6ed167046340 | 87 | pc.printf("d.LED ModeII\n"); |
NorNick | 0:6ed167046340 | 88 | pc.printf("s.Exit\n"); |
NorNick | 0:6ed167046340 | 89 | while(1){ |
NorNick | 0:6ed167046340 | 90 | if(pc.readable()==0){ |
NorNick | 0:6ed167046340 | 91 | if(t.read_ms() <timer_delay1) { |
NorNick | 0:6ed167046340 | 92 | ledSet = 0xF0; |
NorNick | 0:6ed167046340 | 93 | } else if(t.read_ms() <timer_delay2) { |
NorNick | 0:6ed167046340 | 94 | ledSet = 0x0F; |
NorNick | 0:6ed167046340 | 95 | } else if(t.read_ms() <timer_delay3) { |
NorNick | 0:6ed167046340 | 96 | ledSet = 0xCC; |
NorNick | 0:6ed167046340 | 97 | } else if(t.read_ms() <timer_delay4) { |
NorNick | 0:6ed167046340 | 98 | ledSet = 0x33; |
NorNick | 0:6ed167046340 | 99 | }else { |
NorNick | 0:6ed167046340 | 100 | t.reset(); |
NorNick | 0:6ed167046340 | 101 | } |
NorNick | 0:6ed167046340 | 102 | } |
NorNick | 0:6ed167046340 | 103 | else{ |
NorNick | 0:6ed167046340 | 104 | break; |
NorNick | 0:6ed167046340 | 105 | } |
NorNick | 0:6ed167046340 | 106 | } |
NorNick | 0:6ed167046340 | 107 | break; |
NorNick | 0:6ed167046340 | 108 | |
NorNick | 0:6ed167046340 | 109 | case 's': |
NorNick | 0:6ed167046340 | 110 | ledSet = 0x00; |
NorNick | 0:6ed167046340 | 111 | state_menu=0; |
NorNick | 0:6ed167046340 | 112 | state_exit =1; |
NorNick | 0:6ed167046340 | 113 | pc.printf("Exit..... \n"); |
NorNick | 0:6ed167046340 | 114 | |
NorNick | 0:6ed167046340 | 115 | |
NorNick | 0:6ed167046340 | 116 | break; |
NorNick | 0:6ed167046340 | 117 | |
NorNick | 0:6ed167046340 | 118 | default: |
NorNick | 0:6ed167046340 | 119 | pc.printf("plz select a or s\n"); |
NorNick | 0:6ed167046340 | 120 | pc.printf("\n\n"); |
NorNick | 0:6ed167046340 | 121 | break; |
NorNick | 0:6ed167046340 | 122 | |
NorNick | 0:6ed167046340 | 123 | } |
NorNick | 0:6ed167046340 | 124 | } |
NorNick | 0:6ed167046340 | 125 | |
NorNick | 0:6ed167046340 | 126 | } while(state_exit ==0); |
NorNick | 0:6ed167046340 | 127 | pc.printf("\n\n"); |
NorNick | 0:6ed167046340 | 128 | break; |
NorNick | 0:6ed167046340 | 129 | |
NorNick | 0:6ed167046340 | 130 | case '2': |
NorNick | 0:6ed167046340 | 131 | |
NorNick | 0:6ed167046340 | 132 | do { |
NorNick | 0:6ed167046340 | 133 | if(state_menu == 0) { |
NorNick | 0:6ed167046340 | 134 | pc.printf("Switch Test\n"); |
NorNick | 0:6ed167046340 | 135 | pc.printf("a.Read Switch\n"); |
NorNick | 0:6ed167046340 | 136 | pc.printf("s.Exit\n"); |
NorNick | 0:6ed167046340 | 137 | state_menu = 1; |
NorNick | 0:6ed167046340 | 138 | } |
NorNick | 0:6ed167046340 | 139 | if(pc.readable()) { |
NorNick | 0:6ed167046340 | 140 | data = pc.getc(); |
NorNick | 0:6ed167046340 | 141 | pc.printf("\n"); |
NorNick | 0:6ed167046340 | 142 | state_menu=0; |
NorNick | 0:6ed167046340 | 143 | |
NorNick | 0:6ed167046340 | 144 | switch(data) { |
NorNick | 0:6ed167046340 | 145 | |
NorNick | 0:6ed167046340 | 146 | case 'a': |
NorNick | 0:6ed167046340 | 147 | |
NorNick | 0:6ed167046340 | 148 | pc.printf("Status :: %d \n",Sw.read()); |
NorNick | 0:6ed167046340 | 149 | |
NorNick | 0:6ed167046340 | 150 | break; |
NorNick | 0:6ed167046340 | 151 | |
NorNick | 0:6ed167046340 | 152 | case 's': |
NorNick | 0:6ed167046340 | 153 | state_exit =1; |
NorNick | 0:6ed167046340 | 154 | |
NorNick | 0:6ed167046340 | 155 | |
NorNick | 0:6ed167046340 | 156 | break; |
NorNick | 0:6ed167046340 | 157 | |
NorNick | 0:6ed167046340 | 158 | default: |
NorNick | 0:6ed167046340 | 159 | pc.printf("plz select a or x\n"); |
NorNick | 0:6ed167046340 | 160 | pc.printf("\n\n"); |
NorNick | 0:6ed167046340 | 161 | break; |
NorNick | 0:6ed167046340 | 162 | |
NorNick | 0:6ed167046340 | 163 | } |
NorNick | 0:6ed167046340 | 164 | } |
NorNick | 0:6ed167046340 | 165 | |
NorNick | 0:6ed167046340 | 166 | } while(state_exit ==0); |
NorNick | 0:6ed167046340 | 167 | pc.printf("\n\n"); |
NorNick | 0:6ed167046340 | 168 | break; |
NorNick | 0:6ed167046340 | 169 | |
NorNick | 0:6ed167046340 | 170 | |
NorNick | 0:6ed167046340 | 171 | case 0x00: |
NorNick | 0:6ed167046340 | 172 | |
NorNick | 0:6ed167046340 | 173 | break; |
NorNick | 0:6ed167046340 | 174 | |
NorNick | 0:6ed167046340 | 175 | default: |
NorNick | 0:6ed167046340 | 176 | pc.printf("plz select 1 or 2 only\n"); |
NorNick | 0:6ed167046340 | 177 | pc.printf("\n\n"); |
NorNick | 0:6ed167046340 | 178 | break; |
NorNick | 0:6ed167046340 | 179 | } |
NorNick | 0:6ed167046340 | 180 | } |
NorNick | 0:6ed167046340 | 181 | |
NorNick | 0:6ed167046340 | 182 | |
NorNick | 0:6ed167046340 | 183 | } |
NorNick | 0:6ed167046340 | 184 | } |