📄 rfid_rtcmenu.c
字号:
// $Id: rfid_RtcMenu.c,v 1.3 2006/10/12 14:00:54 tprescott Exp $
/*************************************************************
Project : atml_RtcMenu.c
Date : 9/08/2006
Author : Toby Prescott
Company : Atmel
Comments: AVR Studio GCC
Revisions:
v1.0 - Started written for CodeVision
v2.6 - Clean for WinAVR
*************************************************************/
#include "rfid_RtcMenu.h"
// Declare your global variables here
unsigned char cClockFormat = CLOCK_12, cDateFormat = DATE_US;
// *******************************************************************************
// Menu displays the Real-Time Clock and Date in specified formats
// ******************************************************************************/
void rtcMenu_Display(void)
{
unsigned char currentPos=0, nextPos=0;
upDate = 0;
uio_Release();
while(cButton != IO_F1 && cButton != IO_F2 && cButton != IO_F3 && cButton != IO_F4)
{
// Menu Display
if(currentPos != nextPos || upDate == 0)
{
currentPos = nextPos;
lcd_clear_area(SCRN_LEFT+1,12,SCRN_RIGHT-1,SCRN_BOTTOM-1);
lcd_put_fString(4, 22, PSTR("Time"));
lcd_put_fString(4, 40, PSTR("Date"));
if(currentPos == 0){lcd_invert_area(3, 21, 27, 29);}
else if(currentPos == 1){lcd_invert_area(3, 39, 27, 47);}
lcd_update(SCRN_TOP,SCRN_BOTTOM);
upDate = 1;
}
// End display
uio_Get();
switch(currentPos){
case 0:
if(cButton == IO_RIGHT){rtcMenu_SetClockMenu(55, 22);}
else if(cButton == IO_ENTER)
{
if (cClockFormat == CLOCK_12){cClockFormat = CLOCK_24;} // if 12H clock
else {cClockFormat = CLOCK_12;} // 12H clock
rtc_SetClockFormat(cClockFormat);
}
else if(cButton == IO_DOWN){nextPos = 1;}
break;
case 1:
if(cButton == IO_RIGHT){rtcMenu_SetDateMenu(55, 40);}
else if(cButton == IO_ENTER)
{
if (cDateFormat == DATE_ASIA){cDateFormat = DATE_US;} // if 12H clock
else {cDateFormat++;}
}
else if(cButton == IO_UP){nextPos = 0;}
break;
default:
break;
}
if(cButton>0 && cButton<6){uio_Release();}
rtcMenu_ShowClock(55, 22);
rtcMenu_ShowDate(55, 40);
}
uio_Release();
}
// *******************************************************************************
// Formats and Displays the Clock
// ******************************************************************************/
void rtcMenu_ShowClock(unsigned char left, unsigned char top)
{
unsigned char HH, HL, MH, ML, SH, SL;
unsigned char endPos;
if (cClockFormat == CLOCK_12) // if 12H clock
HH = bcd_CHAR2BCD2(TBL_CLOCK_12[rtc_GetClock(HOUR)]);
else
HH = bcd_CHAR2BCD2(rtc_GetClock(HOUR));
HL = (HH & 0x0F) + '0';
HH = (HH >> 4) + '0';
MH = bcd_CHAR2BCD2(rtc_GetClock(MINUTE));
ML = (MH & 0x0F) + '0';
MH = (MH >> 4) + '0';
SH = bcd_CHAR2BCD2(rtc_GetClock(SECOND));
SL = (SH & 0x0F) + '0';
SH = (SH >> 4) + '0';
endPos = left;
lcd_clear_area(endPos-1,top-1,SCRN_RIGHT-5,top+8);
endPos = lcd_put5x7_Char(endPos, top, HH);
endPos = lcd_put5x7_Char(endPos, top, HL);
endPos = lcd_put5x7_Char(endPos, top, ':');
endPos = lcd_put5x7_Char(endPos, top, MH);
endPos = lcd_put5x7_Char(endPos, top, ML);
endPos = lcd_put5x7_Char(endPos, top, ':');
endPos = lcd_put5x7_Char(endPos, top, SH);
endPos = lcd_put5x7_Char(endPos, top, SL);
if (cClockFormat == CLOCK_12 && rtc_GetClock(HOUR) < 12) // if 12H clock
{
lcd_put_fString(endPos+1, top, PSTR(" AM"));
}
else if (cClockFormat == CLOCK_12 && rtc_GetClock(HOUR) >= 12)
{
lcd_put_fString(endPos+1, top, PSTR(" PM"));
}
else{lcd_put_fString(endPos+1, top, PSTR(" "));}
lcd_update(SCRN_TOP,SCRN_BOTTOM);
}
// *******************************************************************************
// Formats and Displays the Date
// ******************************************************************************/
void rtcMenu_ShowDate(unsigned char left, unsigned char top)
{
unsigned char YH, YL, MH, ML, DH, DL;
unsigned char endPos;
YH = bcd_CHAR2BCD2(rtc_GetDate(YEAR));
YL = (YH & 0x0F) + '0';
YH = (YH >> 4) + '0';
MH = bcd_CHAR2BCD2(rtc_GetDate(MONTH));
ML = (MH & 0x0F) + '0';
MH = (MH >> 4) + '0';
DH = bcd_CHAR2BCD2(rtc_GetDate(DAY));
DL = (DH & 0x0F) + '0';
DH = (DH >> 4) + '0';
endPos = left;
lcd_clear_area(endPos-1,top-1,SCRN_RIGHT-5,top+8);
if (cDateFormat == DATE_US)
{
endPos = lcd_put5x7_Char(endPos, top, MH);
endPos = lcd_put5x7_Char(endPos, top, ML);
endPos = lcd_put5x7_Char(endPos, top, '/');
endPos = lcd_put5x7_Char(endPos, top, DH);
endPos = lcd_put5x7_Char(endPos, top, DL);
endPos = lcd_put5x7_Char(endPos, top, '/');
endPos = lcd_put5x7_Char(endPos, top, '2');
endPos = lcd_put5x7_Char(endPos, top, '0');
endPos = lcd_put5x7_Char(endPos, top, YH);
endPos = lcd_put5x7_Char(endPos, top, YL);
}
else if (cDateFormat == DATE_EU)
{
endPos = lcd_put5x7_Char(endPos, top, DH);
endPos = lcd_put5x7_Char(endPos, top, DL);
endPos = lcd_put5x7_Char(endPos, top, '/');
endPos = lcd_put5x7_Char(endPos, top, MH);
endPos = lcd_put5x7_Char(endPos, top, ML);
endPos = lcd_put5x7_Char(endPos, top, '/');
endPos = lcd_put5x7_Char(endPos, top, '2');
endPos = lcd_put5x7_Char(endPos, top, '0');
endPos = lcd_put5x7_Char(endPos, top, YH);
endPos = lcd_put5x7_Char(endPos, top, YL);
}
else if (cDateFormat == DATE_ASIA)
{
endPos = lcd_put5x7_Char(endPos, top, '2');
endPos = lcd_put5x7_Char(endPos, top, '0');
endPos = lcd_put5x7_Char(endPos, top, YH);
endPos = lcd_put5x7_Char(endPos, top, YL);
endPos = lcd_put5x7_Char(endPos, top, '-');
endPos = lcd_put5x7_Char(endPos, top, MH);
endPos = lcd_put5x7_Char(endPos, top, ML);
endPos = lcd_put5x7_Char(endPos, top, '-');
endPos = lcd_put5x7_Char(endPos, top, DH);
endPos = lcd_put5x7_Char(endPos, top, DL);
}
lcd_update(SCRN_TOP,SCRN_BOTTOM);
}
// *******************************************************************************
// Routine to allow the Clock to be set
// ******************************************************************************/
void rtcMenu_SetClockMenu(unsigned char left, unsigned char top)
{
unsigned char currentPos, nextPos=0;
unsigned char sHour, sMinute, sSecond;
unsigned char HH, HL, MH, ML, SH, SL;
unsigned char startPos, endPos, quitFlag = 0;
nextPos = 1;
sHour = rtc_GetClock(HOUR);
sMinute = rtc_GetClock(MINUTE);
sSecond = rtc_GetClock(SECOND);
startPos = left;
uio_Release();
while(cButton != IO_F1 && cButton != IO_F2 && cButton != IO_F3 && cButton != IO_F4 && quitFlag == 0)
{
currentPos = nextPos;
endPos = startPos;
lcd_clear_area(endPos-1,top-1,SCRN_RIGHT-5,top+8);
if (cClockFormat == CLOCK_12) // if 12H clock
HH = bcd_CHAR2BCD2(TBL_CLOCK_12[sHour]);
else
HH = bcd_CHAR2BCD2(sHour);
HL = (HH & 0x0F) + '0';
HH = (HH >> 4) + '0';
MH = bcd_CHAR2BCD2(sMinute);
ML = (MH & 0x0F) + '0';
MH = (MH >> 4) + '0';
SH = bcd_CHAR2BCD2(sSecond);
SL = (SH & 0x0F) + '0';
SH = (SH >> 4) + '0';
endPos = lcd_put5x7_Char(endPos, top, HH);
endPos = lcd_put5x7_Char(endPos, top, HL);
endPos = lcd_put5x7_Char(endPos, top, ':');
endPos = lcd_put5x7_Char(endPos, top, MH);
endPos = lcd_put5x7_Char(endPos, top, ML);
endPos = lcd_put5x7_Char(endPos, top, ':');
endPos = lcd_put5x7_Char(endPos, top, SH);
endPos = lcd_put5x7_Char(endPos, top, SL);
if (cClockFormat == CLOCK_12 && sHour < 12) // if 12H clock
{
lcd_put_fString(endPos+1, top, PSTR(" AM"));
}
else if (cClockFormat == CLOCK_12 && sHour >= 12)
{
lcd_put_fString(endPos+1, top, PSTR(" PM"));
}
else{lcd_put_fString(endPos+1, top, PSTR(" "));}
if(currentPos == 1){lcd_invert_area(startPos-1, top-1, startPos+11, top+7);}
else if(currentPos == 2){lcd_invert_area(startPos+17, top-1, startPos+29, top+7);}
else if(currentPos == 3){lcd_invert_area(startPos+35, top-1, startPos+46, top+7);}
lcd_update(SCRN_TOP,SCRN_BOTTOM);
uio_Get();
if(cButton == IO_ENTER)
{
rtc_SetClock(HOUR, sHour);
rtc_SetClock(MINUTE, sMinute);
rtc_SetClock(SECOND, sSecond);
quitFlag = 1;
}
switch(currentPos){
case 1:
if(cButton == IO_RIGHT){nextPos = 2;}
else if(cButton == IO_LEFT){;}
else if(cButton == IO_UP)
{
if(sHour == 23){sHour = 0;}
else if(sHour < 23){sHour++;}
}
else if(cButton == IO_DOWN)
{
if(sHour == 0){sHour = 23;}
else if(sHour > 0){sHour--;}
}
break;
case 2:
if(cButton == IO_RIGHT){nextPos = 3;}
else if(cButton == IO_LEFT){nextPos = 1;}
else if(cButton == IO_UP)
{
if(sMinute == 59){sMinute = 0;}
else if(sMinute < 59){sMinute++;}
}
else if(cButton == IO_DOWN)
{
if(sMinute == 0){sMinute = 59;}
else if(sMinute > 0){sMinute--;}
}
break;
case 3:
if(cButton == IO_RIGHT){;}
else if(cButton == IO_LEFT){nextPos = 2;}
else if(cButton == IO_UP)
{
if(sSecond == 59){sSecond = 0;}
else if(sSecond < 59){sSecond++;}
}
else if(cButton == IO_DOWN)
{
if(sSecond == 0){sSecond = 59;}
else if(sSecond > 0){sSecond--;}
}
break;
default:
break;
}
if(cButton>0 && cButton<6){uio_Release();}
}
uio_Release();
}
// *******************************************************************************
// Routine to allow the Date to be set
// ******************************************************************************/
void rtcMenu_SetDateMenu(unsigned char left, unsigned char top)
{
unsigned char currentPos, nextPos=0;
unsigned char sYear, sMonth, sDay;
unsigned char YH, YL, MH, ML, DH, DL;
unsigned char startPos, endPos, quitFlag = 0;
nextPos = 1;
sYear = rtc_GetDate(YEAR);
sMonth = rtc_GetDate(MONTH);
sDay = rtc_GetDate(DAY);
startPos = left;
uio_Release();
while(cButton != IO_F1 && cButton != IO_F2 && cButton != IO_F3 && cButton != IO_F4 && quitFlag == 0)
{
currentPos = nextPos;
endPos = startPos;
lcd_clear_area(endPos-1,top-1,SCRN_RIGHT-5,top+8);
YH = bcd_CHAR2BCD2(sYear);
YL = (YH & 0x0F) + '0';
YH = (YH >> 4) + '0';
MH = bcd_CHAR2BCD2(sMonth);
ML = (MH & 0x0F) + '0';
MH = (MH >> 4) + '0';
DH = bcd_CHAR2BCD2(sDay);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -