c51 单片机种统计按键次数

来源:百度知道 编辑:UC知道 时间:2024/05/11 18:21:16
c51 单片机中如何统计4X4键盘的按键次数
怎么获取啊,给个例子看看就能明白了

2楼的,你的链接我打不开

设置个全局变量,放在键盘识别函数中,并把它设定为用后自加。这样每次按下按键时调用键盘函数时候它就会自加,到时候调出来显示就可以了
例如:
unsigned char num=0;(如果你的num可能大于255的话就用int)
unsigned char keyscan(void) //键盘输入函数
{
unsigned char key;
……
省略
……
return key;
num++;
}

main()
{
unsigned char key;
……
……
key=keyscan();
……
……
}
楼上主程序似乎太臃肿了,键盘扫描最好还是写成函数形式。

在循环中加一个自加变量不就行了

http://hi.baidu.com/%B4%AC%B3%A42127/modify/blog/5778f72cc9631e3d349bf711
看看 我的钟表吧

定义一个全局变量就行了,按键就加1

给你这个,我自己写的,想法很简单,原来不是做过4*4按键任意0~f数字嘛,吧中间的switch语句中case后面的num现实特定的数字换成自加1就可以了...希望能对你有帮助
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^6;
sbit wela=P2^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x