www.pudn.com > PRMCharger_V0.04.rar > menu.c, change:2008-03-09,size:10478b


/****************************************Copyright (c)************************************************** 
**                              智 能 充 电 器 开 发 小 组 
**                                     OurAVR 论坛 
**                                   QQ 群: 26052247  
** 
**                               http://www.ouravr.com/bbs 
** 
**--------------文件信息-------------------------------------------------------------------------------- 
**文   件   名: SIO.c 
**创   建   人: Trinove 
**最后修改日期: 2008年01月13日 
**描        述: 菜单的底层函数  FOR AVR MCU / Mega16 
**               
**--------------历史版本信息---------------------------------------------------------------------------- 
** 创建人: aleyn.wu 
** 版  本: V1.0 
** 日 期: 2008年01月13日 
** 描 述: 原始版本 
** 
**--------------当前版本修订------------------------------------------------------------------------------ 
** 修改人: 吕海安 
** 日 期: 2008年03月09日 
** 描 述: For 智能充电器 
** 
**------------------------------------------------------------------------------------------------------ 
********************************************************************************************************/ 
#include "Config.h" 
#include "Menu.h" 
 
#define MENU_LINE 2 
/******************************************************************************************************* 
** 函数名称: ExecuteMenu 
** 功能描述: 菜单显示程序,每 100 mS 调用一次即可 
** 输入参数: 无 
** 输出参数: 无 
********************************************************************************************************/ 
void ExecuteMenu(INT8U MenuID) 
{ 
	if (MenuID == MN_STAT_BATTERY0) 
	{ 
		ReadBatterySTAT(BATTERY0); 
	} 
	else if (MenuID == MN_STAT_BATTERY1) 
	{ 
		ReadBatterySTAT(BATTERY1); 
	} 
	else if (MenuID == MN_STAT_BATTERY_BOTH) 
	{ 
		ReadBatterySTAT(BATTERY_BOTH);		 
	} 
} 
/******************************************************************************************************* 
** 函数名称: MenuNo 
** 功能描述: 菜单序号 
** 输入参数: INT8U No: 
** 输出参数:  
********************************************************************************************************/ 
INT8U MenuNo(INT8U No) 
{ 
    if ((No >= 0) && (No <= 9)) 
    { 
        return No + '0'; 
    } 
    else if ((No >= 10) && (No <= 36)) 
    { 
        return No - 10 + 'A'; 
    } 
    else 
    { 
        return '?'; 
    } 
} 
 
