打印

请教大家!

[复制链接]
1336|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
yangxu0703|  楼主 | 2008-4-13 10:01 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我是新手!请教大家个问题!自己用单片机编程目的是按键显示数字0-9,然后 在设置俩个键用于自加和自减!可是效果达不到,显示数字可以,但再按加减就好像不行!也许是抖动的问题,但不太清楚!请高手指点!
    #include<at89x51.h>
unsigned char code table[]={};//0-9

GETKEY(void)
{
    unsigned char column,line,key,i,temp;
    P1=0xf0;
    for(i=4;i>0;i--);
    temp=P1;
    column=P1;
    column|=0x0f;
    P1=0x0f;
    line=P1;
    line|=0xf0;
    key=column&line;
    return key;
     
    
}
 void main(void)
 {    unsigned char i,key;
         int j=-1;     
     while(1) 
     {
             key=GETKEY();
            switch(key)
     {    case 0xbb :      
                       for(i=255;i>0;i--);
                       P0=table[0];
                       j=0;

                       break;
        case 0x7e :    
                       for(i=255;i>0;i--);
                       P0=table[1];
                       j=1;
                       break;  
        case 0xbe :                           
                        for(i=255;i>0;i--);
                       P0=table[2];
                       j=2;
                       break;
        case 0xde :
                       for(i=255;i>0;i--);
                       P0=table[3] ;
                       j=3;
                       break;
        case 0xee :      
                       for(i=255;i>0;i--);
                       P0=table[4];
                       j=4;
                       break;
        
        case 0x7d :
                       for(i=255;i>0;i--);
                        P0=table[5];
                        j=5;
                        break;
        case 0xbd :  
                       for(i=255;i>0;i--);
                       P0=table[6];
                       j=6;
                       break;
        case 0xdd :       
                       for(i=255;i>0;i--);
                        P0=table[7];
                       j=7;
                       break; 
        case 0xed :
                       for(i=255;i>0;i--);
                       P0=table[8];
                       j=8;
                       break;

                        
        case 0x7b :       
                       for(i=255;i>0;i--);
                       P0=table[9];
                       j=9;
                       break;
        case 0xdb :   if(j==-1)
                          break;
                       else
                         if(j==9)
                           {   j=0;
                          for(i=255;i>0;i--); 
                           P0=table[j]; 
                         }       
                            else
                            for(i=255;i>0;i--);
                            j=j+1;
                            P0=table[j];
                            break;
        case 0xeb :  if(j==-1)
                       break;
                     else 
                       if(j==0)
                        { j=9;
                            for(i=255;i>0;i--);
                            P0=table[j];
                            
                        }

                      else 
                       for(i=255;i>0;i--);
                        j=j-1;
                        P0=table[j];
                        break;

       

      }
     }
 }

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

2

主题

2

帖子

0

粉丝