亚洲春色中文字幕久久久-三上亚,一吻二脱三床四吻胸,国产真实伦对白视频全集,在线毛片观看,精品成品入口黄网,国产毛aⅴ片久久久,亚洲AV色香蕉一区二区三区老师,萧皇后A级艳片,色情日本视频更新,99久久亚洲精品日本无码

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 5517|回復(fù): 8
打印 上一主題 下一主題
收起左側(cè)

關(guān)于單片機矩陣鍵盤的問題,為什么按鍵摁了之后數(shù)碼管不亮?

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:257987 發(fā)表于 2017-12-5 23:52 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
我這個程序有什么問題嗎?為什么按鍵摁了之后數(shù)碼管不亮?
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula = P2 ^ 6; //U1鎖存端
sbit wela = P2 ^ 7; //U2鎖存端
uchar code table[] = { 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71 };
void delayms(uint xms)
{
        uint i, j;
        for (i = xms; i > 0; i--)
                for (j = 110; j > 0; j--);
}
void display(uchar num)
{
        P0 = table[num];
        dula = 1;
        dula = 0;
}
void matrixkeyscan()
{
        uchar temp, key;
        P3 = 0xfe;
        temp = P3;
        temp = temp & 0xf0;
        if (temp != 0xf0)
        {
                delayms(10);
                temp = P3;
                temp = temp & 0xf0;
                if (temp != 0xf0)
                {
                        temp = P3;
                        switch (temp)
                        {
                        case 0xee:
                                key = 0;
                                break;
                        case 0xde:
                                key = 1;
                                break;
                        case 0xbe:
                                key = 2;
                                break;
                        case 0x7e:
                                key = 3;
                                break;
                        }
                        while (temp != 0xfe)
                        {
                                temp = P3;
                                temp = temp & 0xf0;
                        }
                        display(key);
                }
        }
        P3 = 0xfd;
        temp = P3;
        temp = temp & 0xf0;
        if (temp != 0xf0)
        {
                delayms(10);
                temp = P3;
                temp = temp & 0xf0;
                if (temp != 0xf0)
                {
                        temp = P3;
                        switch (temp)
                        {
                        case 0xed:
                                key = 4;
                                break;
                        case 0xdd:
                                key = 5;
                                break;
                        case 0xbd:
                                key = 6;
                                break;
                        case 0x7d:
                                key = 7;
                                break;
                        }
                        while (temp != 0xf0)
                        {
                                temp = P3;
                                temp = temp & 0xf0;
                        }
                        display(key);
                }
        }
        P3 = 0xfb;
        temp = P3;
        temp = temp & 0xf0;
        if (temp != 0xf0)
        {
                delayms(10);
                temp = P3;
                temp = temp & 0xf0;
                if (temp != 0xf0)
                {
                        temp = P3;
                        switch (temp)
                        {
                        case 0xeb:
                                key = 8;
                                break;
                        case 0xdb:
                                key = 9;
                                break;
                        case 0xbb:
                                key = 10;
                                break;
                        case 0x7b:
                                key = 11;
                                break;
                        }
                        while (temp != 0xf0)
                        {
                                temp = P3;
                                temp = temp & 0xf0;
                        }
                        display(key);
                }
        }
        P3 = 0xf7;
        temp = P3;
        temp = temp & 0xf0;
        if (temp != 0xf0)
        {
                delayms(10);
                temp = P3;
                temp = temp & 0xf0;
                if (temp != 0xf0)
                {
                        temp = P3;
                        switch (temp)
                        {
                        case 0xe7:
                                key = 12;
                                break;
                        case 0xd7:
                                key = 13;
                                break;
                        case 0xb7:
                                key = 14;
                                break;
                        case 0x77:
                                key = 15;
                                break;
                        }
                        while (temp != 0xf0)
                        {
                                temp = P3;
                                temp = temp & 0xf0;
                        }
                        display(key);
                }
        }
}
void main()
{
        P0 = 0;
        dula = 1;
        dula = 0;
        P0 = 0xc0;
        wela = 1;
        wela = 0;
        while (1)
        {
                matrixkeyscan();
        }
}


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

沙發(fā)
ID:213173 發(fā)表于 2017-12-6 12:19 | 只看該作者
本帖最后由 wulin 于 2017-12-6 12:52 編輯

這樣寫就可以了。
#include <AT89X52.H>
#define uint unsigned int                 //宏定義無符號整型數(shù)據(jù)
#define uchar unsigned char         //宏定義無符號字符型數(shù)據(jù)
sbit dula=P2^6;                        //數(shù)碼管段鎖存
sbit wela=P2^7;                        //數(shù)碼管位鎖存
uchar code table[]={                //共陰數(shù)碼管0~F
        0x3f,0x06,0x5b,0x4f,
        0x66,0x6d,0x7d,0x07,
        0x7f,0x6f,0x77,0x7c,
        0x39,0x5e,0x79,0x71,0x80};
