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

Gu8RunStep =1; //跳转到每 1 0ms 更新显示一 次的步 骤里 break; case 1: //每 10 ms 更新一次显 示,确保实时 显示秒表当 前的时间 if(0==vG u16UpdateTi merCnt) //每 10 ms 更新显示一 次当前秒表的 时间 { vGu8Upda teTimerFlag =0; vGu16Upd ateTimerCnt =10; //重置定时器 ,为下一 个 10ms 更新…

100%1 / 836
//Su8Temp_3 提取“个秒”位。
Su8Temp_3=vGu32StopWatchTimerCnt/1000%10; //实际精度是 0.001 秒,但显示精度是 0.01
//Su8Temp_2 提取“百毫秒”位。
Su8Temp_2=vGu32StopWatchTimerCnt/100%10; //实际精度是 0.001 秒,但显示精度 0.01
//Su8Temp_1 提取“十毫秒”位。
Su8Temp_1=vGu32StopWatchTimerCnt/10%10; //实际精度是 0.001 秒,但显示精度是 0.01
//判断数据范围,来决定最高位数码管是否需要显示。
if(vGu32StopWatchTimerCnt<10000) //10.000 秒。实际 4 位数码管最大只能显示 99.99
{
Su8Temp_4=10; //在数码管转换表里,10 代表一个“不显示”的数据
}
//上面先分解数据之后,再过渡需要显示的数据到底层驱动变量里,让过渡的时间越短越好
vGu8Display_Righ_4=Su8Temp_4; //过渡需要显示的数据到底层驱动变量
vGu8Display_Righ_3=Su8Temp_3;
vGu8Display_Righ_2=Su8Temp_2;
vGu8Display_Righ_1=Su8Temp_1;
vGu8Display_Righ_Dot_4=0;
vGu8Display_Righ_Dot_3=1; //保留显示 2 位小数点
vGu8Display_Righ_Dot_2=0;
vGu8Display_Righ_Dot_1=0;
}
}
void RunTask(void) //秒表的应用程序
{
if(0==Gu8RunStart)
{
return; // 如果秒表处于停止状态,则直接退出当前函数,不执行该函数以下的其它代码
}
switch(Gu8RunStep)
{
case 0: //在这个步骤里,主要用来初始化一些参
vGu8UpdateTimerFlag=0;
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; //整屏更新一次显示当前秒表的时
}
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;