从单片机基础到程序框架(全集 2019pdf版).pdf - 第613页
Su16KeyCnt 2=0; } else if(0= =Su8KeyLo ck2) { Su16KeyCnt 2++; if(Su16Key Cnt2>=KEY _FILTER_TIME ) { Su8KeyLock 2=1; vGu8KeySec =2; } } } void Displ ayScan(vo id) //数码管底层 的驱动扫描 函数,放 在定时中断函 数里 { static u nsigned ch ar S…

Gu8RunStep=1; //跳转到每 10ms 更新显示一次的步骤里
break;
case 1: //每 10ms 更新一次显示,确保实时显示秒表当前的时间
if(0==vGu16UpdateTimerCnt) //每 10ms 更新显示一次当前秒表的时间
{
vGu8UpdateTimerFlag=0;
vGu16UpdateTimerCnt=10; //重置定时器,为下一个 10ms 更新做准备
vGu8UpdateTimerFlag=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;
}
P0=Su8GetCode;
P1_0=1;
P1_1=1;
P1_2=0;
P1_3=1;
break;
case 4:
Su8GetCode=Cu8DigTable[vGu8Display_Righ_4];
if(1==vGu8Display_Righ_Dot_4)
{
Su8GetCode=Su8GetCode|0x80;
}
P0=Su8GetCode;
P1_0=1;
P1_1=1;
P1_2=1;
P1_3=0;
break;
}
Su8ScanStep++;
if(Su8ScanStep>4)
{