uchar key=16;                                        //定義鍵值全局變量

void keyscan()                                        //按鍵掃描程序
{
        static bit sign=0;                        //按鍵有效標志
        static uint count=0;                //消抖計數(shù)變量                       
        uchar num=0;                                //臨時變量
        P3=0xf0;                                                //賦值P3 1111 0000
        if(P3!=0xf0)                                //檢測按鍵按下
        {
                count++;                                        //消抖計數(shù)
                if((count>=500)&&(sign==0))        //100~1000,根據(jù)主循環(huán)周期調(diào)整約10~20ms與按鍵有效標志0
                {
                        sign=1;                                //按鍵有效標志置1,防止重復(fù)響應(yīng)
                        num=P3;                                //保存P3值xxxx 0000,x為0或1
                        num|=0x0f;                        //保存num按位或0x0f值xxxx 1111
                        P3=num;                                //賦值P3 xxxx 1111
                        num=P3;                                //保存P3值xxxx xxxx
                        switch(num)
                        {
                                case 0xee: key= 0; break;
                                case 0xde: key= 1; break;
                                case 0xbe: key= 2; break;
                                case 0x7e: key= 3; break;
                                case 0xed: key= 4; break;
                                case 0xdd: key= 5; break;
                                case 0xbd: key= 6; break;
                                case 0x7d: key= 7; break;
                                case 0xeb: key= 8; break;
                                case 0xdb: key= 9; break;
                                case 0xbb: key=10; break;
                                case 0x7b: key=11; break;
                                case 0xe7: key=12; break;
                                case 0xd7: key=13; break;
                                case 0xb7: key=14; break;
                                case 0x77: key=15; break;
                        }
                }
        }
        else                                                //鍵抬起
        {
                sign=0;                                //按鍵有效標志清0
                count=0;                                //消抖計數(shù)清0
        }
}

void display()
{        
        P0=table[key];                //段碼
        dula=1;
        dula=0;
        P0=0x7e;                                //位碼
        wela=1;
        wela=0;
}
void main()                                                //主函數(shù)
{
        while(1)
        {
                keyscan();                                //按鍵掃描程序
                display();                                //1位數(shù)碼管顯示程序
        }
}

回復(fù)

使用道具 舉報

板凳
ID:253022 發(fā)表于 2017-12-6 13:40 | 只看該作者
wulin 發(fā)表于 2017-12-6 12:19
這樣寫就可以了。
#include  
#define uint unsigned int                 //宏定義無符號整型數(shù)據(jù)

老師你好!我是剛學(xué)單片機的,剛剛看了你關(guān)于鍵盤檢測的代碼,我有幾個問題想請教你。第一個是為什么P3=0xf0,又要判斷P3是否等于0Xf0?第二個是為什么有P3=num;之后又有num=P3;

老師可以幫我點明一下嗎

回復(fù)

使用道具 舉報

地板
ID:213173 發(fā)表于 2017-12-6 14:32 | 只看該作者
周鑫鑫鑫666 發(fā)表于 2017-12-6 13:40
老師你好!我是剛學(xué)單片機的,剛剛看了你關(guān)于鍵盤檢測的代碼,我有幾個問題想請教你。第一個是為什么P3=0 ...

這里每一行都有注釋,不應(yīng)該看不懂。P3=0xf0是賦值操作,if(P3!=0xf0)是條件判斷,num|=0x0f;是邏輯或運算,等效于num=num|0x0f;。P3=num;之后又有num=P3;這里給P3賦值和讀取P3值再賦num,是因為鍵被按下,num是有變化的。
回復(fù)

使用道具 舉報

5#
ID:256485 發(fā)表于 2017-12-7 22:27 | 只看該作者
請問樓主這個程序是通過矩陣鍵盤數(shù)碼管顯示0~F嗎
回復(fù)

使用道具 舉報

6#
ID:256485 發(fā)表于 2017-12-7 22:29 | 只看該作者
請問樓主這個程序是通過矩陣鍵盤使數(shù)碼管顯示0~F嗎
回復(fù)

使用道具 舉報

7#
ID:259295 發(fā)表于 2017-12-9 07:42 | 只看該作者
應(yīng)該是通過矩陣鍵盤使數(shù)碼管顯示0--F
回復(fù)

使用道具 舉報

8#
ID:259661 發(fā)表于 2017-12-10 08:54 | 只看該作者
來看看
回復(fù)

使用道具 舉報

9#
ID:257987 發(fā)表于 2017-12-16 13:01 來自觸屏版 | 只看該作者
Mxzy 發(fā)表于 2017-12-7 22:29
請問樓主這個程序是通過矩陣鍵盤使數(shù)碼管顯示0~F嗎

是,只顯示一位的。
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表