Dependencies:   FatFileSystem mbed GPS TextLCD

Committer:
pangsk
Date:
Thu Jul 08 21:37:12 2010 +0000
Revision:
1:3552a3289608
Parent:
0:908be729d27c
Child:
2:e7b3b8da71ff

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pangsk 0:908be729d27c 1 /*
pangsk 0:908be729d27c 2
pangsk 0:908be729d27c 3 mbed Can-Bus demo
pangsk 0:908be729d27c 4
pangsk 0:908be729d27c 5 This program is to demonstrate the CAN-bus capability of the mbed module.
pangsk 0:908be729d27c 6
pangsk 1:3552a3289608 7 http://www.skpang.co.uk/catalog/product_info.php?products_id=741
pangsk 0:908be729d27c 8
pangsk 0:908be729d27c 9 v1.0 July 2010
pangsk 0:908be729d27c 10
pangsk 0:908be729d27c 11 ********************************************************************************
pangsk 0:908be729d27c 12
pangsk 0:908be729d27c 13 WARNING: Use at your own risk, sadly this software comes with no guarantees.
pangsk 0:908be729d27c 14 This software is provided 'free' and in good faith, but the author does not
pangsk 0:908be729d27c 15 accept liability for any damage arising from its use.
pangsk 0:908be729d27c 16
pangsk 0:908be729d27c 17 ********************************************************************************
pangsk 0:908be729d27c 18
pangsk 0:908be729d27c 19
pangsk 0:908be729d27c 20 */
pangsk 0:908be729d27c 21
pangsk 0:908be729d27c 22 #include "mbed.h"
pangsk 0:908be729d27c 23 #include "ecu_reader.h"
pangsk 0:908be729d27c 24 #include "globals.h"
pangsk 0:908be729d27c 25 #include "TextLCD.h"
pangsk 0:908be729d27c 26 #include "GPS.h"
pangsk 0:908be729d27c 27
pangsk 0:908be729d27c 28 GPS gps(p28, p27);
pangsk 0:908be729d27c 29 TextLCD lcd(p18, p19, p20, p17, p16, p15, p14); // rs, rw, e, d0, d1, d2, d3
pangsk 0:908be729d27c 30
pangsk 0:908be729d27c 31 DigitalIn click(p21); // Joystick inputs
pangsk 0:908be729d27c 32 DigitalIn right(p22);
pangsk 0:908be729d27c 33 DigitalIn down(p23);
pangsk 0:908be729d27c 34 DigitalIn left(p24);
pangsk 0:908be729d27c 35 DigitalIn up(p25);
pangsk 0:908be729d27c 36
pangsk 0:908be729d27c 37 ecu_reader obdii(CANSPEED_500); //Create object and set CAN speed
pangsk 0:908be729d27c 38 void gps_demo(void);
pangsk 0:908be729d27c 39 void sd_demo(void);
pangsk 0:908be729d27c 40
pangsk 0:908be729d27c 41 int main() {
pangsk 0:908be729d27c 42
pangsk 0:908be729d27c 43 char buffer[20];
pangsk 0:908be729d27c 44
pangsk 0:908be729d27c 45 lcd.locate(0,0);
pangsk 0:908be729d27c 46 lcd.printf("CAN-Bus demo");
pangsk 0:908be729d27c 47
pangsk 0:908be729d27c 48 lcd.locate(0,1);
pangsk 0:908be729d27c 49 lcd.printf("www.skpang.co.uk");
pangsk 0:908be729d27c 50
pangsk 0:908be729d27c 51 pc.printf("\n\rCAN-bus demo...");
pangsk 0:908be729d27c 52
pangsk 0:908be729d27c 53 wait(3);
pangsk 0:908be729d27c 54 lcd.cls();
pangsk 0:908be729d27c 55 lcd.printf("Use joystick");
pangsk 0:908be729d27c 56
pangsk 0:908be729d27c 57 lcd.locate(0,1);
pangsk 0:908be729d27c 58 lcd.printf("U-CAN:D-GPS:L-SD");
pangsk 0:908be729d27c 59
pangsk 0:908be729d27c 60 while(1) // Wait until option is selected by the joystick
pangsk 0:908be729d27c 61 {
pangsk 0:908be729d27c 62
pangsk 0:908be729d27c 63 if(down == 0) gps_demo();
pangsk 0:908be729d27c 64 if(left == 0) sd_demo();
pangsk 0:908be729d27c 65
pangsk 0:908be729d27c 66 if(up == 0) break;
pangsk 0:908be729d27c 67
pangsk 0:908be729d27c 68 }
pangsk 0:908be729d27c 69 lcd.cls();
pangsk 0:908be729d27c 70
pangsk 0:908be729d27c 71 while(1) { // Main CAN loop
pangsk 0:908be729d27c 72 led2 = 1;
pangsk 0:908be729d27c 73 wait(0.1);
pangsk 0:908be729d27c 74 led2 = 0;
pangsk 0:908be729d27c 75 wait(0.1);
pangsk 0:908be729d27c 76
pangsk 0:908be729d27c 77 if(obdii.request(ENGINE_RPM,buffer) == 1) // Get engine rpm and display on LCD
pangsk 0:908be729d27c 78 {
pangsk 0:908be729d27c 79 lcd.locate(0,0);
pangsk 0:908be729d27c 80 lcd.printf(buffer);
pangsk 0:908be729d27c 81 }
pangsk 0:908be729d27c 82
pangsk 0:908be729d27c 83 if(obdii.request(ENGINE_COOLANT_TEMP,buffer) == 1)
pangsk 0:908be729d27c 84 {
pangsk 0:908be729d27c 85 lcd.locate(9,0);
pangsk 0:908be729d27c 86 lcd.printf(buffer);
pangsk 0:908be729d27c 87 }
pangsk 0:908be729d27c 88
pangsk 0:908be729d27c 89 if(obdii.request(VEHICLE_SPEED,buffer) == 1)
pangsk 0:908be729d27c 90 {
pangsk 0:908be729d27c 91 lcd.locate(0,1);
pangsk 0:908be729d27c 92 lcd.printf(buffer);
pangsk 0:908be729d27c 93 }
pangsk 0:908be729d27c 94
pangsk 0:908be729d27c 95 if(obdii.request(THROTTLE,buffer) ==1 )
pangsk 0:908be729d27c 96 {
pangsk 0:908be729d27c 97 lcd.locate(9,1);
pangsk 0:908be729d27c 98 lcd.printf(buffer);
pangsk 0:908be729d27c 99 }
pangsk 0:908be729d27c 100
pangsk 0:908be729d27c 101 }
pangsk 0:908be729d27c 102 }
pangsk 0:908be729d27c 103
pangsk 0:908be729d27c 104 void gps_demo(void)
pangsk 0:908be729d27c 105 {
pangsk 0:908be729d27c 106 pc.printf("\rGPS demo");
pangsk 0:908be729d27c 107 lcd.cls();
pangsk 0:908be729d27c 108 lcd.printf("GPS demo");
pangsk 0:908be729d27c 109 lcd.locate(0,1);
pangsk 0:908be729d27c 110 lcd.printf("Waiting for lock");
pangsk 0:908be729d27c 111
pangsk 0:908be729d27c 112 wait(3);
pangsk 0:908be729d27c 113 lcd.cls();
pangsk 0:908be729d27c 114
pangsk 0:908be729d27c 115
pangsk 0:908be729d27c 116 while(1)
pangsk 0:908be729d27c 117 {
pangsk 0:908be729d27c 118 if(gps.sample()) {
pangsk 0:908be729d27c 119 lcd.cls();
pangsk 0:908be729d27c 120 lcd.printf("Long:%f", gps.longitude);
pangsk 0:908be729d27c 121 lcd.locate(0,1);
pangsk 0:908be729d27c 122 lcd.printf("Lat:%f", gps.latitude);
pangsk 0:908be729d27c 123 pc.printf("I'm at %f, %f\n", gps.longitude, gps.latitude);
pangsk 0:908be729d27c 124 } else {
pangsk 0:908be729d27c 125 pc.printf("Oh Dear! No lock :(\n");
pangsk 0:908be729d27c 126 lcd.cls();
pangsk 0:908be729d27c 127 lcd.printf("Waiting for lock");
pangsk 0:908be729d27c 128
pangsk 0:908be729d27c 129
pangsk 0:908be729d27c 130
pangsk 0:908be729d27c 131 }
pangsk 0:908be729d27c 132
pangsk 0:908be729d27c 133
pangsk 0:908be729d27c 134 }
pangsk 0:908be729d27c 135
pangsk 0:908be729d27c 136 }
pangsk 0:908be729d27c 137
pangsk 0:908be729d27c 138 void sd_demo(void)
pangsk 0:908be729d27c 139 {
pangsk 0:908be729d27c 140 pc.printf("\rSD demo");
pangsk 0:908be729d27c 141
pangsk 0:908be729d27c 142 lcd.cls();
pangsk 0:908be729d27c 143 lcd.printf("Use joystick");
pangsk 0:908be729d27c 144 wait(3);
pangsk 0:908be729d27c 145 while(1)
pangsk 0:908be729d27c 146 {
pangsk 0:908be729d27c 147
pangsk 0:908be729d27c 148
pangsk 0:908be729d27c 149
pangsk 0:908be729d27c 150 }
pangsk 0:908be729d27c 151
pangsk 0:908be729d27c 152 }