標(biāo)題: 51矩陣按鍵 [打印本頁(yè)]

作者: 737161704    時(shí)間: 2017-7-6 19:43
標(biāo)題: 51矩陣按鍵
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
uchar code table1[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uchar code table3[]={
0x1e,0x2e,0x4e,0x8e,
0x1d,0x2d,0x4d,0x8d,
0x1b,0x2b,0x4b,0x8b,
0x17,0x27,0x47,0x87};
uchar code table4[]={
0x0e,0x0e,0x0e,0x0e,
0x0d,0x0d,0x0d,0x0d,
0x0b,0x0b,0x0b,0x0b,
0x07,0x07,0x07,0x07};
void delayms(uint);
uchar key,num1,temp;
void main()
{
        P0=0x00;
        wela=0;
        dula=0;
        while(1)
        {
                 for(num1=0;num1<16;num1++)
                 {
                        P0=table1[key];        //數(shù)碼
                        dula=1;
                        dula=0;
                        P3=table3[num1];
                        temp=P3;
                        if(temp==table4[num1])
                        {
                                delayms(10);
                                temp=P3;
                                if(temp==table4[num1])
                                key=num1;       
                        }
                                while(temp==table4[num1])
                                {
                                        temp=P3;                       
                                }
                }
        }
}
void delayms(uint xms)
{
        uint i,j;
        for(i=xms;i>0;i--)
                for(j=125;j>0;j--);
}






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