⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 buttons.c

📁 一个LCD驱动程序
💻 C
字号:
//*****************************************************************************
//
//  File........: Buttons.c
//
//  Author(s)...: ATMEL Norway
//
//  Target(s)...: ATmega169
//
//  Compiler....: IAR EWAAVR 2.27b
//
//  Description.: This file reads the input from the SWITCHES on STK500
//
//  Revisions...: 1.0
//
//  YYYYMMDD - VER. - COMMENT                                       - SIGN.
//
//  20021015 - 1.0  - Created                                       - LHM
//
//*****************************************************************************

//  Include files
#include "Main.h"
#include "Buttons.h"
#include "Lcd_functions.h"

// pointer table used in the "void Execute(unsigned char Adjust)"
__flash unsigned char *SRAM_values[6][3] = {{&HOUR       , &MINUTE     ,  &SECOND    },
                                            {&DAY        , &MONTH      ,  &YEAR_LO   },
                                            {&SET_POINT  , &SET_POINT  ,  &SET_POINT },
                                            {0            , 0          ,  0          },  
                                            {0            , 0          ,  0          },
                                            {&CONTRAST   , &CONTRAST   ,  &CONTRAST  }};

// three variables to handle the menu-system
unsigned char LCD_Menu1 = 0;
unsigned char LCD_Menu2 = 0;
unsigned char LCD_Menu3 = 0;

unsigned char Buttons = 0;    // store the input value from the buttons

/******************************************************************************************
*
*	Function name : CheckButtons
*
*	Returns :	    Input from user on the STK500-Buttons    	
*
*	Parameters :	none
*
*	Purpose :		Check if any input from the Buttons
*
******************************************************************************************/
void CheckButtons(void)
{
    unsigned char Temp_buttons;
    
    Temp_buttons = ~PINE;               // read PINE, 
    Temp_buttons &= 0xE0;               // mask away other bits
    
    // if anything applied on the buttons, and that differs from the last time
    if(Temp_buttons && (Temp_buttons != Buttons)) 
    {  
        Buttons = Temp_buttons; // load the temporary stored buttons to the global Buttons
    
        if(Buttons == Button1)  // if Button1 is pressed
        {
            if(LCD_Menu2)           // if LCD menu 2 is active
            {
                if(LCD_Menu3)           // if LCD menu 3 is active
                    Execute(1);             // call the Exectcute function
                else                        
                {
                    LCD_Menu2++;        // increment LCD menu 2
                    
                    if(LCD_Menu2 > 3)   // if LCD menu 2 is greater than 3
                        LCD_Menu2 = 1;      // set LCD menu 2 to 1
                }
            }
            else
            {
                LCD_Menu1++;        // increment LCD menu 1
             
                if(LCD_Menu1 > 6)   // if LCD menu 1 is greater than 6
                    LCD_Menu1 = 1;      // set LCD menu 1 to 1
            }
        }
        else if(Buttons == Button2)   // if Button2 is pressed
        {
            if(LCD_Menu1)       // if LCD menu 1 is active
            {
                if(LCD_Menu2)       // if LCD menu 2 is active
                {
                    if(LCD_Menu3)       // if LCD menu 3 is active
                        Execute(0);         // call the Execute function
                    else
                        LCD_Menu3 = 1;      // activate LCD menu 3
                }
                else
                    LCD_Menu2 = 1;  // activate LCD menu 2
            }
        }
        else if(Buttons == Button3)   // if Button3 is pressed
        {
            if(LCD_Menu1)       // if LCD menu 1 is active
            {
                if(LCD_Menu2)       // if LCD menu 2 is active
                {
                    if(LCD_Menu3)       // if LCD menu 3 is active
                        LCD_Menu3 = 0;      // deactivate LCD menu 3
                    else
                        LCD_Menu2 = 0;      // deactivate LCD menu 2
                }
                else    
                    LCD_Menu1 = 0;  // deactivate LCD menu 1
            }
        }
    
        LCDsetupData();     // set up with the new LCD menu X settings
    }
    else
        Buttons = Temp_buttons;     // load the input on PINE to the global Buttons
}


/******************************************************************************************
*
*	Function name : Execute
*
*	Returns :	    None
*
*	Parameters :	Adjust (TRUE or FALSE)
*
*	Purpose :		Increase or decrease a variable selected by LCD_Menu1/2
*
******************************************************************************************/
void Execute(unsigned char Adjust)
{
    if(SRAM_values[LCD_Menu1-1][LCD_Menu2-1])      // if there is a value to adjust
    {
        if(Adjust)  
            *SRAM_values[LCD_Menu1-1][LCD_Menu2-1] += 1; // if TRUE, then increase the variable by one
        else        
            *SRAM_values[LCD_Menu1-1][LCD_Menu2-1] -= 1; // else decrease the variable by one
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -