新闻中心

EEPW首页 > 嵌入式系统 > 设计应用 > 基于单片机的四位二进制转十进制计算显示程序

基于单片机的四位二进制转十进制计算显示程序

作者:时间:2012-09-10来源:网络收藏

是根据自己的板子写的,共阳数码管。

本文引用地址:http://www.eepw.com.cn/article/170906.htm

k1-k4是板子上的4个键 用来进行输入,因为按键只有按下和没有按下两种状态,

的数值就在数码管上.

#include reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar code smg[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar data yy[]={0xff,0xfe,0xfc,0xf8,0xf0,0xfe0,0xc0,0x80,0x00};
uint a;

sbit K1=P3^0;
sbit K2=P3^1;
sbit K3=P3^2;
sbit K4=P3^3;

sbit P20=P2^0;
sbit P22=P2^2;

sbit wx1=P0^0;
sbit wx2=P0^1;
sbit wx3=P0^2;
sbit wx4=P0^3;

void delayms(uint a)
{
uchar i,j;
for(i=a;i>0;i--)
for(j=110;j>0;j--);
}

void main()
{
while(1)
{
{
if(K1==0)
{
wx1=1;
P1=smg[0];
wx2=0;wx3=0;wx4=0;
P2=yy[0];
}


if(K2==0)
{
wx1=1;
P1=smg[1];
wx2=0;wx3=0;wx4=0;
P2=yy[1];
}


if(K3==0)
{
wx1=1;
P1=smg[2];
wx2=0;wx3=0;wx4=0;
P2=yy[2];
}

if(K4==0)
{
wx1=1;
P1=smg[3];
wx2=0;wx3=0;wx4=0;
P2=yy[3];
}

if(K1==0K2==0)
{
wx1=1;
P1=smg[4];
delayms(10);
wx1=0;wx2=0;wx3=0;wx4=0;
P2=yy[4];
delayms(10);
}

if(K1==0K3==0)
{
wx1=1;
P1=smg[5];
delayms(10);
wx1=0;wx2=0;wx3=0;wx4=0;
P2=yy[5];
delayms(10);
}

if(K1==0K4==0)
{
wx1=1;
P1=smg[6];
delayms(10);
wx1=0;wx2=0;wx3=0;wx4=0;
P2=yy[6];
delayms(10);
}

if(K2==0K3==0)
{
wx1=1;
P1=smg[7];
delayms(10);
wx1=0;wx2=0;wx3=0;wx4=0;
P2=yy[7];
delayms(10);
}

if(K2==0K4==0)
{
P20=1;P22=1;
wx1=1;
P1=smg[8];
delayms(10);
wx1=0;wx2=0;wx3=0;wx4=0;
P2=yy[8];
delayms(10);
}

if(K3==0K4==0)
{
wx1=1;
P1=smg[9];
delayms(10);
wx1=0;wx2=0;wx3=0;wx4=0;
P2=yy[8];
delayms(10);
}
}
P2=0xff;
}
}



评论


相关推荐

技术专区

关闭