專(zhuān)注電子技術(shù)學(xué)習(xí)與研究
當(dāng)前位置:單片機(jī)教程網(wǎng) >> MCU設(shè)計(jì)實(shí)例 >> 瀏覽文章

4×4鍵盤(pán)C程序HD7279A顯示

作者:浪子   來(lái)源:浪子   點(diǎn)擊數(shù):  更新時(shí)間:2014年06月10日   【字體:

 #include "AT89X52.H"

#define  uchar unsigned char
#define  uint unsigned int
sbit    CLK  = P3^0;
sbit    DAT  = P3^1;
sbit    CS   = P3^2;//sbit a1=P1^1;
 
void delay(uint t)
{
 uint i;
 while(t--)
 {
  for(i=0;i<125;i++){}
 }
}
 void   L_Delay()                      //CS被清零后,要經(jīng)過(guò)50μs,才送CLK.
{
   uchar i;
   for ( i=0; i<48; i++ ) ;
}
 
//
 
void  Write7279( uchar CMD, uchar DTA )
{
   Send_Byte( CMD );
   Send_Byte( DTA );
 
}
uchar kbscan(void)
{uchar sccode,j,k=0;
 P1=0xf0;
if((P1&0xf0)!=0xf0)
{delay(30);
 if((P1&0xf0)!=0xf0)
  {sccode=0xfe;
   for(j=0;j<4;j++)
     {P1=sccode;
      if((P1&0xf0)!=0xf0)
   {k=~P1;
   while((P1&0XF0)!=0XF0);
    return (k);
   }
      else sccode=(sccode<<1)|0x01;
     }
   }
}
return(0);
}
uchar bian(uchar key)
{switch(key)
{
 case 0x00: return  0;break;
 case 0x11: return  1;break;
 case 0x12: return   2;break;
 case 0x14: return   3;break;
 case 0x18: return   4;break;
 case 0x21: return   5;break;
 case 0x22: return   6;break;
 case 0x24: return   7;break;
 case 0x28: return   8;break;
 case 0x41: return   9;break;
 case 0x42: return   10;break;
 case 0x44: return   11;break;
 case 0x48: return   12;break;
 case 0x81: return   13;break;
 case 0x82: return   14;break;
 case 0x84: return   15;break;
 case 0x88: return   16;break;
 
}
}main()
{
 uchar m;
 while(1)
 {
  m=bian(kbscan()); 
                if(m>0&m<16){
           Write7279( 0xc8,m); }
 }
}
關(guān)閉窗口

相關(guān)文章