- Main Page
- Related Pages
- Data Structures
- Files

# main.c

Go to the documentation of this file.

    00001 /* This file has been prepared for Doxygen automatic documentation generation.*/
    00057 #include <ioavr.h>
    00058 #include <inavr.h>
    00059 #include <stdlib.h>
    00060
    00061 #include "structs.h"
    00062
    00063 #include "main.h"
    00064 #include "ADC.h"
    00065 #include "statefunc.h"
    00066 #include "battery.h"
    00067 #include "menu.h"
    00068 #include "OWI.h"
    00069 #include "PWM.h"
    00070 #include "time.h"
    00071 #include "USI.h"
    00072
    00073
    00074
    00075 //******************************************************************************
    00076 // Globals
    00077 //******************************************************************************
    00078 unsigned char CurrentState;
    00079
    00080
    00081
    00082
    00083
    00084 //******************************************************************************
    00085 // Functions
    00086 //******************************************************************************
    00098 int main( void )
    00099 {
    00100         unsigned char nextstate, inp, i;
    00101         unsigned char (*pStateFunc)(unsigned char);   // Function pointer.
    00102
    00103         // Initialize local state variables.
    00104         inp = ZERO;
    00105         CurrentState = nextstate = ST_INIT;
    00106         pStateFunc = NULL;
    00107
    00108         // Look for function associated with current state, get its address.
    00109         for (i = 0; menu_state[i].state != 0; i++) {
    00110                 if (menu_state[i].state == CurrentState) {
    00111                         pStateFunc = menu_state[i].pFunc;
    00112                 }
    00113         }
    00114
    00115         while (TRUE) {
    00116                 // Run function associated with current state, get next state in return.
    00117                 if (pStateFunc != NULL){
    00118                         nextstate = pStateFunc(inp);
    00119                 }
    00120
    00121                 // Look up function for next state, if it differs from the current.
    00122                 if (nextstate != CurrentState) {
    00123                         CurrentState = nextstate;
    00124                         for ( i = 0; menu_state[i].state != 0; i++) {
    00125                                 if (menu_state[i].state == CurrentState) {
    00126                                         pStateFunc = menu_state[i].pFunc;
    00127                                 }
    00128                         }
    00129                 }
    00130         }
    00131 }
    00132
    00133
    00134 /* Doxygen documentation mainpage ********************************************/