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

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; static unsig ned char Su8Key…

100%1 / 836
vGu8Display_Righ_Dot_2=0;
vGu8Display_Righ_Dot_1=0;
Gu8PartUpdate_1=1; //局部 1 更新显示
Gu8PartUpdate_2=1; //局部 2 更新显示
Gu8PartUpdate_3=1; //局部 3 更新显示
}
if(1==Gu8PartUpdate_1) //局部 1 更新显示,速度
{
Gu8PartUpdate_1=0; //及时清零,只更新一次显示即可,避免一直进来更新显示
Su8Temp_4=Gu8RunSpeed;
vGu8Display_Righ_4=Su8Temp_4; //过渡需要显示的数据到底层驱动变量
}
if(1==Gu8PartUpdate_2) //局部 2 更新显示,方向
{
Gu8PartUpdate_2=0; //及时清零,只更新一次显示即可,避免一直进来更新显示
if(0==Gu8RunDirection) //往右
{
Su8Temp_3=13; //数码管的字模转换表序号 13 代表显示字符“r”
}
else
{
Su8Temp_3=12; //数码管的字模转换表序号 12 代表显示字符“L”
}
vGu8Display_Righ_3=Su8Temp_3; //过渡需要显示的数据到底层驱动变量
}
if(1==Gu8PartUpdate_3) //局部 3 更新显示,计数
{
Gu8PartUpdate_3=0; //及时清零,只更新一次显示即可,避免一直进来更新显示
Su8Temp_2=Gu8RunCounter%100/10; //提取十位
Su8Temp_1=Gu8RunCounter%10/1; //提取个位
vGu8Display_Righ_2=Su8Temp_2; //过渡需要显示的数据到底层驱动变量
vGu8Display_Righ_1=Su8Temp_1; //过渡需要显示的数据到底层驱动变量
}
}
void KeyScan(void) //按键底层的驱动扫描函数,放在定时中断函数
{
static unsigned char Su8KeyLock1;
static unsigned int Su16KeyCnt1;
static unsigned char Su8KeyLock2;
static unsigned int Su16KeyCnt2;
static unsigned char Su8KeyLock3;
static unsigned int Su16KeyCnt3;
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;
}
}
if(0!=KEY_INPUT3)
{
Su8KeyLock3=0;
Su16KeyCnt3=0;
}
else if(0==Su8KeyLock3)
{
Su16KeyCnt3++;
if(Su16KeyCnt3>=KEY_FILTER_TIME)
{
Su8KeyLock3=1;
vGu8KeySec=3;
}
}
}
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;