3650|5

78

帖子

0

TA的资源

一粒金砂(初级)

楼主
 

各位大虾 帮忙看一下这个4*4键盘扫描程序有什么问题 在此谢过 [复制链接]

int keyscan()
{
P0=0x0f;
if(P0&0x0f!=0x0f)
{
      delay();
   P04=0;
   P05=1;
   P06=1;
   P07=1;
   if(P0!=0xef)
   {
    lie=1;
    switch(P0)
    {
    case 0xee:
     hang=1;
     break;
    case 0xed:
     hang=2;
    case 0xeb:
     hang=3;
    case 0xe7:
     hang=4;
    default:
     break;
    }
   }
   P04=1;
   P05=0;
   P06=1;
   P07=1;
   if(P0!=0xdf)
   {
    lie=2;
    switch(P0)
    {
    case 0xde:
     hang=1;
     break;
    case 0xdd:
     hang=2;
     break;
    case 0xdb:
     hang=3;
     break;
    case 0xd7:
     hang=4;
     break;
    default:
     break;
    }
   }
   P04=1;
   P05=1;
   P06=0;
   P07=1;
   if(P0!=0xbf)
   {
    lie=3;
    switch(P0)
    {
    case 0xbe:
     hang=1;
     break;
    case 0xbd:
     hang=2;
     break;
    case 0xbb:
     hang=3;
     break;
    case 0xb7:
     hang=4;
     break;
    default:
     break;
    }
   }
   P04=1;
   P05=1;
   P06=1;
   P07=0;
   if(P0!=0x7f)
   {
    lie=4;
    switch(P0)
    {
    case 0x7e:
     hang=1;
     break;
    case 0x7d:
     hang=2;
     break;
    case 0x7b:
     hang=3;
     break;
    case 0x77:
     hang=4;
     break;
    default:
     break;
    }
    a[0]=hang;
    a[1]=lie;
    return a;
  }
  else
  {
   return 0;
  }
   }
}

最新回复

谢过了,呵呵。。。。  详情 回复 发表于 2009-11-8 19:17
点赞 关注

回复
举报

77

帖子

0

TA的资源

一粒金砂(初级)

沙发
 
写得太复杂;了
 
 

回复

65

帖子

0

TA的资源

一粒金砂(初级)

板凳
 
哥,你这程序毛病一大堆的啊
 
 
 

回复

69

帖子

0

TA的资源

一粒金砂(初级)

4
 
