![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
chad
Dependencies: MCP23017 WattBob_TextLCD mbed-rtos mbed
main.cpp@6:c538f317f426, 2017-03-07 (annotated)
- Committer:
- f_legge
- Date:
- Tue Mar 07 16:18:26 2017 +0000
- Revision:
- 6:c538f317f426
- Parent:
- 5:e1ade53bce83
- Child:
- 7:71a923f423f4
Added lcd printf to error code task
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
f_legge | 4:70553c83c65a | 1 | // Paramater Allocation |
f_legge | 4:70553c83c65a | 2 | // Paramater: 17 |
f_legge | 4:70553c83c65a | 3 | // Log Option: 1 (uSD) |
f_legge | 4:70553c83c65a | 4 | // Watchdog Pulse Length: 6ms |
f_legge | 4:70553c83c65a | 5 | // Watchdog Repetion Rate: 0.5 |
f_legge | 4:70553c83c65a | 6 | // Error Display: 1 (LCD) |
f_legge | 4:70553c83c65a | 7 | // Execution time display: Task5 (LDC display) |
f_legge | 4:70553c83c65a | 8 | |
f_legge | 4:70553c83c65a | 9 | |
f_legge | 4:70553c83c65a | 10 | |
f_legge | 0:10e3e2697134 | 11 | #include "mbed.h" |
f_legge | 4:70553c83c65a | 12 | #include "MCP23017.h" |
f_legge | 4:70553c83c65a | 13 | #include "WattBob_TextLCD.h" |
f_legge | 4:70553c83c65a | 14 | #include "SDFileSystem" |
f_legge | 4:70553c83c65a | 15 | |
f_legge | 4:70553c83c65a | 16 | #define BACK_LIGHT_ON(INTERFACE) INTERFACE->write_bit(1,BL_BIT) |
f_legge | 4:70553c83c65a | 17 | #define BACK_LIGHT_OFF(INTERFACE) INTERFACE->write_bit(0,BL_BIT) |
f_legge | 0:10e3e2697134 | 18 | |
f_legge | 4:70553c83c65a | 19 | // Pointers to LCD Screen |
f_legge | 4:70553c83c65a | 20 | MCP23017 *par_port; // pointer to 16-bit parallel I/O chip |
f_legge | 4:70553c83c65a | 21 | WattBob_TextLCD *lcd; // pointer to 2*16 character LCD object |
f_legge | 4:70553c83c65a | 22 | |
f_legge | 4:70553c83c65a | 23 | // Digital I/O p11 to p20 |
f_legge | 4:70553c83c65a | 24 | DigitalIn FqIn(p11); // Digital frequency in for measurement |
f_legge | 4:70553c83c65a | 25 | DigitalIn DSIn(p12); // Digital switch input |
f_legge | 4:70553c83c65a | 26 | DigitalOut WD_pulse(p14); // Watchdog Pulse |
f_legge | 4:70553c83c65a | 27 | SDFileSystem uSD(p5, p6, p7, p8, "uSD"); //uSD pinout |
f_legge | 4:70553c83c65a | 28 | |
f_legge | 4:70553c83c65a | 29 | // Analogue I/O p15 to p20 |
f_legge | 4:70553c83c65a | 30 | AnalogIn A1_in(p15); // Analogue input to be filtered |
f_legge | 4:70553c83c65a | 31 | AnalogIn A2_in(p16); // Analogue input to be filtered |
f_legge | 4:70553c83c65a | 32 | |
f_legge | 4:70553c83c65a | 33 | // Timer objects |
f_legge | 4:70553c83c65a | 34 | Timer timer; // Frequency Timer |
f_legge | 4:70553c83c65a | 35 | Timer tick; // Clock timer for CycExec |
f_legge | 4:70553c83c65a | 36 | Timer idle; // Timer for idle states |
f_legge | 4:70553c83c65a | 37 | |
f_legge | 4:70553c83c65a | 38 | // Constant Declaration |
f_legge | 5:e1ade53bce83 | 39 | const int SampFreq = 100; // Sampling Frequency |
f_legge | 5:e1ade53bce83 | 40 | const int WD = 6000; // Watchdog pulse length |
f_legge | 4:70553c83c65a | 41 | |
f_legge | 4:70553c83c65a | 42 | // Variable Declaration |
f_legge | 4:70553c83c65a | 43 | long int tck = 0; // Used to define what task is called (CycExec) |
f_legge | 0:10e3e2697134 | 44 | |
f_legge | 4:70553c83c65a | 45 | int period = 0; // Frequency timer variable (Frequency Check) |
f_legge | 4:70553c83c65a | 46 | int freq = 0; // Frequency return variable (Frequency Check) |
f_legge | 4:70553c83c65a | 47 | |
f_legge | 4:70553c83c65a | 48 | bool switch_state = 0; // Switch high or low (Digital In) |
f_legge | 4:70553c83c65a | 49 | |
f_legge | 4:70553c83c65a | 50 | int A1_val = 0; // Analogue 1 return variable (Analogue In) |
f_legge | 4:70553c83c65a | 51 | int A2_val = 0; // Analogue 2 return variable (Analogue In) |
f_legge | 4:70553c83c65a | 52 | |
f_legge | 6:c538f317f426 | 53 | int logcount = 0; // Keep track of log number |
f_legge | 6:c538f317f426 | 54 | |
f_legge | 6:c538f317f426 | 55 | |
f_legge | 4:70553c83c65a | 56 | |
f_legge | 4:70553c83c65a | 57 | //////////////////////////////////////////////////////////////////////////////// |
f_legge | 4:70553c83c65a | 58 | // |
f_legge | 4:70553c83c65a | 59 | // Main Program |
f_legge | 4:70553c83c65a | 60 | // |
f_legge | 4:70553c83c65a | 61 | |
f_legge | 4:70553c83c65a | 62 | int main() |
f_legge | 4:70553c83c65a | 63 | { |
f_legge | 4:70553c83c65a | 64 | // LCD Init |
f_legge | 4:70553c83c65a | 65 | par_port = new MCP23017(p9, p10, 0x40); // initialise 16-bit I/O chip |
f_legge | 4:70553c83c65a | 66 | lcd = new WattBob_TextLCD(par_port); // initialise 2*26 char display |
f_legge | 4:70553c83c65a | 67 | par_port->write_bit(1,BL_BIT); // turn LCD backlight ON |
f_legge | 4:70553c83c65a | 68 | lcd->cls(); // clear display |
f_legge | 4:70553c83c65a | 69 | |
f_legge | 4:70553c83c65a | 70 | // .csv log Init |
f_legge | 4:70553c83c65a | 71 | fp = fopen ("/uSD/log.csv", "w"); // Pointer to log file on uSD |
f_legge | 4:70553c83c65a | 72 | fprintf(fp, "Log of Frazer Legge's Embedded Software Assignment 2\n\n"); |
f_legge | 4:70553c83c65a | 73 | |
f_legge | 4:70553c83c65a | 74 | // |
f_legge | 4:70553c83c65a | 75 | tick.attach(&CycExec, 0.025); // Period set to 25ms |
f_legge | 4:70553c83c65a | 76 | while(1){ |
f_legge | 4:70553c83c65a | 77 | } |
f_legge | 0:10e3e2697134 | 78 | } |
f_legge | 4:70553c83c65a | 79 | |
f_legge | 4:70553c83c65a | 80 | void CycExec() |
f_legge | 4:70553c83c65a | 81 | { |
f_legge | 4:70553c83c65a | 82 | idle.stop(); |
f_legge | 4:70553c83c65a | 83 | |
f_legge | 4:70553c83c65a | 84 | if(tck % 40 = 0) // Every Second (needs offset) |
f_legge | 4:70553c83c65a | 85 | |
f_legge | 4:70553c83c65a | 86 | |
f_legge | 4:70553c83c65a | 87 | |
f_legge | 4:70553c83c65a | 88 | |
f_legge | 4:70553c83c65a | 89 |