回覆列表
  • 1 # dadazhu1

    #include"reg51.h"

    #define uint unsigned int

    #define uchar unsigned char

    sbit key1=P1^0;

    sbit key2=P1^1;

    sbit key3=P1^2;

    sbit key4=P1^3;

    sbit key5=P1^4;

    sbit key6=P1^5;

    sbit key7=P1^6;

    sbit key8=P1^7;

    num=0;

    void delay1ms(uint z)

    {

    uchar i;

    while(z--)

    for(i=115;i>0;i--);

    }

    unsigned char code table[]={

    0xc0,0xf9,0xa4,0xb0,

    0x99,0x92,0x82,0xf8,

    0x80,0x98,0x88,0x83,

    0xc6,0xa1,0x86,0x8e};

    void main()

    {

    while(1)

    {

    if(key1==0)

    {

    delay1ms(10); //按鍵去抖動

    if(key1==0)

    {

    num=1;

    P0=table[num];

    }

    while(!key1);

    }

    if(key2==0)

    {

    delay1ms(10); //按鍵去抖動

    if(key2==0)

    {

    num=2;

    P0=table[num];

    }

    while(!key2);

    if(key3==0)

    {

    num=3;

    P0=table[num];

    }

    while(!key3);

    }

    if(key4==0)

    {

    delay1ms(10); //按鍵去抖動

    if(key4==0)

    {

    num=4;

    P0=table[num];

    }

    while(!key4);

    if(key5==0)

    {

    num=5;

    P0=table[num];

    }

    while(!key5);

    }

    if(key6==0)

    {

    delay1ms(10); //按鍵去抖動

    if(key6==0)

    {

    num=6;

    P0=table[num];

    }

    while(!key6);

    if(key7==0)

    {

    num=7;

    P0=table[num];

    }

    while(!key7);

    }

    if(key8==0)

    {

    delay1ms(10); //按鍵去抖動

    if(key8==0)

    {

    num=8;

    P0=table[num];

    }

    while(!key8);

    }

    }

    }

  • 中秋節和大豐收的關聯?
  • 醃辣椒要不要放香油?