找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 2095|回復(fù): 0
收起左側(cè)

試驗(yàn)板鍵盤問題

[復(fù)制鏈接]
ID:47343 發(fā)表于 2015-1-23 19:24 | 顯示全部樓層 |閱讀模式
首先說下,剛開始學(xué)習(xí)c51程序,是根據(jù)郭天祥的教程寫的
發(fā)現(xiàn)實(shí)驗(yàn)板的鍵盤電路圖有問題。
圖上標(biāo)的是
s6       s7      s8       s9

s10     s11    s12     s13

s14     s14    s16     s17

s18     s19    s20     s21      

實(shí)際是

s6    s10     s14    s18

s7    s11     s15    s19

s8    s12    s16     s20

s9    s13   s17      s21      

//鍵盤按列依次被按下,數(shù)碼管依次顯示0-F
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^6;
sbit wela=P2^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uchar temp,num;
/////////////////延時(shí)程序////////////////       
void delay(uint z)
{
        uint x,y;
        for(x=z;x>0;x--)
        {
                for(y=250;y>0;y--)
                {
                };
        };
}
/////////////////延時(shí)程序////////////////
void main()
{       
        dula=1;
        P0=0;
        dula=0;
        wela=1;
        P0=0x00;
        wela=0;
        while(1)
        {
                P3=0xef;
                temp=P3;
                temp=temp&0x0f;
/////////////////消去按鍵時(shí)的抖動(dòng)////////////////
                while(temp!=0x0f)//檢測(cè)是否有按鍵被按下
                {
                        delay(5);
                        temp=P3;
                        temp=temp&0x0f;
/////////////////消去按鍵時(shí)的抖動(dòng)////////////////
                        while(temp!=0x0f)//檢測(cè)是否真有按鍵被按下
                        {                               
                                temp=P3;
                                switch(temp)
                                {
                                        case 0xee:num=1;       
                                                break;
                                        case 0xed:num=2;
                                                break;
                                        case 0xeb:num=3;
                                                break;
                                        case 0xe7:num=4;
                                                break;
                                };
/////////////////第一列鍵盤掃描的松手檢測(cè)////////////////       
                                while(temp!=0x0f)
                                {
                                        temp=P3;
                                        temp=temp&0x0f;

                                }       
/////////////////第一列鍵盤掃描的松手檢測(cè)////////////////       
/////////////////數(shù)碼管根據(jù)按鍵信息顯示////////////////       
                                dula=1;
                                P0=table[num-1];
                                dula=0;       
/////////////////數(shù)碼管根據(jù)按鍵信息顯示////////////////               
                        };
                };

//第二列鍵盤掃描程序
                P3=0xdf;
                temp=P3;
                temp=temp&0x0f;
                while(temp!=0x0f)
                {
                        delay(5);
                        temp=P3;
                        temp=temp&0x0f;
                        while(temp!=0x0f)
                        {                               
                                temp=P3;
                                switch(temp)
                                {
                                        case 0xde:num=5;       
                                                break;
                                        case 0xdd:num=6;
                                                break;
                                        case 0xdb:num=7;
                                                break;
                                        case 0xd7:num=8;
                                                break;
                                };       
                                while(temp!=0x0f)
                                {
                                        temp=P3;
                                        temp=temp&0x0f;

                                }                                                       
                                dula=1;
                                P0=table[num-1];
                                dula=0;               
                        };

                       
                };
//第三列鍵盤掃描程序
                P3=0xbf;
                temp=P3;
                temp=temp&0x0f;
                while(temp!=0x0f)
                {
                        delay(5);
                        temp=P3;
                        temp=temp&0x0f;
                        while(temp!=0x0f)
                        {                               
                                temp=P3;
                                switch(temp)
                                {
                                        case 0xbe:num=9;       
                                                break;
                                        case 0xbd:num=10;
                                                break;
                                        case 0xbb:num=11;
                                                break;
                                        case 0xb7:num=12;
                                                break;
                                };       
                                while(temp!=0x0f)
                                {
                                        temp=P3;
                                        temp=temp&0x0f;

                                }                                                       
                                dula=1;
                                P0=table[num-1];
                                dula=0;               
                        };

                       
                };
//第四列鍵盤掃描程序
                P3=0x7f;
                temp=P3;
                temp=temp&0x0f;
                while(temp!=0x0f)
                {
                        delay(5);
                        temp=P3;
                        temp=temp&0x0f;
                        while(temp!=0x0f)
                        {                               
                                temp=P3;
                                switch(temp)
                                {
                                        case 0x7e:num=13;       
                                                break;
                                        case 0x7d:num=14;
                                                break;
                                        case 0x7b:num=15;
                                                break;
                                        case 0x77:num=16;
                                                break;
                                };       
                                while(temp!=0x0f)
                                {
                                        temp=P3;
                                        temp=temp&0x0f;

                                }                                                       
                                dula=1;
                                P0=table[num-1];
                                dula=0;               
                        };

                       
                };

        };
               
}

相關(guān)帖子

回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

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

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

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