#include
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^6;
sbit wela=P2^7;
sbit key1=P3^4;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,0};
uchar num,temp,num1;
void delay(uint z)
{
        uint x,y;
        for(x=z;x>0;x--)
                for(y=110;y>0;y--);
}
uchar keyscan();
void display(uchar aa);
void main()
{
        num=17;
        dula=1;
        P0=0;
        dula=0;
        wela=1;
        P0=0xc0;
        wela=0;
       
        while(1)
                {
                        display(keyscan());
                }
}
void display(uchar aa)
{
                        dula=1;
                        P0=table[aa-1];
                        dula=0;               
}
uchar keyscan()
{
                        P3=0xfe;
                        temp=P3;
                        temp=temp&0xf0;
                        while(temp!=0xf0)
                                {
                                        delay(5);
                                        temp=P3;
                                        temp=temp&0xf0;
                                        while(temp!=0xf0)
                                        {
                                                temp=P3;
                                        switch(temp)
                                                {
                                                        case 0xee:num=1;
                                                                break;
                                                        case 0xde:num=2;
                                                                break;
                                                        case 0xbe:num=3;
                                                                break;
                                                        case 0x7e:num=4;
                                                                break;
                                                }
                                        while(temp!=0xf0)
                                                {
                                                        temp=P3;
                                                        temp=temp&0xf0;
                                                }
                                        }
                                }

                        P3=0xfd;
                        temp=P3;
                        temp=temp&0xf0;
                        while(temp!=0xf0)
                                {
                                        delay(5);
                                        temp=P3;
                                        temp=temp&0xf0;
                                        while(temp!=0xf0)
                                        {
                                                temp=P3;
                                        switch(temp)
                                                {
                                                        case 0xed:num=5;
                                                                break;
                                                        case 0xdd:num=6;
                                                                break;
                                                        case 0xbd:num=7;
                                                                break;
                                                        case 0x7d:num=8;
                                                                break;
                                                }
                                        while(temp!=0xf0)
                                                {
                                                        temp=P3;
                                                        temp=temp&0xf0;
                                                }
                                        }
                                }


                        P3=0xfb;
                        temp=P3;
                        temp=temp&0xf0;
                        while(temp!=0xf0)
                                {
                                        delay(5);
                                        temp=P3;
                                        temp=temp&0xf0;
                                        while(temp!=0xf0)
                                        {
                                                temp=P3;
                                        switch(temp)
                                                {
                                                        case 0xeb:num=9;
                                                                break;
                                                        case 0xdb:num=10;
                                                                break;
                                                        case 0xbb:num=11;
                                                                break;
                                                        case 0x7b:num=12;
                                                                break;
                                                }
                                        while(temp!=0xf0)
                                                {
                                                        temp=P3;
                                                        temp=temp&0xf0;
                                                }
                                        }
                                }


                        P3=0xf7;
                        temp=P3;
                        temp=temp&0xf0;
                        while(temp!=0xf0)
                                {
                                        delay(5);
                                        temp=P3;
                                        temp=temp&0xf0;
                                        while(temp!=0xf0)
                                        {
                                                temp=P3;
                                        switch(temp)
                                                {
                                                        case 0xe7:num=13;
                                                                break;
                                                        case 0xd7:num=14;
                                                                break;
                                                        case 0xb7:num=15;
                                                                break;
                                                        case 0x77:num=16;
                                                                break;
                                                }
                                        while(temp!=0xf0)
                                                {
                                                        temp=P3;
                                                        temp=temp&0xf0;
                                                }
                                        }
                                }
return num;

}

仔细参考下这个程序。你的程序真的是一大堆错误。
 
 
 

回复

75

帖子

0

TA的资源

一粒金砂(初级)

5
 
#include
unsigned char temp;
unsigned char code table[]={0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};

void delay_10ms()                         /*延时10MS*/
{
        unsigned char i,j,k;
        for(i=0;i<2;i++)
                for(j=0;j<20;j++)
                        for(k=0;k<248;k++);  
}
void scanf(unsigned char key) /*LED扫描与显示*/
{
        switch(key)
        {
                case 0xe7:P0=0x3f;break;
                case 0xeb:P0=0x06;break;
                case 0xed:P0=0x5b;break;
                case 0xee:P0=0x4f;break;
                case 0xd7:P0=0x66;break;
                case 0xdb:P0=0x6d;break;
                case 0xdd:P0=0x7d;break;
                case 0xde:P0=0x07;break;
                case 0xb7:P0=0x7f;break;
                case 0xbb:P0=0x6f;break;
                case 0xbd:P0=0x77;break;
                case 0xbe:P0=0x7c;break;
                case 0x77:P0=0x39;break;
                case 0x7b:P0=0x5e;break;
                case 0x7d:P0=0x79;break;
                case 0x7e:P0=0x71;break;
                default:  P0=0x00;break;
        }       
}
void control(temp)                        /*确定哪个健按下啊*/
{        temp=temp&0x0f;
                        if( temp!=0x0f)
                                delay_10ms();
                                if( temp!=0x0f)
                                        scanf(P3);
                                        while(temp!=0x0f)
                                                {
                                                         temp=P3;
                                                        temp=temp&0x0f;
                                                }
}


void main()
{       
        unsigned char a;       
                while(1)
                        {
                                 P3=0xff;
                                P3_4=0;                           //确定行
                                a=P3;
                                control(a);
                                P3=0xff;
                                P3_5=0;
                                a=P3;
                                control(a);
                                P3=0xff;
                                P3_6=0;
                                a=P3;
                                control(a);
                                P3=0xff;
                                P3_7=0;
                                a=P3;
                                control(a);
               
                                                }

}
自己写的,参考下
 
 
 

回复

73

帖子

0

TA的资源

一粒金砂(初级)

6
 
谢过了,呵呵。。。。
 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/7 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表