?? deal.h
字號(hào):
#define KEYPIN PINC
#define KEYDDR DDRC
#define KEYPORT PORTC
#define KEYMASK 0x0f
uchar KeyTask = 0;
uchar Keybuf = 0;
uchar Keydata = 0;
void InitalKey(void)
{ KEYDDR = KEYMASK; //高4位輸入,低4位輸出
KEYPORT = ~KEYMASK; //輸入口帶上拉,輸出口為低電平
}
/**********************************************************
*原型:uchar ScanKey(void)
*功能:掃描鍵盤(pán)模塊
*說(shuō)明:采用算法進(jìn)行掃描,不循環(huán)等待。
*參數(shù):無(wú)
*返回:uchar按鍵數(shù)據(jù)
**********************************************************/
uchar ScanKey(void)
{ uchar temp,i;
switch(KeyTask)
{ case 0:/***有按鍵按下嗎?***/
KEYPORT = ~KEYMASK;
if( (KEYPIN&(~KEYMASK)) != (~KEYMASK) )
{ KeyTask=1; } /***延時(shí)一個(gè)系統(tǒng)時(shí)間***/
break;
case 1: /***鍵按下去抖延時(shí)***/
KeyTask=2; /***延時(shí)一個(gè)系統(tǒng)時(shí)間***/
break;
/***延時(shí)一個(gè)系統(tǒng)時(shí)間***/
case 2: /***鍵值判斷***/
if( (KEYPIN&(~KEYMASK)) != (~KEYMASK) )
{ temp = 0x01;
for( i=0; i<4; i++ )
{ KEYPORT |= KEYMASK; //輸出全為高電平
KEYPORT &= ~temp; //輸出某個(gè)為低電平
asm("nop"); asm("nop"); asm("nop"); asm("nop");
if( (KEYPIN&(~KEYMASK)) != (~KEYMASK) )
{ Keybuf = (KEYPIN&(~KEYMASK)) + temp;
KeyTask = 3; KEYPORT = ~KEYMASK; return(1);
}
temp = temp<<1;
}
}
KEYPORT = ~KEYMASK;
KeyTask=0; /*抖動(dòng)*/
break;
case 3: /***有松開(kāi)嗎?***/
if( (KEYPIN&(~KEYMASK)) == (~KEYMASK) )
{ KeyTask=4;
}
else
{ Keycheck++;
if (Keycheck>=110)
{ Keycheck = 100; return(1); }
}
break;
case 4: /***鍵松開(kāi)去抖延時(shí)***/
KeyTask=5; /***延時(shí)一個(gè)系統(tǒng)時(shí)間***/
break;
case 5: /***鍵值判斷***/
if( (KEYPIN&(~KEYMASK)) == (~KEYMASK) )
{ KeyTask=0; Keycheck = 0; } /*去按鍵檢測(cè)開(kāi)始*/
else
{ KeyTask=3; } /*抖動(dòng)*/
break;
}
return(0); //沒(méi)檢測(cè)到按鍵
}
int Isleapyear(int year)
{
if ((year%4==0)&&(year%100!=0)||(year%400==0))
return (1);
else
return (0);
}
void Adjust(void)
{int i=8;
switch(Position)
{
case 0:LCD_write_char(0x0c,0);
break;
case 1:
Time.year++;
break;
case 2:
Time.month++;
if(Time.month>=13) Time.month=1;
break;
case 3:
Time.day++;
switch(Time.month)
{
case 1:if (Time.day==32) Time.day=1;
break;
case 2:if(Isleapyear(Time.year)==1)
{ if (Time.day==30) Time.day=1; }
else if(Time.day==29)
Time.day=1;
break;
case 3:if (Time.day==32) Time.day=1;
break;
case 4:if (Time.day==31) Time.day=1;
break;
case 5:if (Time.day==32) Time.day=1;
break;
case 6:if (Time.day==31) Time.day=1;
break;
case 7:if (Time.day==32) Time.day=1;
break;
case 8:if (Time.day==32) Time.day=1;
break;
case 9:if (Time.day==31) Time.day=1;
break;
case 10:if (Time.day==32) Time.day=1;
break;
case 11:if (Time.day==31) Time.day=1;
break;
case 12:if (Time.day==32) Time.day=1;
break;
default:{}break;
}
break;
case 4:
Time.hour++;
if(State==0)
{if (Time.hour>=24) Time.hour=0;}
else if(Time.hour>=13)
{Time.hour=0;}
break;
case 5:
Time.minute++;
if (Time.minute>=60) Time.minute=0;
break;
case 6:
Time.second=0;
break;
default:
break;
}
}
void DealKey(void)
{
switch( Keybuf )
{ case KEYONE: Position++;
if (Position==7) Position=0;
if(Position!=0)
{
LCD_write_char(0x02,0);
switch(Position)
{case 1:LCD_write_char(0x83,0);
LCD_write_char(0x0d,0);
break;
case 2:LCD_write_char(0x86,0);
LCD_write_char(0x0d,0);
break;
case 3:LCD_write_char(0x89,0);
LCD_write_char(0x0d,0);
break;
case 4:LCD_write_char(0xc1,0);
LCD_write_char(0x0d,0);
break;
case 5:LCD_write_char(0xc4,0);
LCD_write_char(0x0d,0);
break;
case 6:LCD_write_char(0xc7,0);
LCD_write_char(0x0d,0);
break;
default:{}break;
}
}
break;
case KEYTWO: Adjust();
break;
case KEYTHREE:if (State==0)
{State=1;}
else
{State=0;}
break;
default:{}break;
}
}
void DispTime(void)
{
LCD_write_uint8(0, 0,Time.year, 4);
LCD_write_string(4,0,"-");
LCD_write_uint8(5, 0, Time.month, 2);
LCD_write_string(7,0,"-");
LCD_write_uint8(8, 0, Time.day, 2);
if(State==0)
{LCD_write_uint8(0, 1, Time.hour, 2);}
if((State==1)&&(Time.hour>=13))
{LCD_write_uint8(0, 1, Time.hour-12, 2);}
else
{LCD_write_uint8(0,1,Time.hour,2);}
LCD_write_string(2,1,":");
LCD_write_uint8(3, 1, Time.minute, 2);
LCD_write_string(5,1,":");
LCD_write_uint8(6, 1, Time.second, 2);
if(State==1)
{ if(Time.hour>=13)
{LCD_write_string(9,1,"PM");}
else
{LCD_write_string(9,1,"AM");}
}
else
{LCD_write_string(9,1," ");}
}
void TimeAdd(void)
{if(Time.year>2100)
{Time.year=2007;}
Time.second++;
if( Time.second == 60 )
{ Time.second = 0; Time.minute++;
if( Time.minute == 60 )
{ Time.minute = 0; Time.hour++;
if( Time.hour == 24 )
{ Time.hour = 0; Time.day++;
//////////////////////////////////////////////
if( Time.month == 2 )
{ if( (Time.year%4) == 0 ) //閏年28天
{ if(Time.day==29){Time.day=0;Time.month++;if(Time.month==12){Time.month=0;Time.year++;}} }
else //29天
{ if(Time.day==30){Time.day=0;Time.month++;if(Time.month==12){Time.month=0;Time.year++;}} }
}
else if( (Time.month==4) || (Time.month==6) || (Time.month==9) || (Time.month==11) )
{ if(Time.day==31){Time.day=0;Time.month++;if(Time.month==12){Time.month=0;Time.year++;}} }
else
{ if(Time.day==32){Time.day=0;Time.month++;if(Time.month==12){Time.month=0;Time.year++;}} }
//////////////////////////////////////////////
}
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -