funnnn 发表于 2012-3-29 22:29:32

把为一体数码管+矩阵键盘 求指教!!!

想要实现按一个按键然后在八位数码管上显示,按第二个按键的时候第一个移位,显示两个数,就好比如计算器,请各位大侠指教指教。。。。。
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar num2,j;
uchar jianzhi;
uchar code num_table={0xc0,0xF9,       //共阳数码管0~9字形码         p;0x8c E;0x86
                                                0xA4,0xB0,0x99,0x92,
                                                0x82,0xF8,0x80,0x90,};
/******延时函数************/
void delay(uint z)
{
   uint x,y;
   for(x=z;x>0;x--)
      for(y=110;y>0;y--) ;
}
void init()
{
}
/**********3x4矩阵键盘扫描函数*********/
uchar keyscan()
{
    uchar temp,num; //num的初值要为无键盘按下时的返回值
/*********扫描第一行****************/
          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;
                        }
                                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=4;
                                        break;
                                case 0xdd:num=5;
                                        break;
                                case 0xbd:num=6;
                                        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=7;
                                        break;
                                case 0xdb:num=8;
                                        break;
                                case 0xbb:num=9;
                                        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=10;
                                        break;
                                case 0xd7:num=0;
                                        break;
                                case 0xb7:num=12;
                                        break;
                        }
                                while(temp!=0xf0)
                                {
                                  temp=P3;
                                  temp=temp&0xf0;
                                }
                }
          }
return num;
}
void mima(uchar t)
{
                if(t>=0&&t<8)
           {   
             jianzhi=t;                             
           }

}
void main()
{       
        uchar i,t;
        init();
        P2=0x00;
        while(1)
        {
               
                num2=keyscan();
                mima(num2);
                P0=t;      

                P2=i;
                i<<=1;
                if(i==0x00)
                i=0x01;
               
        }
}

funnnn 发表于 2012-3-29 22:32:12

第一次发帖   不好意思   不知道怎么添加附件
页: [1]
查看完整版本: 把为一体数码管+矩阵键盘 求指教!!!