標(biāo)題: C51鍵盤循環(huán)顯示數(shù)字 [打印本頁(yè)]

作者: gjvs    時(shí)間: 2017-6-11 14:29
標(biāo)題: C51鍵盤循環(huán)顯示數(shù)字
#include<reg52.h>
#define segport P0
#define seatport P1
#define keyport P2
unsigned char segt[17]={0x3f,0x06,0x5b,0x4f,0x66,
                                                                                                0x6d,0x7d,0x07,0x7f,0x6f,
                                                                                                0x77,0x7c,0x39,0x5e,0x79,0x71,0x00};
unsigned char seatt[6]={0x1f,0x2f,0x37,0x3b,0x3d,0x3e};

void delay(int s)
{
  for(s;s>0;s--);
}

void showsingle(int d)
{
                seatport=seatt[5];
                segport=segt[d];
                delay(50);
}

void delay1ms_k(int s)
{
                int j;
        for(s;s>0;s--)
                        for(j=150;j>0;j--);
       
}
int keys()
{
        int key,row,col;
        unsigned char rowcode,colcode;
        key=16;
        keyport=0x0ff;
        keyport=keyport&0x0f;
        if((keyport&0x0f)!=0x0f)
        {
                delay1ms_k(10);
                if((keyport&0x0f)!=0x0f)
                {
                        colcode=(keyport&0x0f);
                        switch(colcode)
                        {
                                        case 0x07:col=3;break;
                                        case 0x0b:col=2;break;
                                        case 0x0d:col=1;break;
                                        case 0x0e:col=0;break;
                        }
                        keyport=0x0f0;
                        rowcode=(keyport&0x0f0);
                       
                        switch(rowcode)
                        {
                                        case 0x70:row=3;break;
                                        case 0x0b0:row=2;break;
                                        case 0x0d0:row=1;break;
                                        case 0x0e0:row=0;break;                       
                        }
                        key=row*4+col;
                }
  }
        return key;
}

void main(void)
{
        int key=16;
       
        while(1)
        {
                key=keys();
                       
                showsingle(key);
        }
}






歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1