![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
chad
Dependencies: MCP23017 WattBob_TextLCD mbed-rtos mbed
main.cpp
- Committer:
- f_legge
- Date:
- 2017-03-07
- Revision:
- 13:ad04937ca366
- Parent:
- 12:d088f8024cf0
- Child:
- 14:ede0e7ed2745
File content as of revision 13:ad04937ca366:
// Paramater Allocation // Paramater: 17 // Log Option: 1 (uSD) // Watchdog Pulse Length: 6ms // Watchdog Repetion Rate: 0.5 // Error Display: 1 (LCD) // Execution time display: Task5 (LDC display) #include "main.h" // Pointers to LCD Screen MCP23017 *par_port; // pointer to 16-bit parallel I/O chip WattBob_TextLCD *lcd; // pointer to 2*16 character LCD object FILE *fp; // pointer to uSD object // Digital I/O p11 to p20 DigitalIn Fq(p11); // Digital frequency in for measurement DigitalIn DS(p12); // Digital switch input DigitalIn DS_s(p13); // Digital shutdown switch DigitalOut WD_pulse_out(p14); // Watchdog Pulse SDFileSystem sd(p5, p6, p7, p8, "sd"); //uSD pinout // Analogue I/O p15 to p20 AnalogIn A1_(p15); // Analogue input to be filtered AnalogIn A2_(p16); // Analogue input to be filtered // Timer objects //Ticker tick; // Clock timer for CycExec Thread tick; Timer timer; // Frequency Timer Timer T5; // Timer for idle states // Constant Declaration const int SampFreq = 100; // Sampling Frequency const int WD = 6000; // Watchdog pulse length // Variable Declaration long int tck = 0; // Used to define what task is called (CycExec) bool FqIn = Fq; // Frequency input boolean int period = 0; // Frequency timer variable (Frequency Check) int freq = 0; // Frequency return variable (Frequency Check) bool DSIn = DS; // Switch Input boolean int switch_state = 0; int WD_pulse; int A1_in = A1_; // Analogue 1 input variable int A2_in = A2_; // Analogue 2 input variable int A1_val = 0; // Analogue 1 return variable (Analogue In) int A2_val = 0; // Analogue 2 return variable (Analogue In) bool DS_sIn = DS_s; // Shutdown Switch boolean int error_code = 0; // Error code variable int logcount = 0; // Keep track of log number //////////////////////////////////////////////////////////////////////////////// // // Main Program // void CycExec() {/* if(tck % 40 == 4){ // Every Second (needs offset) Task1(); } else if(tck % 13 == 8){ // Every 1/3 sec Task2(); } else if(tck % 80 == 7){ // Every 2 sec Task3(); } else if(tck % 20 == 0){ // Every 1/2 sec Task4(); } else if(tck % 80 == 1){ // Every 2 sec Task5(); } else if(tck % 20 == 3){ // Every 0.5 sec Task6(); } else if(tck % 20 == 10){ // Every 1/2 sec Task7(); }*/ //else{ // Task8(); //} Task1(); tck++; WD_pulse_out = WD_pulse; } int main() { // LCD Init par_port = new MCP23017(p9, p10, 0x40); // initialise 16-bit I/O chip lcd = new WattBob_TextLCD(par_port); // initialise 2*26 char display par_port->write_bit(1,BL_BIT); // turn LCD backlight ON lcd->cls(); // clear display // .csv log Init fp = fopen ("/sd/log.txt", "a"); // Pointer to log file on uSD fprintf(fp, "Log of Frazer Legge's Embedded Software Assignment 2\n\n"); // //tick.attach(&CycExec, 0.025); // Period set to 25ms while(1){ tick.start(&CycExec); wait_ms(100); } }