key.c
#include "key.h" //把led.h文件包含进来
#include "eepr.h" //把led.h文件包含进来
#include "system.h" //把timer0.h文件包含进来
uchar code smgduan[10]={
0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,
0x90};
uchar DisplayData[4];
uint y=0;
uchar x=0;
uchar num=252;
void Dig_Poll() //数码管显示
{
static uchar i=0;
P0=0xff;//消隐
switch(i) //位选,选择点亮的数码管,
{
case(0):
WEI0=0;WEI1=1;WEI2=1;WEI3=1; break;//显示第0位
case(1):
WEI0=1;WEI1=0;WEI2=1;WEI3=1;;break;//显示第1位
case(2):
WEI0=1;WEI1=1;WEI2=0;WEI3=1;break;//显示第2位
case(3):
WEI0=1;WEI1=1;WEI2=1;WEI3=0;break;//显示第3位
}
P0=DisplayData[i];
i++;
if(i>3){
i=0;}
}
uint KeyScan () //按键扫描函数
{
static uint timer=0;
if(k1==0)
{
timer++;
if(timer==10){
return(1);} //定时10毫秒返回KEY1
else if(timer==1000){
timer=500;return(1);} //否则长按不停加1
}
else if(k2==0)
{
timer++;
if(timer==10){
return(2);} //定时10毫秒返回KEY2
//else if(timer==1000){
timer=900;return(KEY2);