XBEE Project for LPC1768 - program number 2 of 2.

Dependencies:   C12832 LM75B XBee mbed

Committer:
darrenf87
Date:
Wed Jan 11 20:20:33 2017 +0000
Revision:
0:07d7e2c4db5f
XBEE project for LPC1768. Project program number 2 of 2.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
darrenf87 0:07d7e2c4db5f 1 #include "mbed.h" /*Include standard mbed library*/
darrenf87 0:07d7e2c4db5f 2 #include "XBee.h" /*Include library for XBee transmitter/reciever*/
darrenf87 0:07d7e2c4db5f 3 #include "LM75B.h" /*Include library for temperature sensor*/
darrenf87 0:07d7e2c4db5f 4 #include "C12832A1Z.h" /*Include library for LCD display*/
darrenf87 0:07d7e2c4db5f 5
darrenf87 0:07d7e2c4db5f 6 Serial xbee1(p9,p10); /*Declare XBee transmit/receive as pins 9 and 10*/
darrenf87 0:07d7e2c4db5f 7 DigitalOut rst1(p30); /*Declare pin 29 as the reset pin for the XBee*/
darrenf87 0:07d7e2c4db5f 8 LM75B temp(p28,p27); /*Declare temperature sensor transmit/recieve as pins 27 and 28*/
darrenf87 0:07d7e2c4db5f 9 DigitalOut red(p23); /*Declare pin 23 as the red LED*/
darrenf87 0:07d7e2c4db5f 10 DigitalOut green(p24); /*Declare pin 24 as the green LED*/
darrenf87 0:07d7e2c4db5f 11 DigitalOut blue(p25); /*Declare pin 25 as the blue LED*/
darrenf87 0:07d7e2c4db5f 12 DigitalOut relay(p8); /*Declare pin 8 as the output to an external relay*/
darrenf87 0:07d7e2c4db5f 13
darrenf87 0:07d7e2c4db5f 14 C12832A1Z lcd(p5, p7, p6, p8, p11); /*Set pins for LCD display (MOSI, SCK, Reset, A0 and nCS)*/
darrenf87 0:07d7e2c4db5f 15
darrenf87 0:07d7e2c4db5f 16 int main() { /*Start of main function*/
darrenf87 0:07d7e2c4db5f 17 rst1 = 0; /*Set XBee reset pin to 0*/
darrenf87 0:07d7e2c4db5f 18 wait_ms(1); /*Wait 1 millisecond*/
darrenf87 0:07d7e2c4db5f 19 rst1 = 1; /*Set XBee reset pin to 1*/
darrenf87 0:07d7e2c4db5f 20 wait_ms(1); /*Wait 1 millisecond*/
darrenf87 0:07d7e2c4db5f 21
darrenf87 0:07d7e2c4db5f 22 lcd.locate(20,0); /*Locate the area to print in on the LCD*/
darrenf87 0:07d7e2c4db5f 23 lcd.printf("Battery Temperature"); /*Output to LCD screen at position 20,0*/
darrenf87 0:07d7e2c4db5f 24 lcd.locate(18,10); /*Locate the area to print in on the LCD*/
darrenf87 0:07d7e2c4db5f 25 lcd.printf("Monitoring - DMOS B"); /*Output to LCD screen at position 18,10*/
darrenf87 0:07d7e2c4db5f 26 lcd.locate(15,20); /*Locate the area to print in on the LCD*/
darrenf87 0:07d7e2c4db5f 27 lcd.printf("(C) D.Fitzgerald - 2016"); /*Output to the LCD screen at position 15,20*/
darrenf87 0:07d7e2c4db5f 28 wait(5); /*Wait 5 seconds (displays the above message for 5 seconds*/
darrenf87 0:07d7e2c4db5f 29 lcd.cls(); /*Clear all messages from LCD screen*/
darrenf87 0:07d7e2c4db5f 30
darrenf87 0:07d7e2c4db5f 31 int a; /*Declare 'a' as an integer value*/
darrenf87 0:07d7e2c4db5f 32 int b; /*Declare 'b' as an integer value*/
darrenf87 0:07d7e2c4db5f 33 int c; /*Declare 'c' as an integer value*/
darrenf87 0:07d7e2c4db5f 34 int d; /*Declare 'd' as an integer value*/
darrenf87 0:07d7e2c4db5f 35
darrenf87 0:07d7e2c4db5f 36 lcd.locate(6,0); /*Locate the area to print on the LCD*/
darrenf87 0:07d7e2c4db5f 37 lcd.printf("DMOS A Batteries = "); /*Output to LCD screen at position 6,0*/
darrenf87 0:07d7e2c4db5f 38 lcd.locate(6,16); /*Locate the area to print on the LCD*/
darrenf87 0:07d7e2c4db5f 39 lcd.printf("DMOS B Batteries = "); /*Output to LCD screen at position 6,16*/
darrenf87 0:07d7e2c4db5f 40
darrenf87 0:07d7e2c4db5f 41 d=1; /*Set value of 'd' to be '1' permanently*/
darrenf87 0:07d7e2c4db5f 42
darrenf87 0:07d7e2c4db5f 43 while (d>0) { /*Infinite while loop whilst d is greater than 0, which is always*/
darrenf87 0:07d7e2c4db5f 44 /*The three LED's must be 'logically notted' in order to force them off before use*/
darrenf87 0:07d7e2c4db5f 45 green=!green; /*Logically not the green LED*/
darrenf87 0:07d7e2c4db5f 46 red=!red; /*Logically not the red LED*/
darrenf87 0:07d7e2c4db5f 47 blue=!blue; /*Logically not the blue LED (not used but still needs to be turned off to prevent mixing with other colours*/
darrenf87 0:07d7e2c4db5f 48 b = temp.read(); /*Read the temperature from the LM75 temperature sensor*/
darrenf87 0:07d7e2c4db5f 49 /*XBee devices are capable of duplex communications, which is utilised in the next two steps*/
darrenf87 0:07d7e2c4db5f 50 xbee1.putc(b); /*Put the read temperature into the XBee output port*/
darrenf87 0:07d7e2c4db5f 51 a = xbee1.getc(); /*Retrieve the temperature that is being sent from the other ARM MBED device from the XBee*/
darrenf87 0:07d7e2c4db5f 52 lcd.locate(100,0); /*Locate the area to print the temperature to on the LCD screen*/
darrenf87 0:07d7e2c4db5f 53 lcd.printf("%d C\n",a); /*Print the temperature from the other ARM MBED device at location 100,0*/
darrenf87 0:07d7e2c4db5f 54 lcd.locate(100,16); /*Locate the area to print the temperature to on the LCD screen*/
darrenf87 0:07d7e2c4db5f 55 lcd.printf("%d C\n",b); /*Print the temperature from the local ARM MBED device at location 100,16*/
darrenf87 0:07d7e2c4db5f 56 wait_us(10); /*Wait 10 microseconds*/
darrenf87 0:07d7e2c4db5f 57 c = abs(a-b); /*Subtract the local temperature from the remote temperature and create this as an absolute (positive) only value*/
darrenf87 0:07d7e2c4db5f 58 if(c<3){ /*Start of If loop for if the temperature difference calculated in the previous step is equal to or less than 3 degrees*/
darrenf87 0:07d7e2c4db5f 59 /*The LED's have to be forced off to prevent the RGB LED mixing it's colours*/
darrenf87 0:07d7e2c4db5f 60 green=1; /*Turn the green LED on*/
darrenf87 0:07d7e2c4db5f 61 red=0; /*Force the red LED off*/
darrenf87 0:07d7e2c4db5f 62 blue=0; /*Force the blue LED off*/
darrenf87 0:07d7e2c4db5f 63 } /*End of If loop*/
darrenf87 0:07d7e2c4db5f 64 else{ /*If the temperature difference calculated as 'c' is anything other than the parameter set in the previous if loop, do the following...*/
darrenf87 0:07d7e2c4db5f 65 red=1; /*Turn the red LED on*/
darrenf87 0:07d7e2c4db5f 66 green=0; /*Force the green LED off*/
darrenf87 0:07d7e2c4db5f 67 blue=0; /*Force the blue LED off*/
darrenf87 0:07d7e2c4db5f 68 relay=1; /*Apply a logic value of '1' to pin 8, to activate an external relay in order to turn off battery charging supply*/
darrenf87 0:07d7e2c4db5f 69 } /*End of If loop*/
darrenf87 0:07d7e2c4db5f 70 } /*End of infinite while loop*/
darrenf87 0:07d7e2c4db5f 71 } /*End of main function*/