Simulateur CAN 1.0
Dependencies: mbed
Fork of CAN by
main.cpp@1:f961845c25eb, 2018-02-06 (annotated)
- Committer:
- protongamer
- Date:
- Tue Feb 06 07:26:55 2018 +0000
- Revision:
- 1:f961845c25eb
- Parent:
- 0:cea062e60f85
Test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
LabSE | 0:cea062e60f85 | 1 | #include "mbed.h" |
LabSE | 0:cea062e60f85 | 2 | |
LabSE | 0:cea062e60f85 | 3 | Ticker ticker; |
LabSE | 0:cea062e60f85 | 4 | DigitalOut led1(LED1); |
LabSE | 0:cea062e60f85 | 5 | DigitalOut led2(LED2); |
protongamer | 1:f961845c25eb | 6 | |
protongamer | 1:f961845c25eb | 7 | Serial pc(D1, D0); |
protongamer | 1:f961845c25eb | 8 | CAN can1(p9, p10); |
LabSE | 0:cea062e60f85 | 9 | CAN can2(p30, p29); |
protongamer | 1:f961845c25eb | 10 | |
protongamer | 1:f961845c25eb | 11 | char value = 0; |
protongamer | 1:f961845c25eb | 12 | uint8_t state = 0; |
protongamer | 1:f961845c25eb | 13 | |
protongamer | 1:f961845c25eb | 14 | void send(char counter) { |
protongamer | 1:f961845c25eb | 15 | //pc.printf("send()\n"); |
protongamer | 1:f961845c25eb | 16 | if(can2.write(CANMessage(1338, &counter, 8))) { |
protongamer | 1:f961845c25eb | 17 | //pc.printf("wloop()\n"); |
protongamer | 1:f961845c25eb | 18 | //counter++; |
protongamer | 1:f961845c25eb | 19 | pc.printf("Message sent: %d\r\n", counter); |
protongamer | 1:f961845c25eb | 20 | } |
protongamer | 1:f961845c25eb | 21 | led1 = !led1; |
LabSE | 0:cea062e60f85 | 22 | } |
LabSE | 0:cea062e60f85 | 23 | |
LabSE | 0:cea062e60f85 | 24 | int main() { |
protongamer | 1:f961845c25eb | 25 | |
protongamer | 1:f961845c25eb | 26 | //ticker.attach(&send, 1); |
LabSE | 0:cea062e60f85 | 27 | CANMessage msg; |
protongamer | 1:f961845c25eb | 28 | /*char c; |
protongamer | 1:f961845c25eb | 29 | uint16_t instruction; |
protongamer | 1:f961845c25eb | 30 | uint16_t instruction_2; |
protongamer | 1:f961845c25eb | 31 | uint8_t bytes; |
protongamer | 1:f961845c25eb | 32 | int8_t state_val;*/ |
LabSE | 0:cea062e60f85 | 33 | while(1) { |
protongamer | 1:f961845c25eb | 34 | //c = pc.getc(); |
protongamer | 1:f961845c25eb | 35 | |
protongamer | 1:f961845c25eb | 36 | if(can2.read(msg)) { |
protongamer | 1:f961845c25eb | 37 | printf("Message received: %d\n", msg.data[0]); |
protongamer | 1:f961845c25eb | 38 | led2 = !led2; |
protongamer | 1:f961845c25eb | 39 | wait(1.0); |
protongamer | 1:f961845c25eb | 40 | send(0x2A); |
protongamer | 1:f961845c25eb | 41 | } |
protongamer | 1:f961845c25eb | 42 | |
protongamer | 1:f961845c25eb | 43 | printf("awaiting data \r\n"); |
protongamer | 1:f961845c25eb | 44 | wait(0.5); |
protongamer | 1:f961845c25eb | 45 | } |
protongamer | 1:f961845c25eb | 46 | |
protongamer | 1:f961845c25eb | 47 | } |
protongamer | 1:f961845c25eb | 48 | /*switch(state){ |
protongamer | 1:f961845c25eb | 49 | |
protongamer | 1:f961845c25eb | 50 | case 0: |
protongamer | 1:f961845c25eb | 51 | pc.printf("CAN BUS - TERMINAL \r\n"); |
protongamer | 1:f961845c25eb | 52 | pc.printf("Use 1 to set the value to be sent\r\n"); |
protongamer | 1:f961845c25eb | 53 | pc.printf("Use 2 to send the value \r\n"); |
protongamer | 1:f961845c25eb | 54 | state = 1; |
protongamer | 1:f961845c25eb | 55 | break; |
protongamer | 1:f961845c25eb | 56 | |
protongamer | 1:f961845c25eb | 57 | case 1: |
protongamer | 1:f961845c25eb | 58 | |
protongamer | 1:f961845c25eb | 59 | if(c == '1'){ |
protongamer | 1:f961845c25eb | 60 | instruction = 0; |
protongamer | 1:f961845c25eb | 61 | state_val = 0; |
protongamer | 1:f961845c25eb | 62 | pc.printf("1 \r\n\n"); |
protongamer | 1:f961845c25eb | 63 | wait(1.0); |
protongamer | 1:f961845c25eb | 64 | state = 2; |
protongamer | 1:f961845c25eb | 65 | } |
protongamer | 1:f961845c25eb | 66 | |
protongamer | 1:f961845c25eb | 67 | if(c == '2'){ |
protongamer | 1:f961845c25eb | 68 | pc.printf("2 \r\n\n"); |
protongamer | 1:f961845c25eb | 69 | wait(1.0); |
protongamer | 1:f961845c25eb | 70 | switch(bytes){ |
protongamer | 1:f961845c25eb | 71 | |
protongamer | 1:f961845c25eb | 72 | case 1: |
protongamer | 1:f961845c25eb | 73 | send(instruction); |
protongamer | 1:f961845c25eb | 74 | break; |
protongamer | 1:f961845c25eb | 75 | |
protongamer | 1:f961845c25eb | 76 | case 2: |
protongamer | 1:f961845c25eb | 77 | send(instruction_2); |
protongamer | 1:f961845c25eb | 78 | send(instruction); |
protongamer | 1:f961845c25eb | 79 | break; |
protongamer | 1:f961845c25eb | 80 | } |
protongamer | 1:f961845c25eb | 81 | state = 0; |
protongamer | 1:f961845c25eb | 82 | } |
protongamer | 1:f961845c25eb | 83 | |
protongamer | 1:f961845c25eb | 84 | |
protongamer | 1:f961845c25eb | 85 | |
protongamer | 1:f961845c25eb | 86 | break; |
protongamer | 1:f961845c25eb | 87 | |
protongamer | 1:f961845c25eb | 88 | case 2: |
protongamer | 1:f961845c25eb | 89 | pc.printf("Set the value to be sent(hex value) : 0x"); |
protongamer | 1:f961845c25eb | 90 | state = 3; |
protongamer | 1:f961845c25eb | 91 | break; |
protongamer | 1:f961845c25eb | 92 | |
protongamer | 1:f961845c25eb | 93 | case 3: |
protongamer | 1:f961845c25eb | 94 | |
protongamer | 1:f961845c25eb | 95 | switch(c){ |
protongamer | 1:f961845c25eb | 96 | |
protongamer | 1:f961845c25eb | 97 | |
protongamer | 1:f961845c25eb | 98 | |
protongamer | 1:f961845c25eb | 99 | case '0': |
protongamer | 1:f961845c25eb | 100 | pc.printf("0"); |
protongamer | 1:f961845c25eb | 101 | |
protongamer | 1:f961845c25eb | 102 | if(state_val > 0){ |
protongamer | 1:f961845c25eb | 103 | instruction = instruction << 4; |
protongamer | 1:f961845c25eb | 104 | instruction |= 0b0000; |
protongamer | 1:f961845c25eb | 105 | } |
protongamer | 1:f961845c25eb | 106 | |
protongamer | 1:f961845c25eb | 107 | if(state_val == 0){ |
protongamer | 1:f961845c25eb | 108 | instruction = 0b0000; |
protongamer | 1:f961845c25eb | 109 | state_val++; |
protongamer | 1:f961845c25eb | 110 | } |
protongamer | 1:f961845c25eb | 111 | |
protongamer | 1:f961845c25eb | 112 | break; |
protongamer | 1:f961845c25eb | 113 | |
protongamer | 1:f961845c25eb | 114 | case '1': |
protongamer | 1:f961845c25eb | 115 | |
protongamer | 1:f961845c25eb | 116 | if(state_val > 0){ |
protongamer | 1:f961845c25eb | 117 | instruction = instruction << 4; |
protongamer | 1:f961845c25eb | 118 | instruction |= 0b0001; |
protongamer | 1:f961845c25eb | 119 | } |
protongamer | 1:f961845c25eb | 120 | |
protongamer | 1:f961845c25eb | 121 | pc.printf("1"); |
protongamer | 1:f961845c25eb | 122 | if(state_val == 0){ |
protongamer | 1:f961845c25eb | 123 | instruction = 0b0001; |
protongamer | 1:f961845c25eb | 124 | state_val++; |
protongamer | 1:f961845c25eb | 125 | } |
protongamer | 1:f961845c25eb | 126 | |
protongamer | 1:f961845c25eb | 127 | break; |
protongamer | 1:f961845c25eb | 128 | |
protongamer | 1:f961845c25eb | 129 | case '2': |
protongamer | 1:f961845c25eb | 130 | |
protongamer | 1:f961845c25eb | 131 | if(state_val > 0){ |
protongamer | 1:f961845c25eb | 132 | instruction = instruction << 4; |
protongamer | 1:f961845c25eb | 133 | instruction |= 0b0010; |
protongamer | 1:f961845c25eb | 134 | } |
protongamer | 1:f961845c25eb | 135 | |
protongamer | 1:f961845c25eb | 136 | pc.printf("2"); |
protongamer | 1:f961845c25eb | 137 | if(state_val == 0){ |
protongamer | 1:f961845c25eb | 138 | instruction = 0b0010; |
protongamer | 1:f961845c25eb | 139 | state_val++; |
protongamer | 1:f961845c25eb | 140 | } |
protongamer | 1:f961845c25eb | 141 | |
protongamer | 1:f961845c25eb | 142 | break; |
protongamer | 1:f961845c25eb | 143 | |
protongamer | 1:f961845c25eb | 144 | case '3': |
protongamer | 1:f961845c25eb | 145 | pc.printf("3"); |
protongamer | 1:f961845c25eb | 146 | |
protongamer | 1:f961845c25eb | 147 | if(state_val > 0){ |
protongamer | 1:f961845c25eb | 148 | instruction = instruction << 4; |
protongamer | 1:f961845c25eb | 149 | instruction |= 0b0011; |
protongamer | 1:f961845c25eb | 150 | } |
protongamer | 1:f961845c25eb | 151 | |
protongamer | 1:f961845c25eb | 152 | if(state_val == 0){ |
protongamer | 1:f961845c25eb | 153 | instruction = 0b0011; |
protongamer | 1:f961845c25eb | 154 | state_val++; |
protongamer | 1:f961845c25eb | 155 | } |
protongamer | 1:f961845c25eb | 156 | |
protongamer | 1:f961845c25eb | 157 | break; |
protongamer | 1:f961845c25eb | 158 | |
protongamer | 1:f961845c25eb | 159 | case '4': |
protongamer | 1:f961845c25eb | 160 | |
protongamer | 1:f961845c25eb | 161 | if(state_val > 0){ |
protongamer | 1:f961845c25eb | 162 | instruction = instruction << 4; |
protongamer | 1:f961845c25eb | 163 | instruction |= 0b0100; |
protongamer | 1:f961845c25eb | 164 | } |
protongamer | 1:f961845c25eb | 165 | |
protongamer | 1:f961845c25eb | 166 | pc.printf("4"); |
protongamer | 1:f961845c25eb | 167 | if(state_val == 0){ |
protongamer | 1:f961845c25eb | 168 | instruction = 0b0100; |
protongamer | 1:f961845c25eb | 169 | state_val++; |
protongamer | 1:f961845c25eb | 170 | } |
protongamer | 1:f961845c25eb | 171 | |
protongamer | 1:f961845c25eb | 172 | break; |
protongamer | 1:f961845c25eb | 173 | |
protongamer | 1:f961845c25eb | 174 | case '5': |
protongamer | 1:f961845c25eb | 175 | pc.printf("5"); |
protongamer | 1:f961845c25eb | 176 | |
protongamer | 1:f961845c25eb | 177 | if(state_val > 0){ |
protongamer | 1:f961845c25eb | 178 | instruction = instruction << 4; |
protongamer | 1:f961845c25eb | 179 | instruction |= 0b0101; |
protongamer | 1:f961845c25eb | 180 | } |
protongamer | 1:f961845c25eb | 181 | |
protongamer | 1:f961845c25eb | 182 | if(state_val == 0){ |
protongamer | 1:f961845c25eb | 183 | instruction = 0b0101; |
protongamer | 1:f961845c25eb | 184 | state_val++; |
protongamer | 1:f961845c25eb | 185 | } |
protongamer | 1:f961845c25eb | 186 | |
protongamer | 1:f961845c25eb | 187 | break; |
protongamer | 1:f961845c25eb | 188 | |
protongamer | 1:f961845c25eb | 189 | case '6': |
protongamer | 1:f961845c25eb | 190 | pc.printf("6"); |
protongamer | 1:f961845c25eb | 191 | |
protongamer | 1:f961845c25eb | 192 | if(state_val > 0){ |
protongamer | 1:f961845c25eb | 193 | instruction = instruction << 4; |
protongamer | 1:f961845c25eb | 194 | instruction |= 0b0110; |
protongamer | 1:f961845c25eb | 195 | } |
protongamer | 1:f961845c25eb | 196 | |
protongamer | 1:f961845c25eb | 197 | if(state_val == 0){ |
protongamer | 1:f961845c25eb | 198 | instruction = 0b0110; |
protongamer | 1:f961845c25eb | 199 | state_val++; |
protongamer | 1:f961845c25eb | 200 | } |
protongamer | 1:f961845c25eb | 201 | |
protongamer | 1:f961845c25eb | 202 | break; |
protongamer | 1:f961845c25eb | 203 | |
protongamer | 1:f961845c25eb | 204 | case '7': |
protongamer | 1:f961845c25eb | 205 | pc.printf("7"); |
protongamer | 1:f961845c25eb | 206 | |
protongamer | 1:f961845c25eb | 207 | if(state_val > 0){ |
protongamer | 1:f961845c25eb | 208 | instruction = instruction << 4; |
protongamer | 1:f961845c25eb | 209 | instruction |= 0b0111; |
protongamer | 1:f961845c25eb | 210 | } |
protongamer | 1:f961845c25eb | 211 | |
protongamer | 1:f961845c25eb | 212 | if(state_val == 0){ |
protongamer | 1:f961845c25eb | 213 | instruction = 0b0111; |
protongamer | 1:f961845c25eb | 214 | state_val++; |
protongamer | 1:f961845c25eb | 215 | } |
protongamer | 1:f961845c25eb | 216 | |
protongamer | 1:f961845c25eb | 217 | break; |
protongamer | 1:f961845c25eb | 218 | |
protongamer | 1:f961845c25eb | 219 | case '8': |
protongamer | 1:f961845c25eb | 220 | pc.printf("8"); |
protongamer | 1:f961845c25eb | 221 | |
protongamer | 1:f961845c25eb | 222 | if(state_val > 0){ |
protongamer | 1:f961845c25eb | 223 | instruction = instruction << 4; |
protongamer | 1:f961845c25eb | 224 | instruction |= 0b1000; |
protongamer | 1:f961845c25eb | 225 | } |
protongamer | 1:f961845c25eb | 226 | |
protongamer | 1:f961845c25eb | 227 | |
protongamer | 1:f961845c25eb | 228 | if(state_val == 0){ |
protongamer | 1:f961845c25eb | 229 | instruction = 0b1000; |
protongamer | 1:f961845c25eb | 230 | state_val++; |
protongamer | 1:f961845c25eb | 231 | } |
protongamer | 1:f961845c25eb | 232 | |
protongamer | 1:f961845c25eb | 233 | break; |
protongamer | 1:f961845c25eb | 234 | |
protongamer | 1:f961845c25eb | 235 | case '9': |
protongamer | 1:f961845c25eb | 236 | pc.printf("9"); |
protongamer | 1:f961845c25eb | 237 | |
protongamer | 1:f961845c25eb | 238 | if(state_val > 0){ |
protongamer | 1:f961845c25eb | 239 | instruction = instruction << 4; |
protongamer | 1:f961845c25eb | 240 | instruction |= 0b1001; |
protongamer | 1:f961845c25eb | 241 | } |
protongamer | 1:f961845c25eb | 242 | |
protongamer | 1:f961845c25eb | 243 | if(state_val == 0){ |
protongamer | 1:f961845c25eb | 244 | instruction = 0b1001; |
protongamer | 1:f961845c25eb | 245 | state_val++; |
protongamer | 1:f961845c25eb | 246 | } |
protongamer | 1:f961845c25eb | 247 | |
protongamer | 1:f961845c25eb | 248 | break; |
protongamer | 1:f961845c25eb | 249 | |
protongamer | 1:f961845c25eb | 250 | case 'a': |
protongamer | 1:f961845c25eb | 251 | pc.printf("a"); |
protongamer | 1:f961845c25eb | 252 | |
protongamer | 1:f961845c25eb | 253 | if(state_val > 0){ |
protongamer | 1:f961845c25eb | 254 | instruction = instruction << 4; |
protongamer | 1:f961845c25eb | 255 | instruction |= 0b1010; |
protongamer | 1:f961845c25eb | 256 | } |
protongamer | 1:f961845c25eb | 257 | |
protongamer | 1:f961845c25eb | 258 | if(state_val == 0){ |
protongamer | 1:f961845c25eb | 259 | instruction = 0b1010; |
protongamer | 1:f961845c25eb | 260 | state_val++; |
protongamer | 1:f961845c25eb | 261 | } |
protongamer | 1:f961845c25eb | 262 | |
protongamer | 1:f961845c25eb | 263 | break; |
protongamer | 1:f961845c25eb | 264 | |
protongamer | 1:f961845c25eb | 265 | case 'b': |
protongamer | 1:f961845c25eb | 266 | pc.printf("b"); |
protongamer | 1:f961845c25eb | 267 | |
protongamer | 1:f961845c25eb | 268 | if(state_val > 0){ |
protongamer | 1:f961845c25eb | 269 | instruction = instruction << 4; |
protongamer | 1:f961845c25eb | 270 | instruction |= 0b1011; |
protongamer | 1:f961845c25eb | 271 | } |
protongamer | 1:f961845c25eb | 272 | |
protongamer | 1:f961845c25eb | 273 | if(state_val == 0){ |
protongamer | 1:f961845c25eb | 274 | instruction = 0b1011; |
protongamer | 1:f961845c25eb | 275 | state_val++; |
protongamer | 1:f961845c25eb | 276 | } |
protongamer | 1:f961845c25eb | 277 | |
protongamer | 1:f961845c25eb | 278 | break; |
protongamer | 1:f961845c25eb | 279 | |
protongamer | 1:f961845c25eb | 280 | case 'c': |
protongamer | 1:f961845c25eb | 281 | pc.printf("c"); |
protongamer | 1:f961845c25eb | 282 | |
protongamer | 1:f961845c25eb | 283 | if(state_val > 0){ |
protongamer | 1:f961845c25eb | 284 | instruction = instruction << 4; |
protongamer | 1:f961845c25eb | 285 | instruction |= 0b1100; |
protongamer | 1:f961845c25eb | 286 | } |
protongamer | 1:f961845c25eb | 287 | |
protongamer | 1:f961845c25eb | 288 | if(state_val == 0){ |
protongamer | 1:f961845c25eb | 289 | instruction = 0b1100; |
protongamer | 1:f961845c25eb | 290 | state_val++; |
protongamer | 1:f961845c25eb | 291 | } |
protongamer | 1:f961845c25eb | 292 | |
protongamer | 1:f961845c25eb | 293 | break; |
protongamer | 1:f961845c25eb | 294 | |
protongamer | 1:f961845c25eb | 295 | case 'd': |
protongamer | 1:f961845c25eb | 296 | pc.printf("d"); |
protongamer | 1:f961845c25eb | 297 | |
protongamer | 1:f961845c25eb | 298 | if(state_val > 0){ |
protongamer | 1:f961845c25eb | 299 | instruction = instruction << 4; |
protongamer | 1:f961845c25eb | 300 | instruction |= 0b1101; |
protongamer | 1:f961845c25eb | 301 | } |
protongamer | 1:f961845c25eb | 302 | |
protongamer | 1:f961845c25eb | 303 | if(state_val == 0){ |
protongamer | 1:f961845c25eb | 304 | instruction = 0b1101; |
protongamer | 1:f961845c25eb | 305 | state_val++; |
protongamer | 1:f961845c25eb | 306 | } |
protongamer | 1:f961845c25eb | 307 | |
protongamer | 1:f961845c25eb | 308 | break; |
protongamer | 1:f961845c25eb | 309 | |
protongamer | 1:f961845c25eb | 310 | case 'e': |
protongamer | 1:f961845c25eb | 311 | pc.printf("e"); |
protongamer | 1:f961845c25eb | 312 | |
protongamer | 1:f961845c25eb | 313 | if(state_val > 0){ |
protongamer | 1:f961845c25eb | 314 | instruction = instruction << 4; |
protongamer | 1:f961845c25eb | 315 | instruction |= 0b1110; |
protongamer | 1:f961845c25eb | 316 | } |
protongamer | 1:f961845c25eb | 317 | |
protongamer | 1:f961845c25eb | 318 | if(state_val == 0){ |
protongamer | 1:f961845c25eb | 319 | instruction = 0b1110; |
protongamer | 1:f961845c25eb | 320 | state_val++; |
protongamer | 1:f961845c25eb | 321 | } |
protongamer | 1:f961845c25eb | 322 | |
protongamer | 1:f961845c25eb | 323 | break; |
protongamer | 1:f961845c25eb | 324 | |
protongamer | 1:f961845c25eb | 325 | case 'f': |
protongamer | 1:f961845c25eb | 326 | pc.printf("f"); |
protongamer | 1:f961845c25eb | 327 | |
protongamer | 1:f961845c25eb | 328 | if(state_val > 0){ |
protongamer | 1:f961845c25eb | 329 | instruction = instruction << 4; |
protongamer | 1:f961845c25eb | 330 | instruction |= 0b1111; |
protongamer | 1:f961845c25eb | 331 | } |
protongamer | 1:f961845c25eb | 332 | |
protongamer | 1:f961845c25eb | 333 | if(state_val == 0){ |
protongamer | 1:f961845c25eb | 334 | instruction = 0b1111; |
protongamer | 1:f961845c25eb | 335 | state_val++; |
protongamer | 1:f961845c25eb | 336 | } |
protongamer | 1:f961845c25eb | 337 | |
protongamer | 1:f961845c25eb | 338 | break; |
protongamer | 1:f961845c25eb | 339 | |
protongamer | 1:f961845c25eb | 340 | case 'A': |
protongamer | 1:f961845c25eb | 341 | pc.printf("a"); |
protongamer | 1:f961845c25eb | 342 | |
protongamer | 1:f961845c25eb | 343 | if(state_val > 0){ |
protongamer | 1:f961845c25eb | 344 | instruction = instruction << 4; |
protongamer | 1:f961845c25eb | 345 | instruction |= 0b1010; |
protongamer | 1:f961845c25eb | 346 | } |
protongamer | 1:f961845c25eb | 347 | |
protongamer | 1:f961845c25eb | 348 | if(state_val == 0){ |
protongamer | 1:f961845c25eb | 349 | instruction = 0b1010; |
protongamer | 1:f961845c25eb | 350 | state_val++; |
protongamer | 1:f961845c25eb | 351 | } |
protongamer | 1:f961845c25eb | 352 | |
protongamer | 1:f961845c25eb | 353 | break; |
protongamer | 1:f961845c25eb | 354 | |
protongamer | 1:f961845c25eb | 355 | case 'B': |
protongamer | 1:f961845c25eb | 356 | pc.printf("b"); |
protongamer | 1:f961845c25eb | 357 | |
protongamer | 1:f961845c25eb | 358 | if(state_val > 0){ |
protongamer | 1:f961845c25eb | 359 | instruction = instruction << 4; |
protongamer | 1:f961845c25eb | 360 | instruction |= 0b1011; |
protongamer | 1:f961845c25eb | 361 | } |
protongamer | 1:f961845c25eb | 362 | |
protongamer | 1:f961845c25eb | 363 | if(state_val == 0){ |
protongamer | 1:f961845c25eb | 364 | instruction = 0b1011; |
protongamer | 1:f961845c25eb | 365 | state_val++; |
protongamer | 1:f961845c25eb | 366 | } |
protongamer | 1:f961845c25eb | 367 | |
protongamer | 1:f961845c25eb | 368 | break; |
protongamer | 1:f961845c25eb | 369 | |
protongamer | 1:f961845c25eb | 370 | case 'C': |
protongamer | 1:f961845c25eb | 371 | pc.printf("c"); |
protongamer | 1:f961845c25eb | 372 | |
protongamer | 1:f961845c25eb | 373 | if(state_val > 0){ |
protongamer | 1:f961845c25eb | 374 | instruction = instruction << 4; |
protongamer | 1:f961845c25eb | 375 | instruction |= 0b1100; |
protongamer | 1:f961845c25eb | 376 | } |
protongamer | 1:f961845c25eb | 377 | |
protongamer | 1:f961845c25eb | 378 | if(state_val == 0){ |
protongamer | 1:f961845c25eb | 379 | instruction = 0b1100; |
protongamer | 1:f961845c25eb | 380 | state_val++; |
protongamer | 1:f961845c25eb | 381 | } |
protongamer | 1:f961845c25eb | 382 | |
protongamer | 1:f961845c25eb | 383 | break; |
protongamer | 1:f961845c25eb | 384 | |
protongamer | 1:f961845c25eb | 385 | case 'D': |
protongamer | 1:f961845c25eb | 386 | pc.printf("d"); |
protongamer | 1:f961845c25eb | 387 | |
protongamer | 1:f961845c25eb | 388 | if(state_val > 0){ |
protongamer | 1:f961845c25eb | 389 | instruction = instruction << 4; |
protongamer | 1:f961845c25eb | 390 | instruction |= 0b1101; |
protongamer | 1:f961845c25eb | 391 | } |
protongamer | 1:f961845c25eb | 392 | |
protongamer | 1:f961845c25eb | 393 | if(state_val == 0){ |
protongamer | 1:f961845c25eb | 394 | instruction = 0b1101; |
protongamer | 1:f961845c25eb | 395 | state_val++; |
protongamer | 1:f961845c25eb | 396 | } |
protongamer | 1:f961845c25eb | 397 | |
protongamer | 1:f961845c25eb | 398 | break; |
protongamer | 1:f961845c25eb | 399 | |
protongamer | 1:f961845c25eb | 400 | case 'E': |
protongamer | 1:f961845c25eb | 401 | pc.printf("e"); |
protongamer | 1:f961845c25eb | 402 | |
protongamer | 1:f961845c25eb | 403 | if(state_val > 0){ |
protongamer | 1:f961845c25eb | 404 | instruction = instruction << 4; |
protongamer | 1:f961845c25eb | 405 | instruction |= 0b1110; |
protongamer | 1:f961845c25eb | 406 | } |
protongamer | 1:f961845c25eb | 407 | |
protongamer | 1:f961845c25eb | 408 | if(state_val == 0){ |
protongamer | 1:f961845c25eb | 409 | instruction = 0b1110; |
protongamer | 1:f961845c25eb | 410 | state_val++; |
protongamer | 1:f961845c25eb | 411 | } |
protongamer | 1:f961845c25eb | 412 | |
protongamer | 1:f961845c25eb | 413 | break; |
protongamer | 1:f961845c25eb | 414 | |
protongamer | 1:f961845c25eb | 415 | case 'F': |
protongamer | 1:f961845c25eb | 416 | pc.printf("f"); |
protongamer | 1:f961845c25eb | 417 | |
protongamer | 1:f961845c25eb | 418 | if(state_val > 0){ |
protongamer | 1:f961845c25eb | 419 | instruction = instruction << 4; |
protongamer | 1:f961845c25eb | 420 | instruction |= 0b1111; |
protongamer | 1:f961845c25eb | 421 | } |
protongamer | 1:f961845c25eb | 422 | |
protongamer | 1:f961845c25eb | 423 | if(state_val == 0){ |
protongamer | 1:f961845c25eb | 424 | instruction = 0b1111; |
protongamer | 1:f961845c25eb | 425 | state_val++; |
protongamer | 1:f961845c25eb | 426 | } |
protongamer | 1:f961845c25eb | 427 | |
protongamer | 1:f961845c25eb | 428 | break; |
protongamer | 1:f961845c25eb | 429 | |
protongamer | 1:f961845c25eb | 430 | case '\r': |
protongamer | 1:f961845c25eb | 431 | pc.printf("\r\n0x%x \r\n", instruction); |
protongamer | 1:f961845c25eb | 432 | wait(1.0); |
protongamer | 1:f961845c25eb | 433 | state = 0; |
protongamer | 1:f961845c25eb | 434 | if(instruction <= 255){ |
protongamer | 1:f961845c25eb | 435 | bytes = 1; |
protongamer | 1:f961845c25eb | 436 | } |
protongamer | 1:f961845c25eb | 437 | if(instruction > 255){ |
protongamer | 1:f961845c25eb | 438 | bytes = 2; |
protongamer | 1:f961845c25eb | 439 | instruction_2 = instruction; |
protongamer | 1:f961845c25eb | 440 | instruction_2 = instruction_2 >> 8; |
protongamer | 1:f961845c25eb | 441 | instruction = instruction & 0b0000000011111111; |
protongamer | 1:f961845c25eb | 442 | } |
protongamer | 1:f961845c25eb | 443 | break; |
protongamer | 1:f961845c25eb | 444 | |
protongamer | 1:f961845c25eb | 445 | |
protongamer | 1:f961845c25eb | 446 | } |
protongamer | 1:f961845c25eb | 447 | |
protongamer | 1:f961845c25eb | 448 | break; |
protongamer | 1:f961845c25eb | 449 | |
protongamer | 1:f961845c25eb | 450 | |
protongamer | 1:f961845c25eb | 451 | |
protongamer | 1:f961845c25eb | 452 | } |
protongamer | 1:f961845c25eb | 453 | |
protongamer | 1:f961845c25eb | 454 | |
protongamer | 1:f961845c25eb | 455 | |
protongamer | 1:f961845c25eb | 456 | |
protongamer | 1:f961845c25eb | 457 | //wait(0.2); |
protongamer | 1:f961845c25eb | 458 | } |
protongamer | 1:f961845c25eb | 459 | }*/ |
protongamer | 1:f961845c25eb | 460 | |
protongamer | 1:f961845c25eb | 461 | /*printf("loop()\n"); |
LabSE | 0:cea062e60f85 | 462 | if(can2.read(msg)) { |
protongamer | 1:f961845c25eb | 463 | printf("Message received: %d\n", msg.data[0]); |
protongamer | 1:f961845c25eb | 464 | led2 = !led2; |
protongamer | 1:f961845c25eb | 465 | } */ |