新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > 單片機驅動4X4矩陣式鍵盤輸入程序

        單片機驅動4X4矩陣式鍵盤輸入程序

        作者: 時間:2012-12-05 來源:網絡 收藏

        C語言源程序:

        #include AT89X51.H>
        unsigned char code table[]={0x3f,0x06,0x5b,0x4f,
        0x66,0x6d,0x7d,0x07,
        0x7f,0x6f,0x77,0x7c,
        0x39,0x5e,0x79,0x71};
        unsigned char temp;
        unsigned char key;
        unsigned char i,j;

        //我的程序沒有注釋,不過很簡單。有不懂的上論壇51版塊那解決http://www.51hei.com c程序和上面的匯編程序是實現一樣的功能的,初學者可通過對比熟悉兩種語言的使用方法。
        void main(void)
        {
        while(1)
        {
        P3=0xff;
        P3_4=0;
        temp=P3;
        temp=temp 0x0f;
        if (temp!=0x0f)
        {
        for(i=50;i>0;i--)
        for(j=200;j>0;j--);
        temp=P3;
        temp=temp 0x0f;
        if (temp!=0x0f)
        {
        temp=P3;
        temp=temp 0x0f;
        switch(temp)
        {
        case 0x0e:
        key=7;
        break;
        case 0x0d:
        key=8;
        break;
        case 0x0b:
        key=9;
        break;
        case 0x07:
        key=10;
        break;
        }
        temp=P3;
        P1_0=~P1_0;
        P0=table[key];
        temp=temp 0x0f;
        while(temp!=0x0f)
        {
        temp=P3;
        temp=temp 0x0f;
        }
        }
        }

        P3=0xff;
        P3_5=0;
        temp=P3;
        temp=temp 0x0f;
        if (temp!=0x0f)
        {
        for(i=50;i>0;i--)
        for(j=200;j>0;j--);
        temp=P3;
        temp=temp 0x0f;
        if (temp!=0x0f)
        {
        temp=P3;
        temp=temp 0x0f;
        switch(temp)
        {
        case 0x0e:
        key=4;
        break;
        case 0x0d:
        key=5;
        break;
        case 0x0b:
        key=6;
        break;
        case 0x07:
        key=11;
        break;
        }
        temp=P3;
        P1_0=~P1_0;
        P0=table[key];
        temp=temp 0x0f;
        while(temp!=0x0f)
        {
        temp=P3;
        temp=temp 0x0f;
        }
        }
        }

        P3=0xff;
        P3_6=0;
        temp=P3;
        temp=temp 0x0f;
        if (temp!=0x0f)
        {
        for(i=50;i>0;i--)
        for(j=200;j>0;j--);
        temp=P3;
        temp=temp 0x0f;
        if (temp!=0x0f)
        {
        temp=P3;
        temp=temp 0x0f;
        switch(temp)
        {
        case 0x0e:
        key=1;
        break;
        case 0x0d:
        key=2;
        break;
        case 0x0b:
        key=3;
        break;
        case 0x07:
        key=12;
        break;
        }
        temp=P3;
        P1_0=~P1_0;
        P0=table[key];
        temp=temp 0x0f;
        while(temp!=0x0f)
        {
        temp=P3;
        temp=temp 0x0f;
        }
        }
        }

        P3=0xff;
        P3_7=0;
        temp=P3;
        temp=temp 0x0f;
        if (temp!=0x0f)
        {
        for(i=50;i>0;i--)
        for(j=200;j>0;j--);
        temp=P3;
        temp=temp 0x0f;
        if (temp!=0x0f)
        {
        temp=P3;
        temp=temp 0x0f;
        switch(temp)
        {
        case 0x0e:
        key=0;
        break;
        case 0x0d:
        key=13;
        break;
        case 0x0b:
        key=14;
        break;
        case 0x07:
        key=15;
        break;
        }
        temp=P3;
        P1_0=~P1_0;
        P0=table[key];
        temp=temp 0x0f;
        while(temp!=0x0f)
        {
        temp=P3;
        temp=temp 0x0f;
        }
        }
        }
        }
        }

        蜂鳴器相關文章:蜂鳴器原理

        上一頁 1 2 下一頁

        評論


        相關推薦

        技術專區

        關閉
        主站蜘蛛池模板: 楚雄市| 元阳县| 依安县| 扎兰屯市| 宜兴市| 深水埗区| 巴彦县| 福安市| 日照市| 阜宁县| 延寿县| 波密县| 通山县| 曲阳县| 舟曲县| 龙门县| 连山| 南岸区| 中西区| 房产| 吉安县| 华阴市| 松江区| 丘北县| 恭城| 章丘市| 莱州市| 利辛县| 津市市| 天等县| 安岳县| 拉萨市| 开江县| 小金县| 兰考县| 桂阳县| 庆安县| 门头沟区| 施甸县| 宜春市| 和田县|