+

来自「51开发板protuse仿真电路」· 代码 · 共 191 行

TXT
191
字号
   /* 广州手之创电子科技有限公司
公司网址首页:http://www.soochange.com
      		  http://www.sochange.cn
公司淘宝网店:http://sochange.taobao.com/
联系电话(传真):020-62199826
联系电话:020-28991152
公司官方qq(添加好友者请写上贵公司名称,本q只对企业客户开发):779827265
技术qq1:956626567
技术qq2:974205767
 */
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit duan=P1^0;	//数码管端码使能端
sbit wei=P1^1;//数码管位码使能端
sbit Leden=P1^2;//LED灯控制端
sbit Line=P1^3;//点阵行控制端							   


uchar code table[]=	{
						0x80,0x3f,0x76,0x5e,
						0x07,0x7f,0x6f,0x39,
						0x66,0x6d,0x7d,0x7c,
						0x06,0x5b,0x4f,0x77,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()
{
P0=0X00; //关闭点阵
Line=0;
P0=0XFF; //关闭LED灯
Leden=0;
num=17;
duan=1;
P0=0;
duan=0;
wei=1;
P0=0x00;
wei=0;

while(1)
   {
    display(keyscan());
   }
}
void display(uchar aa)
{
    duan=1;
    P0=table[aa-1];
    duan=0;  
}
uchar keyscan()
{
    P2=0xfe;
    temp=P2;
    temp=temp&0xf0;
    while(temp!=0xf0)
     {
      delay(5);
      temp=P2;
      temp=temp&0xf0;
      while(temp!=0xf0)
      {
       temp=P2;
      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=P2;
        temp=temp&0xf0;
       }
      }
     }

    P2=0xfd;
    temp=P2;
    temp=temp&0xf0;
    while(temp!=0xf0)
     {
      delay(5);
      temp=P2;
      temp=temp&0xf0;
      while(temp!=0xf0)
      {
       temp=P2;
      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=P2;
        temp=temp&0xf0;
       }
      }
     }


    P2=0xfb;
    temp=P2;
    temp=temp&0xf0;
    while(temp!=0xf0)
     {
      delay(5);
      temp=P2;
      temp=temp&0xf0;
      while(temp!=0xf0)
      {
       temp=P2;
      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=P2;
        temp=temp&0xf0;
       }
      }
     }


    P2=0xf7;
    temp=P2;
    temp=temp&0xf0;
    while(temp!=0xf0)
     {
      delay(5);
      temp=P2;
      temp=temp&0xf0;
      while(temp!=0xf0)
      {
       temp=P2;
      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=P2;
        temp=temp&0xf0;
       }
      }
     }
return num;

}
 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?