#include <LCDv3.h>
#include "Config.h"
#include "Menu.h"
#include "LCD_Interface.c"
#include "Input.c"
#define MENU_LINE 2
unsigned char MenuNo(unsigned char No)
{
if ((No>=0)&&(No<=9))
{
return No+'0';
}
else if ((No>=10)&&(No<=36))
{
return No-10+'A';
}
else
{
return '?';
}
}
void ChooseRadioMenu(unsigned char ParamCaptionID,unsigned char MenuDefineID,unsigned char *Value)
{
flash unsigned char *Caption;
flash unsigned char *pDefine;
unsigned char Key;
unsigned char Pos;
unsigned int TopMenuItem;
unsigned int CurrentMenuItem;
//unsigned char i;
unsigned char MenuCount;
delay_ms(10);
SOUND_STOP;
LCD_WriteCaption(ParamCaptionID,0);
Pos=LCD_Position()-1;
WriteCGRAM(0x82,1,0);
WriteCGRAM(0x83,2,0);
WriteCGRAM(0x84,3,0);
pDefine=SubMenuDefine+(unsigned int)2*(unsigned int)MenuDefineID;
MenuCount=pDefine[1];
TopMenuItem=pDefine[0];
CurrentMenuItem=*Value;
if (CurrentMenuItem>MenuCount-1)
{
CurrentMenuItem=MenuCount-1;
}
Key=1;
while (Key!=BT_APPLY)
{
if (Key!=0)
{
LCD_Ctrl(LCD_SET_DDRAM|Pos);
Caption=Menu+(CAPTION_LENGTH+2)*(TopMenuItem+CurrentMenuItem-1);
if (CurrentMenuItem==0)
{
LCD_Write(3);
}
else if (CurrentMenuItem==MenuCount-1)
{
LCD_Write(1);
}
else
{
LCD_Write(2);
}
//LCD_Write(MenuNo(CurrentMenuItem));
LCD_Write(' ');
LCD_Write('=');
LCD_PutStrF(Caption);
}
Key=GetKey();
if (Key!=0)
{
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);
SOUND_STOP; //Sound Stop
}
}
}
void ShowMenu(void)
{
flash unsigned char *pMenu;
flash unsigned char *pDefine;
flash unsigned char *Caption;
unsigned char Key;
unsigned int TopMenuItem;
unsigned int CurrentMenuItem;
unsigned char i;
unsigned char Stack[3][5];
unsigned char StackIndex;
unsigned char DrawMenuItem[6]={LCD_SET_DDRAM,0xC0,1,0,0,1};
unsigned char MenuCount;
unsigned char j;
//unsigned char MenuItem;
pMenu=Menu;
pDefine=SubMenuDefine;
TopMenuItem=0;
CurrentMenuItem=0;
//MenuItem=0;
Key=1;
WriteCGRAM(0x80,0,0);
WriteCGRAM(0x81,1,0);
StackIndex=0;
Stack[0][0]=0;
Stack[1][0]=0;
Stack[2][0]=0;
MenuCount=SubMenuDefine[1];
while (1)
{
if (Key!=0)
{
for (j=0;j<2;j++)
{
LCD_Ctrl(DrawMenuItem[0+j]);
if (DrawMenuItem[(unsigned char)(j+4)]<MenuCount)
{
Caption=Menu+(CAPTION_LENGTH+2)*(TopMenuItem+DrawMenuItem[(unsigned char)(j+4)]);
if (DrawMenuItem[(unsigned char)(j+2)])
{
LCD_PutStrF(" ");
LCD_Write(0);
LCD_Write(MenuNo(DrawMenuItem[(unsigned char)(j+4)]+1));
LCD_Write('.');
LCD_PutStrF(Caption);
}
else
{
LCD_PutStrF(" ");
LCD_Write(MenuNo(DrawMenuItem[(unsigned char)(j+4)]+1));
LCD_Write('.');
LCD_PutStrF(Caption);
}
}
else
{
for (i=0;i<16;i++) LCD_Write(' ');
}
}
}
Key=GetKey();
if (Key!=0)
{
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+(unsigned int)(*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_LEFT)
{
if (StackIndex>0)
{
StackIndex--;
pDefine=SubMenuDefine+(unsigned int)(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;
}
}
delay_ms(10);
SOUND_STOP; //Sound Stop
}
}
}
AVR源程序(CVAVR 1.24.8)
生成AVR菜单的工具
|
|
|
|