新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 基于單片機(jī)的四位二進(jìn)制轉(zhuǎn)十進(jìn)制計(jì)算顯示程序

基于單片機(jī)的四位二進(jìn)制轉(zhuǎn)十進(jìn)制計(jì)算顯示程序

作者: 時(shí)間:2012-09-10 來源:網(wǎng)絡(luò) 收藏

是根據(jù)自己的板子寫的,共陽數(shù)碼管。

本文引用地址:http://butianyuan.cn/article/170906.htm

k1-k4是板子上的4個(gè)鍵 用來進(jìn)行輸入,因?yàn)榘存I只有按下和沒有按下兩種狀態(tài),

的數(shù)值就在數(shù)碼管上.

#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;
}
}



評論


相關(guān)推薦

技術(shù)專區(qū)

關(guān)閉