<meta name="keywords" content="必胜时时彩开户,keywords" /> MSP430和AT89C51单片机4x4键盘C法式模范 联系我们

MSP430和AT89C51单片机4x4键盘C法式模范模范

本法式模范模范在一名上显示按键,假定多位显示主法式模范模范须要修高为多位显示。本法式模范模范软件网罗去抖功效,没有注释诠释。
#include<reg51.h>
#define uchar unsigned char
#define uint  unsigned int 
uint key,i;
uchar temp,temp1,ms,buff;
uchar tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,
             0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
void delay(ms)
{
 while(ms--)
  {
   for(i=0;i<120;i++);
  }
}
void B_key()
{  
  temp1=0xfe;
  P1=temp1;
  if(P1!=temp1)
      {
     delay(10);
     if (P1!=temp1)
        {
          temp=P1;
          switch(temp)
            {
           case 0xee:key=0;break;
           case 0xde:key=1;break;
           case 0xbe:key=2;break;
           case 0x7e:key=3;break;
           default:break;
            }
        }
       } 
  temp1=0xfd;
  P1=temp1;
  if(P1!=temp1)
      {
     delay(10);
     if (P1!=temp1)
        {
          temp=P1;
          switch(temp)
            {
           case 0xed:key=4;break;
           case 0xdd:key=5;break;
           case 0xbd:key=6;break;
           case 0x7d:key=7;break;
           default:break;
            }
           }
       }
   temp1=0xfb;
   P1=temp1;
  if(P1!=temp1)
     {
        delay(10);
     if (P1!=temp1)
        {
         temp=P1;
         switch(temp)
            {
           case 0xeb:key=8;break;
           case 0xdb:key=9;break;
           case 0xbb:key=10;break;
           case 0x7b:key=11;break;
           default:break;
            }
        }
     }
   temp1=0xf7;
   P1=temp1;
  if(P1!=temp1)
      {
     delay(10);
     if (P1!=temp1)
        {
          temp=P1;
          switch(temp)
            {
           case 0xe7:key=12;break;
           case 0xd7:key=13;break;
           case 0xb7:key=14;break;
           case 0x77:key=15;break;
           default:break;
           }
        }
    }   
}
void main()
{
while(1)
 {
     B_key();
  P2=tab[key];
  P3=0x04;
 }
}

 #include "io430.h"
#define uchar unsigned char
#define uint  unsigned int 
uint key,i;
uchar temp,temp1,ms;
uchar tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,
             0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
void delay(uchar ms)
{
 while(ms--)
  {
   for(i=0;i<120;i++);
  }
}
void B_key()
{     
  temp1=0x0e;
  P1OUT=temp1;
  if(P1IN!=temp1)
      {
     delay(10);
     if (P1IN!=temp1)
        {
          temp=P1IN|temp1;
          switch(temp)
            {
           case 0xee:key=0;break;
           case 0xde:key=1;break;
           case 0xbe:key=2;break;
           case 0x7e:key=3;break;
           default:break;
            }
        }
      } 
  temp1=0x0d;
  P1OUT=temp1;
  if(P1IN!=temp1)
      {
     delay(10);
     if (P1IN!=temp1)
        {
          temp=P1IN|temp1;
          switch(temp)
            {
           case 0xed:key=4;break;
           case 0xdd:key=5;break;
           case 0xbd:key=6;break;
           case 0x7d:key=7;break;
           default:break;
            }
         }
       }
   temp1=0x0b;
   P1OUT=temp1;
  if(P1IN!=temp1)
      {
     delay(10);
     if (P1IN!=temp1)
        {
          temp=P1IN|temp1;
         switch(temp)
            {
           case 0xeb:key=8;break;
           case 0xdb:key=9;break;
           case 0xbb:key=10;break;
           case 0x7b:key=11;break;
           default:break;
            }
        }
     }
   temp1=0x07;
   P1OUT=temp1;
  if(P1IN!=temp1)
      {
     delay(10);
     if (P1IN!=temp1)
        {
          temp=P1IN|temp1;
          switch(temp)
            {
           case 0xe7:key=12;break;
           case 0xd7:key=13;break;
           case 0xb7:key=14;break;
           case 0x77:key=15;break;
           default:break;
           }
        }
    }   
}
int main( void )
{
  // Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
P1DIR=0x0f;
P2DIR=0xff;
while(1)
 {
   B_key();
   P2OUT=tab[key];
 }
}