📄 key continous.c
字号:
#include <reg52.h>
#include <lcd.h>
#define uchar unsigned char
#define uint unsigned int
#define N 100
uchar code table[18]={"0123456789abcdef0"};
void delay(uint k)
{
uint a,b;
for(a=0;a<k;a++)
for(b=0;b<125;b++)
{
}
}
uchar keyword(void)
{
uchar row,queue,key=16,sccode=0;
P1=0xf0;
if((P1&0xf0)!=0xf0)
{
delay(10);
if((P1&0xf0)!=0xf0)
{
row=0xfe;
while((row&0x10)!=0)
{
P1=row;
if((P1&0xf0)!=0xf0)
{
queue=P1&0xf0;
switch(queue)
{
case 0xe0: key=0+sccode;break;
case 0xd0: key=1+sccode;break;
case 0xb0: key=2+sccode;break;
case 0x70: key=3+sccode;break;
}
return(key);
}
else
row=(row<<1)|0x01;
sccode+=4;
}
}
}
return(key);
}
void main(void)
{
uchar t,b[N],c[2];
uchar temp;
uchar i;
lcd_initial();
delay(1); // 用这个delay,是消除因gotoxy函数没有执行完而print函数就开始执行从而
gotoxy(15); // 在液晶屏起始位置出现0字的现象
print("0");
i=0;
while(1)
{
t=keyword();
if(t==11)
{
i=0;
lcd_write(lcd_command,lcd_clear_screen);
delay(10); // 用delay()满足清零需要的时序?不然下面的print函数就不会执行,lcd上显示不出清屏后的0值//
lcd_write(lcd_command,lcd_homing);
delay(10);
gotoxy(15);
print("0");
}
c[0]=table[t];
if(t<=9&&t>=0)
{
if(i>0&&i<8)
{
gotoxy(15-i);
print(b);
}
gotoxy(15);
print(c);
temp=P1; // 保证一次按键就只执行一次功能
temp=temp&0xf0;
while((temp&0xf0)!=0xf0) // 这里要特别注意:不能引用lcd-write函数将数据写进去
{ // 可能是主函数没有将其调入进去
temp=P1;
temp=temp&0xf0;
}
b[i]=c[0];
i++;
b[i]='\0';
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -