![](/media/cache/profiles/25a76ba89c58a499eadfd4cb8ecf8af5.jpg.50x50_q85.jpg)
Bus comms (external protocol) with xbee code for coordinator
Dependencies: C12832_lcd mbed xbee_lib
main.cpp@0:bf3639924624, 2015-02-15 (annotated)
- Committer:
- dannellyz
- Date:
- Sun Feb 15 06:26:25 2015 +0000
- Revision:
- 0:bf3639924624
Round 1 Bus comms (external protocol) with xbee
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dannellyz | 0:bf3639924624 | 1 | #include "mbed.h" |
dannellyz | 0:bf3639924624 | 2 | #include "xbee.h" // Include for xbee code |
dannellyz | 0:bf3639924624 | 3 | #include "C12832_lcd.h" // Include for LCD code |
dannellyz | 0:bf3639924624 | 4 | |
dannellyz | 0:bf3639924624 | 5 | xbee xbee1(p9,p10,p30); //Initalise xbee_lib varName(rx,tx,reset) |
dannellyz | 0:bf3639924624 | 6 | DigitalOut rst1(p30); |
dannellyz | 0:bf3639924624 | 7 | Serial pc(USBTX, USBRX); //Initalise PC serial comms |
dannellyz | 0:bf3639924624 | 8 | C12832_LCD lcd; //Initialize LCD Screen |
dannellyz | 0:bf3639924624 | 9 | |
dannellyz | 0:bf3639924624 | 10 | //Initialize the Bus LEDs on appBoard |
dannellyz | 0:bf3639924624 | 11 | BusOut leds(LED1,LED2,LED3,LED4); |
dannellyz | 0:bf3639924624 | 12 | int main() |
dannellyz | 0:bf3639924624 | 13 | { |
dannellyz | 0:bf3639924624 | 14 | // reset the xbees (at least 200ns) |
dannellyz | 0:bf3639924624 | 15 | rst1 = 0; |
dannellyz | 0:bf3639924624 | 16 | wait_ms(1); |
dannellyz | 0:bf3639924624 | 17 | rst1 = 1; |
dannellyz | 0:bf3639924624 | 18 | wait_ms(1); |
dannellyz | 0:bf3639924624 | 19 | //Setup LCD screen |
dannellyz | 0:bf3639924624 | 20 | lcd.cls(); |
dannellyz | 0:bf3639924624 | 21 | lcd.locate(0,1); |
dannellyz | 0:bf3639924624 | 22 | |
dannellyz | 0:bf3639924624 | 23 | char readData[1]; //Buffer to read value of bus |
dannellyz | 0:bf3639924624 | 24 | |
dannellyz | 0:bf3639924624 | 25 | while(1) { |
dannellyz | 0:bf3639924624 | 26 | xbee1.RecieveData(readData,0); //Read data from the XBee |
dannellyz | 0:bf3639924624 | 27 | |
dannellyz | 0:bf3639924624 | 28 | //Local echo in terminal |
dannellyz | 0:bf3639924624 | 29 | pc.printf("Value of Bus%d \n",readData); |
dannellyz | 0:bf3639924624 | 30 | |
dannellyz | 0:bf3639924624 | 31 | //and on LCD |
dannellyz | 0:bf3639924624 | 32 | lcd.printf("%c\n",readData[0]); |
dannellyz | 0:bf3639924624 | 33 | wait(0.1); |
dannellyz | 0:bf3639924624 | 34 | |
dannellyz | 0:bf3639924624 | 35 | //Switch to change LEDs based on Bus value |
dannellyz | 0:bf3639924624 | 36 | switch(readData[0]){ |
dannellyz | 0:bf3639924624 | 37 | case '0': |
dannellyz | 0:bf3639924624 | 38 | leds = 0; |
dannellyz | 0:bf3639924624 | 39 | break; //optional |
dannellyz | 0:bf3639924624 | 40 | case '1': |
dannellyz | 0:bf3639924624 | 41 | leds = 1; |
dannellyz | 0:bf3639924624 | 42 | break; //optional |
dannellyz | 0:bf3639924624 | 43 | case '2': |
dannellyz | 0:bf3639924624 | 44 | leds = 2; |
dannellyz | 0:bf3639924624 | 45 | break; //optional |
dannellyz | 0:bf3639924624 | 46 | case '4': |
dannellyz | 0:bf3639924624 | 47 | leds = 4; |
dannellyz | 0:bf3639924624 | 48 | break; //optional |
dannellyz | 0:bf3639924624 | 49 | case '8': |
dannellyz | 0:bf3639924624 | 50 | leds = 8; |
dannellyz | 0:bf3639924624 | 51 | break; //optional |
dannellyz | 0:bf3639924624 | 52 | case '9': |
dannellyz | 0:bf3639924624 | 53 | leds = 0xFFFF; |
dannellyz | 0:bf3639924624 | 54 | break; //optional |
dannellyz | 0:bf3639924624 | 55 | |
dannellyz | 0:bf3639924624 | 56 | } |
dannellyz | 0:bf3639924624 | 57 | |
dannellyz | 0:bf3639924624 | 58 | } |
dannellyz | 0:bf3639924624 | 59 | } |