51单片机4*5键盘程序。

来源:百度知道 编辑:UC知道 时间:2024/07/07 15:45:43
刚刚写了个4*5的键盘程序,不知道对不对,请大家看下,行用P1.0_P1.3,列用P3.0_P3.4,要防抖还要排除按2个键或者多个键。
#include <reg51.h>
unsigned char temph;
unsigned char templ;
sbit INT_0 =P3^2; // 将p3.2外部中断0
bit judge_hitkey();
void system_init(void ); //设定INT0的工作方式
void INT0_SCANkey(); //外部中断0处理程序
void scan_key(void); //扫描键盘
void delay(unsigned int N) ;//延时子程序,实现(16*N+24)us的延时

////////////////////////////////////////////////////////////////////
void main(void)
{
temph=0xff;
templ=0xff;
P1=temph;
P2=templ;
system_init() ;
while(1)
{
INT0_SCANkey() ;
}
}

void system_init(void )
{
.
.
.
}
void delay(unsigned int N)
{
int i;
for(i=0;i<N;i++);
}
void INT0_SCANkey() interrupt 0 using 1
{

{

INT

if( INT_0 != 0 ) //再次判断是否有键按下
{
EA=0;
scan_key();
delay(50);
INT_0 =judge_hitkey();
while( INT_0 !=1); //等待按键释放
EA=1;
}
在EA=0;这句前,有无加上了,重新把 INT_0 =judge_hitkey(); 再赋回来了?,,我在郭天祥的板子上调试不行; EXITE.C(93): warning C206: 'manage_key1': missing function-prototype;
这是我花两个多小时写得51单片机,矩阵键盘的显示,希望能对你有帮助;
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
sbit dula=P2^6;
sbit wela=P2^7;
void init();
void display(uchar);
uchar keyscan();
uchar temp,num; //键盘扫描
void delay(uint xms) //延时子函数
{
int i,j;
for(i=xms;i>0;i--) //延时xms毫秒
for(j=110;j>0;j--);
}
void main()
{
init();
while(1)
{
keyscan();//不断扫描键盘;