/******************************************************************************************************* 
** 函数名称: ChooseRadioMenu 
** 功能描述: 选择单选菜单 
** 输入参数: INT8U ParamCaptionID: 
**           INT8U MenuDefineID: 
**           INT8U *Value 
** 输出参数: 无 
********************************************************************************************************/ 
/* 
void ChooseRadioMenu(INT8U ParamCaptionID, INT8U MenuDefineID, INT8U *Value) 
{ 
    flash INT8U *Caption; 
    flash INT8U *pDefine; 
    INT8U Key; 
    INT8U Pos; 
    INT16U TopMenuItem; 
    INT16U CurrentMenuItem; 
    //INT8U i; 
    INT8U MenuCount; 
    delay_ms(10); 
    //LCD_WriteCaption(ParamCaptionID, 0); 
    //Pos = LCD_Position() - 1;   
     lcd_locate(0,0); 
    //WriteCGRAM(0x82,1,0); 
    //WriteCGRAM(0x83,2,0); 
    //WriteCGRAM(0x84,3,0); 
    pDefine = SubMenuDefine + (INT16U)2 * (INT16U)MenuDefineID; 
    MenuCount = pDefine[1]; 
    TopMenuItem = pDefine[0]; 
    CurrentMenuItem = *Value; 
    if (CurrentMenuItem > MenuCount - 1) 
    { 
        CurrentMenuItem=MenuCount - 1; 
    } 
 
    Key = INIT_KEY; 
    while (Key != BT_APPLY) 
    { 
        if (Key != NO_KEY) 
        { 
            lcd_write_byte((0x80 | Pos), CMD); 
            Caption = Menu + (CAPTION_LENGTH + 2) * (TopMenuItem + CurrentMenuItem - 1); 
            if (CurrentMenuItem == 0) 
            {    
                lcd_write_byte(3, DATA); 
            } 
            else if (CurrentMenuItem == MenuCount - 1) 
            { 
                lcd_write_byte(1, DATA); 
            } 
            else 
            { 
                lcd_write_byte(2, DATA); 
            } 
            //LCD_Write(MenuNo(CurrentMenuItem));  
            lcd_write_byte(' ', DATA);  
            lcd_write_byte('=', DATA);             
            lcd_print_stringF(Caption); 
        } 
        Key = read_keycode(); 
        if (Key != NO_KEY) 
        { 
            if (Key == BT_UP) 
            { 
                if (CurrentMenuItem > 0) 
                { 
                    CurrentMenuItem --; 
                }  
            } 
            else if (Key == BT_DOWN) 
            {    
                if (CurrentMenuItem < MenuCount - 1) 
                { 
                    CurrentMenuItem ++; 
                } 
            } 
            else if (Key == BT_APPLY) 
            { 
                *Value = CurrentMenuItem; 
            } 
            else if (Key == BT_LEFT) 
            { 
                Key = BT_APPLY; 
            } 
            delay_ms(10) 
        } 
    } 
}  
*/ 
/******************************************************************************************************* 
** 函数名称: ShowMenu 
** 功能描述: 菜单显示程序,每 100 mS 调用一次即可 
** 输入参数: 无 
** 输出参数: 无 
********************************************************************************************************/ 
void ShowMenu(void) 
{ 
    static flash INT8U *pMenu; 
    static flash INT8U *pDefine; 
    static flash INT8U *Caption;   
    static INT16U TopMenuItem = 0; 
    static INT16U CurrentMenuItem = 0; 
    static INT8U Stack[3][5] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};  
    static INT8U StackIndex = 0; 
    static INT8U DrawMenuItem[6]={0x80,0xC0,1,0,0,1}; 
    static INT8U MenuCount; 
    static INT8U FlagMenuInit = 1;   // 显示菜单框架 
    static INT8U Key = INIT_KEY;     // 第一次显示菜单 
    INT8U i = 0; 
    INT8U j = 0;  
    if(FlagMenuInit) 
    { 
        FlagMenuInit = 0;  // 清第一次标志  
        lcd_cls();  //清屏     
        pMenu = Menu;   
        pDefine = SubMenuDefine; 
        MenuCount = SubMenuDefine[1];  
        //WriteCGRAM(0x80,0,0);     // 写入特殊字符  
        //WriteCGRAM(0x81,1,0);     // 写入特殊字符   
    }   
    if (Key != NO_KEY) 
    {         
        for (j=0; j<2; j++) 
        { 
            lcd_write_byte(DrawMenuItem[0 + j], CMD); 
            if (DrawMenuItem[(INT8U)(j + 4)] < MenuCount) 
            { 
                Caption = Menu + (CAPTION_LENGTH + 2) * (TopMenuItem + DrawMenuItem[(INT8U)(j + 4)]); 
                if (DrawMenuItem[(INT8U)(j + 2)]) 
                {                 
                    lcd_write_byte(0, DATA); 
                    lcd_write_byte(MenuNo(DrawMenuItem[(INT8U)(j + 4)] + 1), DATA); 
                    lcd_write_byte('.', DATA); 
                    lcd_print_stringF(Caption); 
                } 
                else 
                {    
                    lcd_print_stringF(" "); 
                    lcd_write_byte(MenuNo(DrawMenuItem[(INT8U)(j + 4)] + 1), DATA); 
                    lcd_write_byte('.', DATA); 
                    lcd_print_stringF(Caption); 
                } 
            } 
            else 
            { 
                for (i=0; i<16; i++)  
                { 
                    lcd_write_byte(' ', DATA); 
                } 
            }        
        } 
    } 
    Key = read_keycode();  
    if (Key != NO_KEY) 
    { 
        if (Key == BT_UP) 
        { 
            if (DrawMenuItem[3]) 
            { 
                DrawMenuItem[2]=1; 
                DrawMenuItem[3]=0; 
            }  
            else if (DrawMenuItem[4]>0) 
            { 
                DrawMenuItem[4]--; 
                DrawMenuItem[5]--; 
            } 
        } 
        else if (Key == BT_DOWN) 
        {    
            if (DrawMenuItem[2]) 
            { 
                DrawMenuItem[2]=0; 
                DrawMenuItem[3]=1; 
            } 
            else if (DrawMenuItem[5]<MenuCount-1) 
            { 
                DrawMenuItem[4]++; 
                DrawMenuItem[5]++; 
            } 
        } 
        else if ((Key == BT_APPLY) || (Key == BT_RIGHT)) 
        { 
            if (DrawMenuItem[2]) 
            { 
                CurrentMenuItem = TopMenuItem + DrawMenuItem[4]; 
            } 
            else 
            { 
                CurrentMenuItem = TopMenuItem + DrawMenuItem[5]; 
            } 
            if (CurrentMenuItem < MENU_COUNT) 
            { 
                pMenu = Menu + ((CAPTION_LENGTH + 2) * CurrentMenuItem) + CAPTION_LENGTH + 1; 
                if (*pMenu > MENU_SUBITEM) 
                { 
                    Stack[0][StackIndex] = pDefine-SubMenuDefine; 
                    Stack[1][StackIndex] = DrawMenuItem[2]; 
                    Stack[2][StackIndex] = DrawMenuItem[4]; 
                    StackIndex ++; 
                    pDefine = SubMenuDefine + ((INT16U)(*pMenu - MENU_SUBITEM) * 2); 
                    TopMenuItem =* pDefine - 1; 
                    MenuCount = pDefine[1]; 
                    DrawMenuItem[2] = 1; 
                    DrawMenuItem[3] = 0; 
                    DrawMenuItem[4] = 0; 
                    DrawMenuItem[5] = 1; 
                } 
                else if (*pMenu <= MENU_SUBITEM) 
                { 
                    ExecuteMenu(CurrentMenuItem + 1); 
                } 
            } 
        } 
        else if ((Key == BT_CANCEL) || (Key == BT_LEFT)) 
        { 
            if (StackIndex > 0) 
            { 
                StackIndex --; 
                pDefine=SubMenuDefine + (INT16U)(Stack[0][StackIndex]); 
                TopMenuItem=*pDefine - 1; 
                MenuCount=pDefine[1]; 
                DrawMenuItem[2] = Stack[1][StackIndex]; 
                DrawMenuItem[3] = 1 - Stack[1][StackIndex]; 
                DrawMenuItem[4] = Stack[2][StackIndex]; 
                DrawMenuItem[5] = Stack[2][StackIndex] + 1; 
            } 
        } 
    }               
} 
 
 
/******************************************************************************************************** 
**                                 END OF FILE 
********************************************************************************************************/ 

送体验金的网站