Dependencies:   FatFileSystem mbed GPS TextLCD

Committer:
pangsk
Date:
Mon Jul 12 10:03:53 2010 +0000
Revision:
2:e7b3b8da71ff
Parent:
1:3552a3289608
Child:
3:05bb8f0bd7a4

        

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 2:e7b3b8da71ff 27 #include "SDFileSystem.h"
pangsk 0:908be729d27c 28
pangsk 0:908be729d27c 29 GPS gps(p28, p27);
pangsk 0:908be729d27c 30 TextLCD lcd(p18, p19, p20, p17, p16, p15, p14); // rs, rw, e, d0, d1, d2, d3
pangsk 2:e7b3b8da71ff 31 SDFileSystem sd(p5, p6, p7, p13, "sd");
pangsk 0:908be729d27c 32
pangsk 0:908be729d27c 33 DigitalIn click(p21); // Joystick inputs
pangsk 0:908be729d27c 34 DigitalIn right(p22);
pangsk 0:908be729d27c 35 DigitalIn down(p23);
pangsk 0:908be729d27c 36 DigitalIn left(p24);
pangsk 0:908be729d27c 37 DigitalIn up(p25);
pangsk 0:908be729d27c 38
pangsk 0:908be729d27c 39 ecu_reader obdii(CANSPEED_500); //Create object and set CAN speed
pangsk 0:908be729d27c 40 void gps_demo(void);
pangsk 0:908be729d27c 41 void sd_demo(void);
pangsk 0:908be729d27c 42
pangsk 0:908be729d27c 43 int main() {
pangsk 0:908be729d27c 44
pangsk 0:908be729d27c 45 char buffer[20];
pangsk 0:908be729d27c 46
pangsk 2:e7b3b8da71ff 47 lcd.locate(0,0); // Set LCD cursor position
pangsk 0:908be729d27c 48 lcd.printf("CAN-Bus demo");
pangsk 0:908be729d27c 49
pangsk 0:908be729d27c 50 lcd.locate(0,1);
pangsk 0:908be729d27c 51 lcd.printf("www.skpang.co.uk");
pangsk 0:908be729d27c 52
pangsk 0:908be729d27c 53 pc.printf("\n\rCAN-bus demo...");
pangsk 0:908be729d27c 54
pangsk 0:908be729d27c 55 wait(3);
pangsk 0:908be729d27c 56 lcd.cls();
pangsk 0:908be729d27c 57 lcd.printf("Use joystick");
pangsk 0:908be729d27c 58
pangsk 0:908be729d27c 59 lcd.locate(0,1);
pangsk 0:908be729d27c 60 lcd.printf("U-CAN:D-GPS:L-SD");
pangsk 0:908be729d27c 61
pangsk 0:908be729d27c 62 while(1) // Wait until option is selected by the joystick
pangsk 0:908be729d27c 63 {
pangsk 0:908be729d27c 64
pangsk 0:908be729d27c 65 if(down == 0) gps_demo();
pangsk 0:908be729d27c 66 if(left == 0) sd_demo();
pangsk 0:908be729d27c 67
pangsk 0:908be729d27c 68 if(up == 0) break;
pangsk 0:908be729d27c 69
pangsk 0:908be729d27c 70 }
pangsk 0:908be729d27c 71 lcd.cls();
pangsk 0:908be729d27c 72
pangsk 0:908be729d27c 73 while(1) { // Main CAN loop
pangsk 0:908be729d27c 74 led2 = 1;
pangsk 0:908be729d27c 75 wait(0.1);
pangsk 0:908be729d27c 76 led2 = 0;
pangsk 0:908be729d27c 77 wait(0.1);
pangsk 0:908be729d27c 78
pangsk 0:908be729d27c 79 if(obdii.request(ENGINE_RPM,buffer) == 1) // Get engine rpm and display on LCD
pangsk 0:908be729d27c 80 {
pangsk 0:908be729d27c 81 lcd.locate(0,0);
pangsk 0:908be729d27c 82 lcd.printf(buffer);
pangsk 0:908be729d27c 83 }
pangsk 0:908be729d27c 84
pangsk 0:908be729d27c 85 if(obdii.request(ENGINE_COOLANT_TEMP,buffer) == 1)
pangsk 0:908be729d27c 86 {
pangsk 0:908be729d27c 87 lcd.locate(9,0);
pangsk 0:908be729d27c 88 lcd.printf(buffer);
pangsk 0:908be729d27c 89 }
pangsk 0:908be729d27c 90
pangsk 0:908be729d27c 91 if(obdii.request(VEHICLE_SPEED,buffer) == 1)
pangsk 0:908be729d27c 92 {
pangsk 0:908be729d27c 93 lcd.locate(0,1);
pangsk 0:908be729d27c 94 lcd.printf(buffer);
pangsk 0:908be729d27c 95 }
pangsk 0:908be729d27c 96
pangsk 0:908be729d27c 97 if(obdii.request(THROTTLE,buffer) ==1 )
pangsk 0:908be729d27c 98 {
pangsk 0:908be729d27c 99 lcd.locate(9,1);
pangsk 0:908be729d27c 100 lcd.printf(buffer);
pangsk 0:908be729d27c 101 }
pangsk 0:908be729d27c 102
pangsk 0:908be729d27c 103 }
pangsk 0:908be729d27c 104 }
pangsk 0:908be729d27c 105
pangsk 0:908be729d27c 106 void gps_demo(void)
pangsk 0:908be729d27c 107 {
pangsk 0:908be729d27c 108 lcd.cls();
pangsk 0:908be729d27c 109 lcd.printf("GPS demo");
pangsk 0:908be729d27c 110 lcd.locate(0,1);
pangsk 0:908be729d27c 111 lcd.printf("Waiting for lock");
pangsk 0:908be729d27c 112
pangsk 0:908be729d27c 113 wait(3);
pangsk 0:908be729d27c 114 lcd.cls();
pangsk 2:e7b3b8da71ff 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 2:e7b3b8da71ff 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 void sd_demo(void)
pangsk 0:908be729d27c 135 {
pangsk 2:e7b3b8da71ff 136 lcd.cls();
pangsk 2:e7b3b8da71ff 137 lcd.printf("SD demo");
pangsk 2:e7b3b8da71ff 138 wait(2);
pangsk 0:908be729d27c 139 lcd.cls();
pangsk 2:e7b3b8da71ff 140
pangsk 2:e7b3b8da71ff 141 FILE *fp = fopen("/sd/sdtest2.txt", "w");
pangsk 2:e7b3b8da71ff 142 if(fp == NULL) {
pangsk 2:e7b3b8da71ff 143 lcd.cls();
pangsk 2:e7b3b8da71ff 144 lcd.printf("Could not open file for write\n");
pangsk 2:e7b3b8da71ff 145 }
pangsk 2:e7b3b8da71ff 146 fprintf(fp, "Hello fun SD Card World! testing 1234");
pangsk 2:e7b3b8da71ff 147 fclose(fp);
pangsk 2:e7b3b8da71ff 148 lcd.locate(0,1);
pangsk 2:e7b3b8da71ff 149 lcd.printf("Writtern to SD card");
pangsk 2:e7b3b8da71ff 150
pangsk 0:908be729d27c 151 while(1)
pangsk 0:908be729d27c 152 {
pangsk 2:e7b3b8da71ff 153 led2 = 1;
pangsk 2:e7b3b8da71ff 154 wait(0.1);
pangsk 2:e7b3b8da71ff 155 led2 = 0;
pangsk 2:e7b3b8da71ff 156 wait(0.1);
pangsk 2:e7b3b8da71ff 157
pangsk 0:908be729d27c 158 }
pangsk 0:908be729d27c 159
pangsk 0:908be729d27c 160 }