从单片机基础到程序框架(全集 2019pdf版).pdf - 第624页

void KeySc an(void) //按键 底层的驱动扫 描函数,放在 定时中断函数 里 { static unsig ned char Su8KeyL ock1; static unsig ned int Su1 6KeyCnt1; static unsig ned char Su8KeyL ock2; static unsig ned int Su1 6KeyCnt2; if(0!=KEY_ INPUT1) { Su8KeyL…

100%1 / 836
vGu16UpdateTimerCnt=10; //每 10ms 更新显示一次当前倒计时的时间
vGu8UpdateTimerFlag=1;
Gu8RunStep=1; //跳转到每 10ms 更新显示一次的步骤里
break;
case 1: //每 10ms 更新一次显示,确保实时显示当前倒计时的时
if(0==vGu16UpdateTimerCnt) //每 10ms 更新显示一次当前倒计时的时间
{
vGu8UpdateTimerFlag=0;
vGu16UpdateTimerCnt=10; //重置定时器,为下一 10ms 更新做准备
vGu8UpdateTimerFlag=1;
Gu8WdUpdate=1; //整屏更新一次显示当前倒计时的时间
if(0==vGu32CountdownTimerCnt) //如果倒计时的时间到,则跳转到结束的步骤
{
Gu8RunStep=2; //跳转到倒计时结束的步骤
}
}
break;
case 2: //倒计时结束的步骤
//Gu8RunStatus=0; //这行代码注释掉,让每次新启动之前都必须按一次 K1 复位按键才有效
Gu8RunStart=0; //倒计时的运行步骤的停止
Gu8RunStep=0; //总运行步骤归零。建议跟 vGu8RunStart 成双成对出
vGu8BeepTimerFlag=0;
vGu16BeepTimerCnt=VOICE_TIME; //蜂鸣器发出“滴”一声
vGu8BeepTimerFlag=1;
Gu8WdUpdate=1; //整屏更新一次显示当前倒计时的时间
break;
}
}
void KeyScan(void) //按键底层的驱动扫描函数,放在定时中断函数
{
static unsigned char Su8KeyLock1;
static unsigned int Su16KeyCnt1;
static unsigned char Su8KeyLock2;
static unsigned int Su16KeyCnt2;
if(0!=KEY_INPUT1)
{
Su8KeyLock1=0;
Su16KeyCnt1=0;
}
else if(0==Su8KeyLock1)
{
Su16KeyCnt1++;
if(Su16KeyCnt1>=KEY_FILTER_TIME)
{
Su8KeyLock1=1;
vGu8KeySec=1;
}
}
if(0!=KEY_INPUT2)
{
Su8KeyLock2=0;
Su16KeyCnt2=0;
}
else if(0==Su8KeyLock2)
{
Su16KeyCnt2++;
if(Su16KeyCnt2>=KEY_FILTER_TIME)
{
Su8KeyLock2=1;
vGu8KeySec=2;
}
}
}
void DisplayScan(void) //数码管底层的驱动扫描函数,放在定时中断函数里
{
static unsigned char Su8GetCode;
static unsigned char Su8ScanStep=1;
if(0==vGu16ScanTimerCnt)
{
P0=0x00;
P1_0=1;
P1_1=1;
P1_2=1;
P1_3=1;
switch(Su8ScanStep)
{
case 1:
Su8GetCode=Cu8DigTable[vGu8Display_Righ_1];
if(1==vGu8Display_Righ_Dot_1)
{
Su8GetCode=Su8GetCode|0x80;
}
P0=Su8GetCode;
P1_0=0;
P1_1=1;
P1_2=1;
P1_3=1;
break;
case 2:
Su8GetCode=Cu8DigTable[vGu8Display_Righ_2];
if(1==vGu8Display_Righ_Dot_2)
{
Su8GetCode=Su8GetCode|0x80;
}
P0=Su8GetCode;
P1_0=1;
P1_1=0;
P1_2=1;
P1_3=1;
break;
case 3:
Su8GetCode=Cu8DigTable[vGu8Display_Righ_3];
if(1==vGu8Display_Righ_Dot_3)
{
Su8GetCode=Su8GetCode|0x80;
}