📄 key.h
字号:
//#ifndef _KEY
//#define _KEY
/***********************键盘预定义******************************************/
#define up_array 0x01
#define down_array 0x02
#define clock_array 0x03
#define null 0
/********************************************************************************************
* 函数名称:Key_Scan()
* 功 能:键盘扫描
* 入口参数:无
* 出口参数:键值
*********************************************************************************************/
uchar Key_Scan()
{
if( (P0&0x07) != 0x07 ) //判断按键
{
Delay(4); //消除抖动
if( (P0&0x07) != 0x07 )
{
switch (P0&0x07) //将按键码转换成键值
{
case 0x06: return up_array;
case 0x05: return down_array;
case 0x03: return clock_array;
default : return null;
}
}
}
return null;
}
/********************************************************************************************
* 函数名称:Key_Idle()
* 功 能:键盘松开
* 入口参数:无
* 出口参数:无
*********************************************************************************************/
void Key_Idle()
{
while( (P0&0x07) != 0x07 );
}
/********************************************************************************************
* 函数名称:Key_Set_Time()
* 功 能:键盘设定时间
* 入口参数:clock_time[6]指针
* 出口参数:无
*********************************************************************************************/
void Key_Set_Time( uchar *point)
{
uchar *i;
i = point;
Key_Idle();
while(1)
{
uchar second;
{ Lcd_Character_16X16(6, 48, null_logo); Delay(8); Lcd_Clock(i); } //闪烁指示second更改
(*point) &= 0x7f;
second =( (*point >>4)*10 ) + ( (*point)&0x0f ); //BCD 转 HEX
switch( Key_Scan() ) //调整second
{
case up_array:
{
second ++ ; if( second == 60 ) second=0;
(*point) = second/10 <<4 ; (*point) = (*point) | (second%10); //HEX 转 BCD
Lcd_Clock(i); Key_Idle();
}
case down_array:
{
if(second==0) second = 60; second --; // if( second == 0) second =59;
(*point) = second/10 <<4 ; (*point) = (*point) | (second%10); //HEX 转 BCD
Lcd_Clock(i); Key_Idle();
}
break;
case clock_array:
{//调整时
//******************************************************************************************************************************************************
point++; //指向分
Key_Idle();
while(1)
{
uchar minute;
{ cs1=1;cs2=0; Lcd_Character_16X16(6, 24, null_logo); Delay(8); Lcd_Clock(i); } //闪烁指示minute更改
minute = ( (*point >>4)*10 ) + ( (*point)&0x0f ); //BCD 转 HEX
switch( Key_Scan() ) //调整分
{
case up_array:
{
minute ++ ; if( minute == 60 ) minute=0;
(*point) = minute/10 <<4 ; (*point) = (*point) | ( minute%10); //HEX 转 BCD
Lcd_Clock(i); Key_Idle();
}
break;
case down_array:
{if(minute==0) minute = 60; minute --; if( minute == 0) minute =59;
(*point) = minute/10 <<4 ; (*point) = (*point) | ( minute%10); //HEX 转 BCD
Lcd_Clock(i); Key_Idle();
}
break;
//******************************************************************************************************************************************************
case clock_array: //调整时
{
point++; //指向时
Key_Idle();
while(1)
{
uchar hour;
{ cs1=1;cs2=0; Lcd_Character_16X16(6, 0, null_logo); Delay(8); Lcd_Clock(i); } //闪烁指示小时更改
hour = ( (*point >>4)*10 ) + ( (*point)&0x0f ); //BCD 转 HEX
switch( Key_Scan())
{
case up_array:
{ hour ++; if(hour == 24) hour = 0;
(*point) = hour/10 <<4 ; (*point) = (*point) | (hour%10); //HEX 转 BCD
Lcd_Clock(i); Key_Idle();
}
break;
case down_array:
{ if(hour == 0) hour = 24; hour --; if(hour == 0) *point =23;
(*point) = hour/10 <<4 ; (*point) = (*point) | (hour%10); //HEX 转 BCD
Lcd_Clock(i); Key_Idle();
}
break;
//******************************************************************************************************************************************************
case clock_array: //调整日
{
point++; //指向日
Key_Idle();
while(1)
{
uchar day;
{ cs1=1;cs2=0; Lcd_Character_16X16(2,48, null_logo); Delay(8); Lcd_Clock(i); } //闪烁指示日更改
day = ( (*point >>4)*10 ) + ( (*point)&0x0f ); //BCD 转 HEX
switch(Key_Scan())
{
case up_array:
{ day ++; if(day == 32) day = 1;
(*point) = day/10 <<4 ; (*point) = (*point) | (day%10); //HEX 转 BCD
Lcd_Clock(i); Key_Idle();
}
break;
case down_array:
{ if(day == 0) day= 31; day --; if(day == 0) day=31;
(*point) = day/10 <<4 ; (*point) = (*point) | (day%10); //HEX 转 BCD
Lcd_Clock(i); Key_Idle();
}
break;
//******************************************************************************************************************************************************
case clock_array: //调整月
{
point++; //指向月
Key_Idle();
while(1)
{
uchar month;
{ cs1=1;cs2=0; Lcd_Character_16X16(2,24, null_logo); Delay(8); Lcd_Clock(i); } //闪烁指示月更改
month = ( (*point >>4)*10 ) + ( (*point)&0x0f ); //BCD 转 HEX
switch(Key_Scan())
{
case up_array:
{ month ++; if(month == 13) month= 1;
(*point) = month/10 <<4 ; (*point) = (*point) | (month%10); //HEX 转 BCD
Lcd_Clock(i); Key_Idle();
}
break;
case down_array:
{ if(month==0) month = 12; month --; if(month==0) month = 12;
(*point) = month/10 <<4 ; (*point) = (*point) | (month%10); //HEX 转 BCD
Lcd_Clock(i); Key_Idle();
}
break;
//******************************************************************************************************************************************************
case clock_array: //调整月
{
point++;
point++; //指向年
Key_Idle();
while(1)
{
uchar year;
{ cs1=1;cs2=0; Lcd_Character_16X16(2,0, null_logo);Delay(8); Lcd_Clock(i); } //闪烁指示月更改
year = ( (*point >>4)*10 ) + ( (*point)&0x0f ); //BCD 转 HEX
switch(Key_Scan())
{
case up_array:
{ year ++; if(year == 100) year= 0;
(*point) = year/10 <<4 ; (*point) = (*point) | (year%10); //HEX 转 BCD
Lcd_Clock(i); Key_Idle();
}
break;
case down_array:
{ if(year==0) year=100 ; year--; if(year==0) year=100;
(*point) = year/10 <<4 ; (*point) = (*point) | (year%10); //HEX 转 BCD
Lcd_Clock(i); Key_Idle();
}
break;
//******************************************************************************************************************************************************
case clock_array: { Key_Idle(); goto loop; }
break;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
loop: Key_Idle();
}
/********************************************************************************/
//#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -