標(biāo)題: 矩陣按鍵,按著沒(méi)反應(yīng),編譯沒(méi)錯(cuò),但沒(méi)現(xiàn)象 [打印本頁(yè)]

作者: 風(fēng)案件快遞    時(shí)間: 2017-12-9 11:05
標(biāo)題: 矩陣按鍵,按著沒(méi)反應(yīng),編譯沒(méi)錯(cuò),但沒(méi)現(xiàn)象
代碼如下
#include <stc15f2k60s2.h>
unsigned char s0;
int temp;
void keyscan16();
void delay(int a);
unsigned char s0=0;


void main()
{P2=0XA0;P0=0X00;P2=0X80;P0=0xff;

        while(1)
        {keyscan16()        ;
                if(s0==1)
        {s0=0;
                P2=0XC0;
                P0=0X01;
                P2=0XFF;
                P0=0XC0;
        }
        else if(s0==2)
        {s0=0;
                P2=0xc0;
                P0=0X02;
                P2=0XFF;
                P0=0XF9;
               
        }
       
}
       
}
       
       
       
void delay(int a)
{int i,b;
        for(i=a;a--;a>0)
        {for(b=850;b--;b>0);}
}


void keyscan16()
{
        P3=0x7f;
        temp=P3&0x0f;
        if(temp!=0x0f)
        {delay(5);
                temp=P3&0X0F;
                if(temp!=0x0f)
                {temp=P3;
                        switch (temp)
                                {case 0x7e:s0=1;break;
                                case 0x7d:s0=2;break;
                                case 0x7b:s0=3;break;
                                case 0x77:s0=4;break;
                        }
                }
                while(temp!=0x0f)
                {temp&=0x0f;
                }
        }

P3=0XBF;temp=P3&0X0F;
if(temp!=0x0f)
{delay(5);
        temp=P3&0XBF;
        if(temp!=0x0f)
        {temp=P3;
                switch(temp)
                        {case 0xbe:s0=5;break;
                                case 0xbd:s0=6;break;
                                case 0xbb:s0=7;break;
                                case 0xb7:s0=8;break;
                }
                }
                while(temp!=0x0f)
                {temp&=0x0f;
                }       
        }
        P3=0XDF;temp=P3&0X0F;
        if(temp!=0x0f)
        {delay(5);
                temp=P3&0x0f;
                if(temp!=0x0f)
                {temp=P3;
                        switch(temp)
                        {case 0xbe:s0=9;break;
                                case 0xbd:s0=10;break;
                                case 0xbb:s0=11;break;
                                case 0xb7:s0=12;break;
                        }
                        while(temp!=0x0f)
                        {temp=P3&0x0f;
                        }
                }
               
               
        }
                P3=0X7F;temp=P3&0X0F;
        if(temp!=0x0f)
        {delay(5);
                temp=P3&0x0f;
                if(temp!=0x0f)
                {temp=P3;
                        switch(temp)
                        {case 0x7e:s0=13;break;
                                case 0x7d:s0=14;break;
                                case 0x7b:s0=15;break;
                                case 0x77:s0=16;break;
                        }
                        while(temp!=0x0f)
                        {temp=P3&0x0f;
                        }
                }
               
               
        }       
}







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