📄 lcd.c
字号:
0xBCCC,cChar_BCCC,
0xBCFC,cChar_BCFC,
0xC3F9,cChar_C3F9,
0xC6F7,cChar_C6F7,
0xC7EB,cChar_C7EB,
0xC8CE,cChar_C8CE,
0xCABC,cChar_CABC,
0xCAD4,cChar_CAD4,
0xCEDE,cChar_CEDE,
0xD0A7,cChar_D0A7,
0xD0F8,cChar_D0F8,
0xD2E2,cChar_D2E2,
0xD6D0,cChar_D6D0,
0xFFFF,0
};
//display structure for Frame0
const struct LCDString Frame0[4] =
{
0,0," ATmega16 GUI ",
0,1," 初始化中,请等待",
0,2," ",
0,3," "
};
//display structure for Frame1
const struct LCDString Frame1[4] =
{
0,0," ATmega16 GUI ",
0,1," LED测试 ",
0,2," 蜂鸣器测试 ",
0,3," "
};
//display structure for Frame2
const struct LCDString Frame2[4] =
{
0,0," ATmega16 GUI ",
0,1," 无效按键,按任 ",
0,2,"意键继续... ",
0,3," ",
};
//display structure for Frame3
const struct LCDString Frame3[4] =
{
0,0," ATmega16 GUI ",
0,1," LED测试 ",
0,2," ENTER = START ",
0,3," ESC = CANCEL "
};
//display structure for Frame4
const struct LCDString Frame4[4] =
{
0,0," ATmega16 GUI ",
0,1," 蜂鸣器测试 ",
0,2," ENTER = START ",
0,3," ESC = CANCEL "
};
//******************************************************************************
// Function : LCD_Window0_Process
// Input : none
// Output : none
// Description : Self Test and Progress Bar Process
//******************************************************************************
void LCD_Window0_Process(void)
{
static INT8U bCount = 0;
if(bWindowIndexPre != bWindowIndex)
{
Win_Show_Screen(Frame0);
LCD_Show_Time();
}
while(1)
{
if(OS_Task_Switch(cPrioLCD) == true)
{
return;
}
wLCD_Event = OS_Event_Pend(cPrioLCD);
if(wLCD_Event == 0)
{
return;
}
if(wLCD_Event & (1 << eLCDTimer))
{
bWindowIndexPre = 0;
LCD_Show_Time();
LCD_Write_Char(2,bCount,eChar_DD);
if(bCount++ >= 16)
{
bCount = 0;
bWindowIndex = 1; //Select Test Window
return;
}
}
}
}
//******************************************************************************
// Function : LCD_Window1_Process
// Input : none
// Output : none
// Description : Window Process for Invalid Key
//******************************************************************************
void LCD_Window1_Process(void)
{
static INT8U bIndex = 0;
if(bWindowIndexPre != bWindowIndex)
{
Win_Show_Screen(Frame1);
LCD_Write_Char(1,1,eChar_10); //Display Cursor
LCD_Show_Time();
}
while(1)
{
if(OS_Task_Switch(cPrioLCD) == true)
{
return;
}
wLCD_Event = OS_Event_Pend(cPrioLCD);
if(wLCD_Event == 0)
{
return;
}
if(wLCD_Event & (1 << eLCDTimer))
{
bWindowIndexPre = bWindowIndex;
LCD_Show_Time();
}
if(wLCD_Event & (1 << eLCDKeyEnter))
{
if(bIndex == 0)
{
bWindowIndex = 3; //LED Test Window
}
else if(bIndex == 1)
{
bWindowIndex = 4; //BUZZER Test Window
}
bIndex = 0;
return;
}
if(wLCD_Event & (1 << eLCDKeyEsc))
{
bWindowIndex = 2; //无效按键页面
bIndex = 0;
return;
}
if(wLCD_Event & (1 << eLCDKeyUp))
{
if(bIndex == 1)
{
bIndex = 0;
LCD_Write_Char(1,1,eChar_10);//显示光标
LCD_Write_Char(2,1,eChar_20);//清除光标
}
}
if(wLCD_Event & (1 << eLCDKeyDown))
{
if(bIndex == 0)
{
bIndex = 1;
LCD_Write_Char(1,1,eChar_20);//清除光标
LCD_Write_Char(2,1,eChar_10);//显示光标
}
}
}
}
//******************************************************************************
// Function : LCD_Window2_Process
// Input : none
// Output : none
// Description : Window Process for Test Selection
//******************************************************************************
void LCD_Window2_Process(void)
{
if(bWindowIndexPre != bWindowIndex)
{
Win_Show_Screen(Frame2);
LCD_Show_Time();
}
while(1)
{
if(OS_Task_Switch(cPrioLCD) == true)
{
return;
}
wLCD_Event = OS_Event_Pend(cPrioLCD);
if(wLCD_Event == 0)
{
return;
}
if(wLCD_Event & (1 << eLCDTimer))
{
bWindowIndexPre = bWindowIndex;
LCD_Show_Time();
}
if(wLCD_Event & (1 << eLCDKeyEnter))
{
bWindowIndex = 1; //Selection Window
return;
}
if(wLCD_Event & (1 << eLCDKeyEsc))
{
bWindowIndex = 1; //Selection Window
return;
}
if(wLCD_Event & (1 << eLCDKeyUp))
{
bWindowIndex = 1; //Selection Window
return;
}
if(wLCD_Event & (1 << eLCDKeyDown))
{
bWindowIndex = 1; //Selection Window
return;
}
}
}
//******************************************************************************
// Function : LCD_Window3_Process
// Input : none
// Output : none
// Description : Window Process for LED Test
//******************************************************************************
void LCD_Window3_Process(void)
{
static INT8U bCount = 0;
if(bWindowIndexPre != bWindowIndex)
{
Win_Show_Screen(Frame3);
}
while(1)
{
if(OS_Task_Switch(cPrioLCD) == true)
{
return;
}
wLCD_Event = OS_Event_Pend(cPrioLCD);
if(wLCD_Event == 0)
{
return;
}
if(wLCD_Event & (1 << eLCDTimer))
{
bWindowIndexPre = bWindowIndex;
if(sbGet_LED_Test() == true)
{
if(bCount == 0)
{
LED_ON_ALL();
bCount = 1;
}
else
{
LED_OFF_ALL();
bCount = 0;
}
}
}
if(wLCD_Event & (1 << eLCDKeyEnter))
{
if(sbGet_LED_Test() == false)
{
sSet_LED_Test(true);
}
}
if(wLCD_Event & (1 << eLCDKeyEsc))
{
sSet_LED_Test(false);
LED_OFF_ALL();
bWindowIndex = 1; //选择界面
return;
}
}
}
//******************************************************************************
// Function : LCD_Window4_Process
// Input : none
// Output : none
// Description : Window Process for Buzzer Test
//******************************************************************************
void LCD_Window4_Process(void)
{
static INT8U bCount = 0;
if(bWindowIndexPre != bWindowIndex)
{
Win_Show_Screen(Frame4);
}
while(1)
{
if(OS_Task_Switch(cPrioLCD) == true)
{
return;
}
wLCD_Event = OS_Event_Pend(cPrioLCD);
if(wLCD_Event == 0)
{
return;
}
if(wLCD_Event & (1 << eLCDTimer))
{
bWindowIndexPre = bWindowIndex;
if(sbGet_Buzzer_Test() == true)
{
if(bCount == 0)
{
BUZZER_ON();
bCount = 1;
}
else
{
BUZZER_OFF();
bCount = 0;
}
}
}
if(wLCD_Event & (1 << eLCDKeyEnter))
{
if(sbGet_Buzzer_Test() == false)
{
sSet_Buzzer_Test(true);
}
}
if(wLCD_Event & (1 << eLCDKeyEsc))
{
sSet_Buzzer_Test(false);
BUZZER_OFF();
bWindowIndex = 1; //选择界面
return;
}
}
}
//******************************************************************************
// Function : LCD_Show_String
// Input : x-line,0~3,y-char colum,0~15
// string-pointer to string,invert-not use
// Output : none
// Description : Display a string on one line
//******************************************************************************
void LCD_Show_String(INT8U X,INT8U Y,INT8U *string,INT8U invert)
{
INT16U wTemp;
const INT8U *wStrPtr;
INT8U wPointerX;
INT8U wPointerY;
wPointerX = X;
wPointerY = Y;
while(*string != '\0')
{
wTemp = *string++;
if(wTemp < 0x0080)
{
wStrPtr = FindStringIndexFromCode(wTemp);
LCD_Write_Char(wPointerX,wPointerY,wStrPtr);
wPointerY +=1;
}
else
{
wTemp = wTemp<<8;
wTemp |= *string++;
wStrPtr = FindStringIndexFromCode(wTemp);
LCD_Write_Word(wPointerX,wPointerY,wStrPtr);
wPointerY +=2;
}
}
}
//******************************************************************************
// Function : Win_Show_Screen
// Input : Ptr-pointer to display frame
// Output : none
// Description : Display a Window on LCD
//******************************************************************************
void Win_Show_Screen(const struct LCDString *Ptr)
{
INT8U wTemp;
for(wTemp = 0;wTemp < 4;wTemp++)
{
LCD_Show_String(Ptr->wXPointer,Ptr->wYPointer,Ptr->StrPointer,0);
Ptr++;
}
}
//******************************************************************************
// Function : FindStringIndexFromCode
// Input : wCode-mask of a char or word
// Output : pointer to the mask array
// Description : find the mask array address for given char/word code
//******************************************************************************
const INT8U *FindStringIndexFromCode(INT16U wCode)
{
INT16U Low;
INT16U High;
INT16U Mid;
const struct DataBaseIndex *pDB;
INT16U wData;
Low = 0;
High = wDataBaseLength - 1;
while(Low <= High)
{
Mid = (Low + High) >> 1;
pDB = &DataBaseIndexList[Mid];
wData = pDB -> Code;
if(wCode == wData)
{
return(pDB->Ptr);
}
else if(wCode < wData)
{
High = Mid - 1;
}
else
{
Low = Mid + 1;
}
}
return(0);
}
//******************************************************************************
// Function : Initial_DataBaseLength
// Input : none
// Output : length of the database
// Description : calculate the length of the database
//*******************************************************************************
INT16U Initial_DataBaseLength(void)
{
INT16U wLength = 0;
const struct DataBaseIndex *DataBasePtr = DataBaseIndexList;
while(DataBasePtr->Code != 0xFFFF)
{
wLength++;
DataBasePtr++;
}
return(wLength);
}
//******************************************************************************
// Function : Int2Char
// Input : wData-data to be converted,Ptr-pointer to buffer
// wWidth-length to convert
// Output : none
// Description : convert decimal to char
//*******************************************************************************
void Int2Char(INT16U wData,INT8U *Ptr,INT8U wWidth)
{
if(wWidth == 1)
{
*Ptr++ = wData + '0';
}
else if(wWidth == 2)
{
*Ptr++ = wData/10 + '0';
*Ptr++ = wData%10 + '0';
}
else if(wWidth == 3)
{
*Ptr++ = wData/100;
*Ptr++ = (wData%100)/10 + '0';
*Ptr++ = (wData%10) + '0';
}
else if(wWidth == 4)
{
*Ptr++ = wData/1000 + '0';
*Ptr++ = (wData%1000)/100 + '0';
*Ptr++ = (wData%100)/10 + '0';
*Ptr++ = (wData%10) + '0';
}
}
//******************************************************************************
// Function : LCD_Show_Time
// Input : none
// Output : none
// Description : Display real time on lcd
//*******************************************************************************
INT8U wTemp[20];
INT8U *Ptr;
void LCD_Show_Time(void)
{
Ptr = &wTemp[0];
Int2Char(20,Ptr,2);
Ptr += 2;
Int2Char(bYear,Ptr,2);
Ptr += 2;
*Ptr++ = '-';
Int2Char(bMonth,Ptr,2);
Ptr += 2;
*Ptr++ = '-';
Int2Char(bDate,Ptr,2);
Ptr += 2;
*Ptr++ = ' ';
Int2Char(bMinute,Ptr,2);
Ptr += 2;
*Ptr++ = ':';
Int2Char(bSecond,Ptr,2);
Ptr += 2;
*Ptr++ = '\0';
LCD_Show_String(3,0,wTemp,0);
}
//===============================END OF FILE==================================//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -