求助,矩阵键盘 反转程序一直返回0XFF,去掉return 0xff,...

2020-01-16 18:35发布

本帖最后由 fangwenbo0002 于 2016-9-30 21:35 编辑

捕获.JPG (26.56 KB, 下载次数: 0) 下载附件 电路图 2016-9-30 21:26 上传 #include "key.h"
#include "STC15F2K60S2.h"
#include "lcd1202.h"
//#define keydat P0
#define uchar unsigned char

uchar Key_Scan()
{
uchar keyval,key_h,key_l;
P0=0x0f;
key_l=P0&0x0f;
if(key_l!=0x0f)
{
  delay1ms(10);
  if(key_l!=0x0f)
  {
   key_l=P0&0x0f;
   P0=key_l|0xf0;
   key_h=P0&0xf0;
   key_l=key_l&0x0f;
   keyval=key_h+key_l;
   //Lcd_Show_String(keyval,0,0);
   return keyval;
  }
  
}return 0xff;

}
void Key_Display()
{
uchar key;
key=Key_Scan();
if(key!=0xff)
{
  switch(key)
  {
   case 0xee: Lcd_Show_String("1:ee",0,0);break;
   case 0xed: Lcd_Show_String("1:ed",0,0);break;
   case 0xeb: Lcd_Show_String("1:eb",0,0);break;
   case 0xe7: Lcd_Show_String("1:e7",0,0);break;
   case 0xde: Lcd_Show_String("1:de",0,0);break;
   case 0xdd: Lcd_Show_String("1:dd",0,0);break;
   case 0xdb: Lcd_Show_String("1:db",0,0);break;
   case 0xd7: Lcd_Show_String("1:d7",0,0);break;
   case 0xbe: Lcd_Show_String("1:be",0,0);break;
   case 0xbd: Lcd_Show_String("1:bd",0,0);break;
   case 0xbb: Lcd_Show_String("1:bb",0,0);break;
   case 0xb7: Lcd_Show_String("1:b7",0,0);break;
   case 0x7e: Lcd_Show_String("1:7e",0,0);break;
   case 0x7d: Lcd_Show_String("1:7d",0,0);break;
   case 0x7b: Lcd_Show_String("1:7b",0,0);break;
   case 0x77: Lcd_Show_String("1:77",0,0);break;
  
  }
}
else
  Lcd_Show_String("0xff",0,0);
}


主函数
int main(void)
{

P1M0=0x00;
P1M1=0x00;
P2M0=0x00;
P2M1=0x00;
P3M0=0x00;
P3M1=0x00;
P4M0=0x00;
P4M1=0x00;
Lcd_Init();
  

while(1)
{
  
  Key_Display();

}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
3条回答
fangwenbo0002
2020-01-17 04:01
我已经弄好了,修改后的程序为:
uchar Key_Scan()
{
        uchar keyval,key_h,key_l;
        P0=0x0f;  
        delay1ms(1);
        key_l=P0&0x0f;
        if(key_l!=0x0f)
        {
                        delay1ms(10);
                        key_l=P0&0x0f;
                        if(key_l!=0x0f);
                        {
                                key_l=P0&0x0f;
                                P0=key_l|0xf0;
                                delay1ms(1);
                                key_h=P0&0xf0;
                                //key_l=key_l&0x0f;
                                keyval=key_h+key_l;

                                return keyval;
                        }

        }return 0xff;

}

一周热门 更多>