標(biāo)題: 矩陣鍵盤掃描設(shè)計(jì) [打印本頁(yè)]

作者: 草木第八    時(shí)間: 2018-12-6 15:42
標(biāo)題: 矩陣鍵盤掃描設(shè)計(jì)

//按不同的按鍵,數(shù)碼管顯示不同的數(shù)值
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar DisCount,LedDat,keyTmp1,keyTmp2,keyvalue;
uint DisTime;
uchar code SegTable[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x38};
uchar dispNum[16]={0X00,0X01,0X02,0X03,0X04,0X05,0X06,0X07,0X08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
uchar u1[9]={0x00,0x00,0x01,0xff,0x02,0xff,0xff,0xff,0x03};
uchar u2[9]={0x10,0x00,0x04,0xff,0x08,0xff,0xff,0xff,0x0c};
void delay(void)
{
  uchar i,j;
  for(i=0;i<10;i++)
  for(j=0;j<125;j++);
}

  uchar keyScan()
{
  
  P1=0xf0;
  keyTmp1=P1;
  P1=0x0f;
  delay();
  keyTmp2=P1;
  keyvalue=~(keyTmp1|keyTmp2);
  keyTmp1=keyvalue&0X0F;
  keyTmp2=(keyvalue>>4)&0X0F;
  keyvalue=u1[keyTmp1]+u2[keyTmp2];
  return keyvalue;
}

void main(void)
{
TMOD=0x11;
TH0=0Xfe;
TL0=0X18;
TR0=1;
TR1=1;
ET0=1;
EA=1;
LedDat=0x01;
while(1)
{
  keyvalue=keyScan();
  }

}
void Timer0ISR() interrupt 1
{
  TH0=TH0+0xfc;
TL0=TL0+0x18;
DisTime++;
if(DisTime>100)
{
  DisTime=0x00;
  P0=0x00;
  LedDat=(LedDat>>1)|(LedDat<<7);
  P2=~LedDat;
  P2=0x7F;
  P0=SegTable[dispNum[keyvalue]];
  DisCount++;
  if(DisCount>7)
   DisCount=0;
}
}


矩陣鍵盤.zip

27.96 KB, 下載次數(shù): 5, 下載積分: 黑幣 -5






歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1