Example software for a Cyclic Executive

Dependencies:   MCP23017 SDFileSystem WattBob_TextLCD mbed

Committer:
sk398
Date:
Fri Feb 26 10:36:23 2016 +0000
Revision:
4:b85bc0d810e1
Parent:
3:c611b9bb5770
Child:
5:250f51c80ac1
Display function works, Analog function works, digitalIN function works.; ; Freq measurement still to work.; ; Display to be changed to class structure

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sk398 4:b85bc0d810e1 1 /* #####################################################################
sk398 4:b85bc0d810e1 2 main.cpp
sk398 4:b85bc0d810e1 3 ---------
sk398 4:b85bc0d810e1 4
sk398 4:b85bc0d810e1 5 Embedded Software - Assignment 2
sk398 4:b85bc0d810e1 6 --------------------------------
sk398 4:b85bc0d810e1 7
sk398 4:b85bc0d810e1 8 Written by: Steven Kay
sk398 4:b85bc0d810e1 9
sk398 4:b85bc0d810e1 10 Date: February 2016
sk398 4:b85bc0d810e1 11
sk398 4:b85bc0d810e1 12 Function: This
sk398 4:b85bc0d810e1 13
sk398 4:b85bc0d810e1 14 Version: 1.0
sk398 4:b85bc0d810e1 15
sk398 4:b85bc0d810e1 16 Version History
sk398 4:b85bc0d810e1 17 ---------------
sk398 4:b85bc0d810e1 18
sk398 4:b85bc0d810e1 19 1.1 rgdfgdfgdfggdfgdg
sk398 4:b85bc0d810e1 20
sk398 4:b85bc0d810e1 21 1.0 gdgddfdddgd
sk398 4:b85bc0d810e1 22
sk398 4:b85bc0d810e1 23 ##################################################################### */
sk398 2:22ebabd78084 24
sk398 0:5989ac10c4d3 25 #include "mbed.h"
sk398 1:221d677fe0d3 26 #include "Tasks.h"
sk398 4:b85bc0d810e1 27 #include "MCP23017.h"
sk398 4:b85bc0d810e1 28 #include "WattBob_TextLCD.h"
sk398 0:5989ac10c4d3 29
sk398 4:b85bc0d810e1 30 #define BACK_LIGHT_ON(INTERFACE) INTERFACE->write_bit(1,BL_BIT)
sk398 4:b85bc0d810e1 31 #define BACK_LIGHT_OFF(INTERFACE) INTERFACE->write_bit(0,BL_BIT)
sk398 4:b85bc0d810e1 32
sk398 4:b85bc0d810e1 33 MCP23017 *par_port;
sk398 4:b85bc0d810e1 34 WattBob_TextLCD *lcd;
sk398 0:5989ac10c4d3 35
sk398 0:5989ac10c4d3 36 DigitalOut myled(LED1);
sk398 0:5989ac10c4d3 37
sk398 4:b85bc0d810e1 38 Task1 task1(p11); // Square wave Measurement
sk398 4:b85bc0d810e1 39 Task2 task2_switch1(p12); // Read digital Output
sk398 4:b85bc0d810e1 40 Task3 task3(p13); // Watchdog Pulse
sk398 4:b85bc0d810e1 41 Task4 task4(p15,p16); // Read analog Inputs
sk398 0:5989ac10c4d3 42
sk398 4:b85bc0d810e1 43 void updateDisplay(int task1Param,int task2Param, float task4Channel1, float task4Channel2);
sk398 0:5989ac10c4d3 44
sk398 0:5989ac10c4d3 45 int main() {
sk398 3:c611b9bb5770 46
sk398 4:b85bc0d810e1 47 par_port = new MCP23017(p9,p10,0x40);
sk398 4:b85bc0d810e1 48 lcd = new WattBob_TextLCD(par_port);
sk398 4:b85bc0d810e1 49 par_port -> write_bit(1,BL_BIT);
sk398 4:b85bc0d810e1 50
sk398 4:b85bc0d810e1 51
sk398 4:b85bc0d810e1 52 int task1Frequency = task1.ReadFrequency();
sk398 4:b85bc0d810e1 53 printf("Task 1 Frequency %d Hz\r\n",task1Frequency);
sk398 4:b85bc0d810e1 54
sk398 4:b85bc0d810e1 55 int task2SwitchState = task2_switch1.digitalInState();
sk398 4:b85bc0d810e1 56 printf("Switch 1 State: %d\r\n",task2SwitchState);
sk398 4:b85bc0d810e1 57
sk398 3:c611b9bb5770 58 task3.OutputWatchdogPulse();
sk398 4:b85bc0d810e1 59
sk398 3:c611b9bb5770 60 float *analogReading = task4.returnAnalogReadings();
sk398 4:b85bc0d810e1 61 float channel1 = *(analogReading);
sk398 4:b85bc0d810e1 62 float channel2 = *(analogReading+1);
sk398 4:b85bc0d810e1 63 printf("Analog Readings:\r\nChannel 1-%f\r\nChannel 2-%f\r\n",channel1,channel2);
sk398 3:c611b9bb5770 64
sk398 4:b85bc0d810e1 65 updateDisplay(task1Frequency,task2SwitchState,channel1,channel2);
sk398 0:5989ac10c4d3 66 while(1) {
sk398 0:5989ac10c4d3 67 myled = 1;
sk398 0:5989ac10c4d3 68 wait(0.2);
sk398 0:5989ac10c4d3 69 myled = 0;
sk398 0:5989ac10c4d3 70 wait(0.2);
sk398 0:5989ac10c4d3 71 }
sk398 0:5989ac10c4d3 72 }
sk398 4:b85bc0d810e1 73
sk398 4:b85bc0d810e1 74 void updateDisplay(int task1Param,int task2Param, float task4Channel1, float task4Channel2)
sk398 4:b85bc0d810e1 75 {
sk398 4:b85bc0d810e1 76 lcd -> cls();
sk398 4:b85bc0d810e1 77 lcd -> locate(0,0);
sk398 4:b85bc0d810e1 78 lcd -> printf("F-%4dHz S1-%d ",task1Param,task2Param);
sk398 4:b85bc0d810e1 79 lcd -> locate(1,0);
sk398 4:b85bc0d810e1 80 lcd -> printf("C1-%1.2f C2-%1.2f ",task4Channel1,task4Channel2);
sk398 4:b85bc0d810e1 81 }