4×4键盘扫描源程序 求注解!
#include<reg51.h>#include<absacc.h>#include<intrins.h>#defineucharunsignedchar#define...
#include<reg51.h>
#include<absacc.h>
#include<intrins.h>
#define uchar unsigned char
#define pcom8155 XBYTE[0xff23]
#define pa8155 XBYTE[0xff20]
#define pb8155 XBYTE[0xff21]
#define pc8155 XBYTE[0xff22]
void delay(unsigned int i)
{
unsigned int j,k;
for(k=0;k<i;k++)
for(j=0;j<100;j++);
}
void main(void)
{
uchar idata disbuf[8]={0,0,1,2,3,4,5,6};
uchar code table[20]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E,0xFF,0x0C,0x89,0xDE};
P2=0xff;
pcom8155=0x81;
while(1)
{
uchar x=8,y=0x80,m,n,t=0x0f;
y=~y;
for(x=0;x<8;x++) //led display
{
pb8155=table[disbuf[x]];
pa8155=y;
m=pc8155;
m=m&0x03;
if (x==2 );
{
if ( m==0x01)
{
n=0x0e;
disbuf[4]=0x0e;
}
if (m==0x02)
{
n=6;
disbuf[4]=6;
}
}
if (x==3 );
{
if ( m==0x01)
{
n=3;
disbuf[4]=3;
}
if (m==0x02)
{
n=9;
disbuf[4]=9;
}
}
if (x==4 )
{
if ( m==0x01)
{
n=0x0f;
disbuf[3]=0x0f;
}
if (m==0x02)
{
n=5;
disbuf[3]=5;
}
}
if (x==5 )
{
if ( m==0x01)
{
n=2;
disbuf[3]=2;
}
if (m==0x02)
{
n=8;
disbuf[3]=8;
}
}
if (x==6 )
{
if ( m==0x01)
{
n=0;
disbuf[2]=0;
}
if (m==0x02)
{
n=4;
disbuf[2]=4;
}
}
if (x==7 )
{
if ( m==0x01)
{
n=1;
disbuf[2]=1;
}
if (m==0x02)
{
n=7;
disbuf[2]=7;
}
}
if (x==0 )
{
if ( m==0x01)
{
n=0x0d;
disbuf[5]=0x0d;
}
if (m==0x02)
{
n=0x0b;
disbuf[5]=0x0b;
}
}
if (x==1 )
{
if ( m==0x01)
{
n=0x0c;
disbuf[5]=0x0c;
}
if (m==0x02)
{
n=0x0a;
disbuf[5]=0x0a;
}
}
delay(2);
y=_cror_(y,1);
}
}
}
4×4键盘扫描源程序 以上是源程序的C语言代码 求高人一一注解我瞅瞅
懂了有加分~ 展开
#include<absacc.h>
#include<intrins.h>
#define uchar unsigned char
#define pcom8155 XBYTE[0xff23]
#define pa8155 XBYTE[0xff20]
#define pb8155 XBYTE[0xff21]
#define pc8155 XBYTE[0xff22]
void delay(unsigned int i)
{
unsigned int j,k;
for(k=0;k<i;k++)
for(j=0;j<100;j++);
}
void main(void)
{
uchar idata disbuf[8]={0,0,1,2,3,4,5,6};
uchar code table[20]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E,0xFF,0x0C,0x89,0xDE};
P2=0xff;
pcom8155=0x81;
while(1)
{
uchar x=8,y=0x80,m,n,t=0x0f;
y=~y;
for(x=0;x<8;x++) //led display
{
pb8155=table[disbuf[x]];
pa8155=y;
m=pc8155;
m=m&0x03;
if (x==2 );
{
if ( m==0x01)
{
n=0x0e;
disbuf[4]=0x0e;
}
if (m==0x02)
{
n=6;
disbuf[4]=6;
}
}
if (x==3 );
{
if ( m==0x01)
{
n=3;
disbuf[4]=3;
}
if (m==0x02)
{
n=9;
disbuf[4]=9;
}
}
if (x==4 )
{
if ( m==0x01)
{
n=0x0f;
disbuf[3]=0x0f;
}
if (m==0x02)
{
n=5;
disbuf[3]=5;
}
}
if (x==5 )
{
if ( m==0x01)
{
n=2;
disbuf[3]=2;
}
if (m==0x02)
{
n=8;
disbuf[3]=8;
}
}
if (x==6 )
{
if ( m==0x01)
{
n=0;
disbuf[2]=0;
}
if (m==0x02)
{
n=4;
disbuf[2]=4;
}
}
if (x==7 )
{
if ( m==0x01)
{
n=1;
disbuf[2]=1;
}
if (m==0x02)
{
n=7;
disbuf[2]=7;
}
}
if (x==0 )
{
if ( m==0x01)
{
n=0x0d;
disbuf[5]=0x0d;
}
if (m==0x02)
{
n=0x0b;
disbuf[5]=0x0b;
}
}
if (x==1 )
{
if ( m==0x01)
{
n=0x0c;
disbuf[5]=0x0c;
}
if (m==0x02)
{
n=0x0a;
disbuf[5]=0x0a;
}
}
delay(2);
y=_cror_(y,1);
}
}
}
4×4键盘扫描源程序 以上是源程序的C语言代码 求高人一一注解我瞅瞅
懂了有加分~ 展开
3个回答
2010-06-15
展开全部
我有一个短的
反扫描 就两句关键,一起学习 QQ705374254
#include <reg52.h>//包含头文件
#define uchar unsigned char
#define uint unsigned int
unsigned char const dofly[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,
0x77,0x7c,0x39,0x5e,0x79,0x71};//0-F
uchar keyscan(void);
void delay(uint i);
void main()
{
uchar key;
P2=0x00;//1数码管亮 按相应的按键,会显示按键上的字符
while(1)
{
key=keyscan();//调用键盘扫描,
switch(key)
{
case 0x7e:P0=dofly[0];break;//0 按下相应的键显示相对应的码值
case 0x7d:P0=dofly[1];break;//1
case 0x7b:P0=dofly[2];break;//2
case 0x77:P0=dofly[3];break;//3
case 0xbe:P0=dofly[4];break;//4
case 0xbd:P0=dofly[5];break;//5
case 0xbb:P0=dofly[6];break;//6
case 0xb7:P0=dofly[7];break;//7
case 0xde:P0=dofly[8];break;//8
case 0xdd:P0=dofly[9];break;//9
case 0xdb:P0=dofly[10];break;//a
case 0xd7:P0=dofly[11];break;//b
case 0xee:P0=dofly[12];break;//c
case 0xed:P0=dofly[13];break;//d
case 0xeb:P0=dofly[14];break;//e
case 0xe7:P0=dofly[15];break;//f
}
}
}
uchar keyscan(void)//键盘扫描函数,使用行列反转扫描法
{
uchar cord_h,cord_l;//行列值
P3=0x0f; //行线输出全为0
cord_h=P3&0x0f; //读入列线值
if(cord_h!=0x0f) //先检测有无按键按下
{
delay(100); //去抖
if(cord_h!=0x0f)
{
cord_h=P3&0x0f; //读入列线值
P3=cord_h|0xf0; //输出当前列线值
cord_l=P3&0xf0; //读入行线值
return(cord_h+cord_l);//键盘最后组合码值
}
}return(0xff); //返回该值
}
void delay(uint i)//延时函数
{
while(i--);
}
反扫描 就两句关键,一起学习 QQ705374254
#include <reg52.h>//包含头文件
#define uchar unsigned char
#define uint unsigned int
unsigned char const dofly[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,
0x77,0x7c,0x39,0x5e,0x79,0x71};//0-F
uchar keyscan(void);
void delay(uint i);
void main()
{
uchar key;
P2=0x00;//1数码管亮 按相应的按键,会显示按键上的字符
while(1)
{
key=keyscan();//调用键盘扫描,
switch(key)
{
case 0x7e:P0=dofly[0];break;//0 按下相应的键显示相对应的码值
case 0x7d:P0=dofly[1];break;//1
case 0x7b:P0=dofly[2];break;//2
case 0x77:P0=dofly[3];break;//3
case 0xbe:P0=dofly[4];break;//4
case 0xbd:P0=dofly[5];break;//5
case 0xbb:P0=dofly[6];break;//6
case 0xb7:P0=dofly[7];break;//7
case 0xde:P0=dofly[8];break;//8
case 0xdd:P0=dofly[9];break;//9
case 0xdb:P0=dofly[10];break;//a
case 0xd7:P0=dofly[11];break;//b
case 0xee:P0=dofly[12];break;//c
case 0xed:P0=dofly[13];break;//d
case 0xeb:P0=dofly[14];break;//e
case 0xe7:P0=dofly[15];break;//f
}
}
}
uchar keyscan(void)//键盘扫描函数,使用行列反转扫描法
{
uchar cord_h,cord_l;//行列值
P3=0x0f; //行线输出全为0
cord_h=P3&0x0f; //读入列线值
if(cord_h!=0x0f) //先检测有无按键按下
{
delay(100); //去抖
if(cord_h!=0x0f)
{
cord_h=P3&0x0f; //读入列线值
P3=cord_h|0xf0; //输出当前列线值
cord_l=P3&0xf0; //读入行线值
return(cord_h+cord_l);//键盘最后组合码值
}
}return(0xff); //返回该值
}
void delay(uint i)//延时函数
{
while(i--);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询