新聞中心

        EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 單片機(jī)驅(qū)動(dòng)4X4矩陣式鍵盤(pán)輸入程序

        單片機(jī)驅(qū)動(dòng)4X4矩陣式鍵盤(pán)輸入程序

        作者: 時(shí)間:2012-12-05 來(lái)源:網(wǎng)絡(luò) 收藏

        C語(yǔ)言源程序:

        #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;

        //我的程序沒(méi)有注釋,不過(guò)很簡(jiǎn)單。有不懂的上論壇51版塊那解決http://www.51hei.com c程序和上面的匯編程序是實(shí)現(xiàn)一樣的功能的,初學(xué)者可通過(guò)對(duì)比熟悉兩種語(yǔ)言的使用方法。
        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;
        }
        }
        }
        }
        }

        蜂鳴器相關(guān)文章:蜂鳴器原理

        上一頁(yè) 1 2 下一頁(yè)

        評(píng)論


        相關(guān)推薦

        技術(shù)專區(qū)

        關(guān)閉
        主站蜘蛛池模板: 垣曲县| 侯马市| 库伦旗| 前郭尔| 巨鹿县| 萨迦县| 青冈县| 隆尧县| 泰州市| 和静县| 张家口市| 祁门县| 岳阳县| 筠连县| 曲松县| 金堂县| 望谟县| 达孜县| 隆子县| 剑河县| 柘城县| 乌兰浩特市| 白山市| 阿图什市| 旬邑县| 保康县| 时尚| 泌阳县| 河西区| 大田县| 夏河县| 嘉善县| 门源| 文登市| 镇康县| 格尔木市| 仪征市| 扶沟县| 南城县| 龙海市| 阿拉善盟|