📄 key.c
字号:
#include "reg51.h"
#define uchar unsigned char
#define uint unsigend int
xdata uchar delay_1s=0; //连按时间存放
xdata uchar have_down=0; //有下降按件按下
xdata uchar key=0;
xdata uchar oldkey=0; //上次按件号
xdata uchar newkey=0; //本次按件号
xdata uchar eq_time=0;
xdata uchar eq_key_lab=0; //连按标志
xdata uchar inputtime=0;
xdata uchar input_sttime=0;
xdata uchar inputtime_lab=0;
xdata uchar input_sttime_lab=0;
sbit key_16 =P1^7;
sbit key_15 =P1^6;
sbit key_14 =P1^5;
sbit key_13 =P1^4;
sbit ds_1302=P1^5;
extern uchar input_frq_lab;
extern uchar input_sti_lab;
extern uchar frq_wei;
uchar flash=0;
uchar sti_flash=0;
extern void display_char(uchar char_[18],uchar f_cl,uchar b_cl,uchar x,uchar y);
/********************************************************************
函 数 名:ini_int()
功 能: 定时器 和中断初始化
说 明:
调 用: main()
入口参数:无
返 回 值:无
设 计:志博51 AVR PIC 开发板 日 期:2007年11月13日
变 更 日 期:
变 更 备 注:
***********************************************************************/
void ini_int(void)
{
EA=0;
EX0=0;
ET1=0;
EX1=0;
ET0=1;
PT1=0;
PT0=1;
PX1=1;
PX0=0;
IT0=1;
TMOD=0X01;
TH0=0X00;
TL0=0X01;
TR0=1;
EA=1;
}
/********************************************************************
函 数 名:time_int()
功 能:系统定时和按件处理
说 明:
调 用:
入口参数:无
返 回 值:无
设 计:志博51 AVR PIC 开发板 日 期:2007年11月13日
变 更 日 期:
变 更 备 注:
***********************************************************************/
void time_int()interrupt 1
{
uchar a=0;
uchar b=0;
uchar c=0;
uchar d=0;
uchar e=0;
uchar f=0;
uchar j=0;
uchar k=0;
uchar m=0;
TH0=0X00;
TL0=0X00;
P1=0XFF;
if(input_frq_lab)
{
if(inputtime<20)
inputtime++;
else
{
inputtime=0;
if(inputtime_lab==0)
inputtime_lab=1;
else
inputtime_lab=0;
if(inputtime_lab)
{
flash=0;
}
else
flash=1;
}
}
if(input_sti_lab)
{
if(input_sttime<20)
input_sttime++;
else
{
input_sttime=0;
if(input_sttime_lab==0)
input_sttime_lab=1;
else
input_sttime_lab=0;
if(input_sttime_lab)
{
sti_flash=0;
}
else
sti_flash=1;
}
}
if(!key_13)
{
key=13;
goto test_eq;
}
if(!key_14)
{
key=14;
goto test_eq;
}
if(!key_15)
{
key=15;
goto test_eq;
}
if(!key_16)
{
key=16;
goto test_eq;
}
P1=0XF8;
a=(0x01);
m=P1;
for(c=0;c<3;c++)
{
k=~a;
b=(0xff&k);
P1=(b|0x02);
d=(P1>>4);
a=(a<<1);
if(d!=0x0f)
for(e=0;e<4;e++)
{
d=d>>e;
if(!(d&0x01))
{
key=(c*4)+e+1;
goto test_eq;
}
else
key=0;
}
}
test_eq:
if((key!=0))
{
oldkey=key;
key=0;
if(eq_time<60)
eq_time++;
else
{
eq_time=70;
eq_key_lab=0xff;
}
}
else if((oldkey!=0)&&(key==0))
{
newkey=oldkey;
eq_time=0;
oldkey=0;
eq_key_lab=0x00;
}//以上语句为按件处理 单次按下 和连按分析
ds_1302=0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -