Buttons.c

Go to the documentation of this file.
00001 /* This file has been prepared for Doxygen automatic documentation generation.*/
00025 //  Include files
00026 #include "Main.h"
00027 #include "Buttons.h"
00028 #include "Lcd_functions.h"
00029 
00030 // pointer table used in the "void Execute(unsigned char Adjust)"
00031 __flash unsigned char *SRAM_values[6][3] = {{&HOUR       , &MINUTE     ,  &SECOND    },
00032                                             {&DAY        , &MONTH      ,  &YEAR_LO   },
00033                                             {&SET_POINT  , &SET_POINT  ,  &SET_POINT },
00034                                             {0            , 0          ,  0          },
00035                                             {0            , 0          ,  0          },
00036                                             {&CONTRAST   , &CONTRAST   ,  &CONTRAST  }};
00037 
00038 // three variables to handle the menu-system
00039 unsigned char LCD_Menu1 = 0;
00040 unsigned char LCD_Menu2 = 0;
00041 unsigned char LCD_Menu3 = 0;
00042 
00043 unsigned char Buttons = 0;    // store the input value from the buttons
00044 
00045 
00049 void CheckButtons(void)
00050 {
00051     unsigned char Temp_buttons;
00052 
00053     Temp_buttons = ~PINE;               // read PINE,
00054     Temp_buttons &= 0xE0;               // mask away other bits
00055 
00056     // if anything applied on the buttons, and that differs from the last time
00057     if(Temp_buttons && (Temp_buttons != Buttons))
00058     {
00059         Buttons = Temp_buttons; // load the temporary stored buttons to the global Buttons
00060 
00061         if(Buttons == Button1)  // if Button1 is pressed
00062         {
00063             if(LCD_Menu2)           // if LCD menu 2 is active
00064             {
00065                 if(LCD_Menu3)           // if LCD menu 3 is active
00066                     Execute(1);             // call the Exectcute function
00067                 else
00068                 {
00069                     LCD_Menu2++;        // increment LCD menu 2
00070 
00071                     if(LCD_Menu2 > 3)   // if LCD menu 2 is greater than 3
00072                         LCD_Menu2 = 1;      // set LCD menu 2 to 1
00073                 }
00074             }
00075             else
00076             {
00077                 LCD_Menu1++;        // increment LCD menu 1
00078 
00079                 if(LCD_Menu1 > 6)   // if LCD menu 1 is greater than 6
00080                     LCD_Menu1 = 1;      // set LCD menu 1 to 1
00081             }
00082         }
00083         else if(Buttons == Button2)   // if Button2 is pressed
00084         {
00085             if(LCD_Menu1)       // if LCD menu 1 is active
00086             {
00087                 if(LCD_Menu2)       // if LCD menu 2 is active
00088                 {
00089                     if(LCD_Menu3)       // if LCD menu 3 is active
00090                         Execute(0);         // call the Execute function
00091                     else
00092                         LCD_Menu3 = 1;      // activate LCD menu 3
00093                 }
00094                 else
00095                     LCD_Menu2 = 1;  // activate LCD menu 2
00096             }
00097         }
00098         else if(Buttons == Button3)   // if Button3 is pressed
00099         {
00100             if(LCD_Menu1)       // if LCD menu 1 is active
00101             {
00102                 if(LCD_Menu2)       // if LCD menu 2 is active
00103                 {
00104                     if(LCD_Menu3)       // if LCD menu 3 is active
00105                         LCD_Menu3 = 0;      // deactivate LCD menu 3
00106                     else
00107                         LCD_Menu2 = 0;      // deactivate LCD menu 2
00108                 }
00109                 else
00110                     LCD_Menu1 = 0;  // deactivate LCD menu 1
00111             }
00112         }
00113 
00114         LCDsetupData();     // set up with the new LCD menu X settings
00115     }
00116     else
00117         Buttons = Temp_buttons;     // load the input on PINE to the global Buttons
00118 }
00119 
00120 
00121 
00125 void Execute(unsigned char Adjust)
00126 {
00127     if(SRAM_values[LCD_Menu1-1][LCD_Menu2-1])      // if there is a value to adjust
00128     {
00129         if(Adjust)
00130             *SRAM_values[LCD_Menu1-1][LCD_Menu2-1] += 1; // if TRUE, then increase the variable by one
00131         else
00132             *SRAM_values[LCD_Menu1-1][LCD_Menu2-1] -= 1; // else decrease the variable by one
00133     }
00134 }

Generated on Fri Feb 17 12:28:29 2006 for AVR064: A Temperature Monitoring System with LCD Output by  doxygen 1.4.5