Main Page | Data Structures | File List | Data Fields | Globals

ATAVRBFLY_FILES/main.c

Go to the documentation of this file.
00001 // This file has been prepared for Doxygen automatic documentation generation. 00047 //Includes 00048 #include<inavr.h> 00049 #include<iom169.h> 00050 00051 #include"main.h" 00052 #include"LCD_functions.h" 00053 #include"LCD_driver.h" 00054 #include"button.h" 00055 #include"BCD.h" 00056 #include"types.h" 00057 #include"STATE_functions.h" 00058 #include"menu.h" 00059 00060 #include"..\AVRGSM_FILES\AVRGSM_api.h" 00061 #include"..\AVRGSM_FILES\AVRGSM_com.h" 00062 00063 00064 #define pLCDREG_test (*(char *)(0xEC)) 00065 00066 00067 extern int rx_ack; //From AVRGSM_com.c 00068 00069 extern __flash unsigned int LCD_character_table[]; 00070 00071 unsigned char state; // helds the current state, according to 00072 // "menu.h" 00073 00074 00084 __C_task void main( void ) 00085 { 00086 00088 unsigned char nextstate; 00089 static char __flash *statetext; 00090 char (*pStateFunc)(char); 00091 char input; 00092 char i; 00093 00095 state = nextstate = ST_AVR_IDLE; 00096 statetext = MT_IDLE; 00097 pStateFunc = NULL; 00098 00099 00101 Initialization( ); 00102 __enable_interrupt(); 00103 00104 00106 for( ;; ) 00107 { 00108 00109 if( ( state == ST_AVR_READY ) && ( rx_ack == 1 ) ) //New SMS 00110 { 00111 00112 state = nextstate = ST_AVR_NEW_SMS_function; //Setting new state 00113 statetext = NULL; 00114 pStateFunc = ST_get_index; 00115 } 00116 00117 // Plain menu text 00118 if( statetext ) 00119 { 00120 00121 LCD_puts_f( statetext, 1 ); 00122 LCD_Colon( 0 ); 00123 statetext = NULL; 00124 } 00125 00126 //Get input 00127 input = getkey( ); 00128 00129 if ( pStateFunc ) 00130 { 00131 00132 // When in this state, we must call the state function 00133 nextstate = pStateFunc(input); 00134 } 00135 00136 else if (input != KEY_NULL) 00137 { 00138 00139 // Plain menu, clock the state machine 00140 nextstate = StateMachine(state, input); 00141 } 00142 00143 if (nextstate != state) 00144 { 00145 state = nextstate; 00146 00147 for (i=0; menu_state[i].state; i++) 00148 { 00149 00150 if (menu_state[i].state == state) 00151 { 00152 00153 statetext = menu_state[i].pText; 00154 pStateFunc = menu_state[i].pFunc; 00155 break; 00156 } 00157 } 00158 } 00159 } 00160 } 00161 00162 00171 unsigned char StateMachine( char state, unsigned char stimuli ) 00172 { 00173 00174 unsigned char nextstate = state; // Default stay in same state 00175 unsigned char i; 00176 00177 for ( i=0; menu_nextstate[i].state; i++ ) 00178 { 00179 00180 if ( ( menu_nextstate[i].state == state ) && ( menu_nextstate[i].input == stimuli ) ) 00181 { 00182 00183 // This is the one! 00184 nextstate = menu_nextstate[i].nextstate; 00185 break; 00186 } 00187 } 00188 00189 return nextstate; 00190 } 00191 00192 00206 void Initialization(void) 00207 { 00208 00209 PORTB = (15<<PORTB0); // Enable pullup on 00210 PORTE = (15<<PORTE4); 00211 00212 COM_init( 51 ); //9600bps @ 8MHz 00213 Button_Init( ); // Initialize pin change interrupt on joystick 00214 LCD_Init( ); // initialize the LCD 00215 }

Generated on Tue Nov 1 16:21:39 2005 for AVR323 Interfacing GSM modems by doxygen 1.3.7