main
Dependencies: TextLCD mbed PID
usart.cpp@5:6604ec9044a0, 2014-03-17 (annotated)
- Committer:
- com3
- Date:
- Mon Mar 17 06:37:37 2014 +0000
- Revision:
- 5:6604ec9044a0
- Parent:
- 4:536cd493a337
main
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
com3 | 0:e6d14fec4954 | 1 | #include "mbed.h" |
com3 | 0:e6d14fec4954 | 2 | #include "common.h" |
com3 | 0:e6d14fec4954 | 3 | |
com3 | 0:e6d14fec4954 | 4 | #define KEYCODE 0xAA |
com3 | 1:fb4277ce4d93 | 5 | #define TX_CHECKCODE (tx_data[1]^tx_data[2]^tx_data[3]^tx_data[4]^tx_data[5]^tx_data[6]^tx_data[7]^tx_data[8]) |
com3 | 1:fb4277ce4d93 | 6 | #define RX_CHECKCODE (rx_data[1]^rx_data[2]^rx_data[3]^rx_data[4]^rx_data[5]^rx_data[6]^rx_data[7]^rx_data[8]) |
com3 | 4:536cd493a337 | 7 | #define DATA_NUM 11 |
com3 | 0:e6d14fec4954 | 8 | #define CHECK (DATA_NUM - 1) |
com3 | 4:536cd493a337 | 9 | #define ALL_IR 11 |
com3 | 0:e6d14fec4954 | 10 | |
com3 | 0:e6d14fec4954 | 11 | |
com3 | 4:536cd493a337 | 12 | extern Serial xbee; |
com3 | 0:e6d14fec4954 | 13 | extern Serial sensor; |
com3 | 0:e6d14fec4954 | 14 | extern Serial pc; |
com3 | 5:6604ec9044a0 | 15 | extern DigitalOut myled[4]; |
com3 | 0:e6d14fec4954 | 16 | |
com3 | 3:440e774cc24b | 17 | extern uint8_t value_ir, ir_num, ir_dis, ball_on; |
com3 | 0:e6d14fec4954 | 18 | extern uint8_t ping[4]; |
com3 | 0:e6d14fec4954 | 19 | extern uint8_t line[4]; |
com3 | 0:e6d14fec4954 | 20 | extern uint8_t ir_max, ir_num; |
com3 | 0:e6d14fec4954 | 21 | extern int compass; |
com3 | 0:e6d14fec4954 | 22 | |
com3 | 5:6604ec9044a0 | 23 | int count = 0; |
com3 | 4:536cd493a337 | 24 | void xbee_tx(){ |
com3 | 5:6604ec9044a0 | 25 | xbee.putc(1); |
com3 | 4:536cd493a337 | 26 | } |
com3 | 4:536cd493a337 | 27 | |
com3 | 4:536cd493a337 | 28 | void xbee_rx(){ |
com3 | 5:6604ec9044a0 | 29 | if(xbee.readable()){ |
com3 | 5:6604ec9044a0 | 30 | count = xbee.getc(); |
com3 | 5:6604ec9044a0 | 31 | } else { |
com3 | 5:6604ec9044a0 | 32 | count = 0; |
com3 | 5:6604ec9044a0 | 33 | } |
com3 | 5:6604ec9044a0 | 34 | //pc.printf("%d\n", count); |
com3 | 4:536cd493a337 | 35 | } |
com3 | 4:536cd493a337 | 36 | |
com3 | 0:e6d14fec4954 | 37 | void micon_rx(){ |
com3 | 0:e6d14fec4954 | 38 | |
com3 | 0:e6d14fec4954 | 39 | static uint8_t rx; |
com3 | 0:e6d14fec4954 | 40 | static int rx_data[DATA_NUM]; |
com3 | 0:e6d14fec4954 | 41 | |
com3 | 0:e6d14fec4954 | 42 | rx_data[rx] = sensor.getc(); |
com3 | 0:e6d14fec4954 | 43 | |
com3 | 0:e6d14fec4954 | 44 | if(rx_data[0] == KEYCODE){ |
com3 | 0:e6d14fec4954 | 45 | rx++; |
com3 | 0:e6d14fec4954 | 46 | } |
com3 | 0:e6d14fec4954 | 47 | |
com3 | 0:e6d14fec4954 | 48 | if(rx >= DATA_NUM){ |
com3 | 0:e6d14fec4954 | 49 | if(rx_data[CHECK] == RX_CHECKCODE){ |
com3 | 1:fb4277ce4d93 | 50 | value_ir = rx_data[1]; |
com3 | 1:fb4277ce4d93 | 51 | ir_num = rx_data[2]; |
com3 | 1:fb4277ce4d93 | 52 | ping[FRONT] = rx_data[3]; |
com3 | 1:fb4277ce4d93 | 53 | ping[LEFT] = rx_data[4]; |
com3 | 1:fb4277ce4d93 | 54 | ping[BACK] = rx_data[5]; |
com3 | 1:fb4277ce4d93 | 55 | ping[RIGHT] = rx_data[6]; |
com3 | 1:fb4277ce4d93 | 56 | compass = rx_data[7] + rx_data[8]; |
com3 | 3:440e774cc24b | 57 | ir_dis = rx_data[9]; |
com3 | 4:536cd493a337 | 58 | //ball_on = rx_data[10]; |
com3 | 1:fb4277ce4d93 | 59 | /* line[FRONT] = rx_data[7]; |
com3 | 1:fb4277ce4d93 | 60 | line[LEFT] = rx_data[8]; |
com3 | 1:fb4277ce4d93 | 61 | line[BACK] = rx_data[9]; |
com3 | 1:fb4277ce4d93 | 62 | line[RIGHT] = rx_data[10]; |
com3 | 1:fb4277ce4d93 | 63 | */ |
com3 | 1:fb4277ce4d93 | 64 | //pc.printf("%d %d\n", rx_data[1], rx_data[2]); |
com3 | 1:fb4277ce4d93 | 65 | //pc.printf("%d %d %d %d\n", rx_data[3], rx_data[4], rx_data[5], rx_data[6]); |
com3 | 1:fb4277ce4d93 | 66 | //pc.printf("%d %d %d %d\n", rx_data[7], rx_data[8], rx_data[9], rx_data[10]); |
com3 | 1:fb4277ce4d93 | 67 | //pc.printf("%d %d %d\n", rx_data[7], rx_data[8], compass); |
com3 | 4:536cd493a337 | 68 | //pc.printf("%d\n", rx_data[7]); |
com3 | 3:440e774cc24b | 69 | //pc.printf("%d\t%d\t%d\t%d\n", ping[FRONT], ping[LEFT], ping[BACK], ping[RIGHT]); |
com3 | 3:440e774cc24b | 70 | //pc.printf("%d %d %d\n", ping[LEFT], ping[RIGHT], ping[LEFT] + ping[RIGHT]); |
com3 | 3:440e774cc24b | 71 | //pc.printf("%d\t%d\t%d\t%d\n", ir_dis, ball_on, value_ir, ir_num); |
com3 | 1:fb4277ce4d93 | 72 | } |
com3 | 0:e6d14fec4954 | 73 | rx = 0; |
com3 | 0:e6d14fec4954 | 74 | } |
com3 | 0:e6d14fec4954 | 75 | //pc.printf("%d\n", rx_data[rx]); |
com3 | 0:e6d14fec4954 | 76 | } |
com3 | 0:e6d14fec4954 | 77 | |
com3 | 1:fb4277ce4d93 | 78 | /* |
com3 | 0:e6d14fec4954 | 79 | void micon_tx(){ |
com3 | 0:e6d14fec4954 | 80 | |
com3 | 0:e6d14fec4954 | 81 | static uint8_t tx; |
com3 | 0:e6d14fec4954 | 82 | static uint8_t tx_data[DATA_NUM]; |
com3 | 0:e6d14fec4954 | 83 | |
com3 | 0:e6d14fec4954 | 84 | if(tx >= DATA_NUM){ |
com3 | 0:e6d14fec4954 | 85 | tx_data[0] = KEYCODE; |
com3 | 0:e6d14fec4954 | 86 | tx_data[1] = KEYCODE; |
com3 | 0:e6d14fec4954 | 87 | tx_data[2] = KEYCODE; |
com3 | 0:e6d14fec4954 | 88 | tx_data[3] = KEYCODE; |
com3 | 0:e6d14fec4954 | 89 | tx_data[4] = KEYCODE; |
com3 | 0:e6d14fec4954 | 90 | tx_data[5] = KEYCODE; |
com3 | 0:e6d14fec4954 | 91 | tx_data[6] = KEYCODE; |
com3 | 0:e6d14fec4954 | 92 | tx_data[7] = KEYCODE; |
com3 | 0:e6d14fec4954 | 93 | tx_data[8] = KEYCODE; |
com3 | 0:e6d14fec4954 | 94 | tx_data[9] = KEYCODE; |
com3 | 0:e6d14fec4954 | 95 | tx_data[10] = KEYCODE; |
com3 | 0:e6d14fec4954 | 96 | tx_data[11] = TX_CHECKCODE; |
com3 | 0:e6d14fec4954 | 97 | |
com3 | 0:e6d14fec4954 | 98 | tx = 0; |
com3 | 0:e6d14fec4954 | 99 | } |
com3 | 0:e6d14fec4954 | 100 | |
com3 | 0:e6d14fec4954 | 101 | sensor.putc(tx_data[tx]); |
com3 | 0:e6d14fec4954 | 102 | tx++; |
com3 | 1:fb4277ce4d93 | 103 | } |
com3 | 1:fb4277ce4d93 | 104 | */ |