專注電子技術(shù)學(xué)習(xí)與研究
當(dāng)前位置:單片機(jī)教程網(wǎng) >> MCU設(shè)計實例 >> 瀏覽文章

四位二進(jìn)制轉(zhuǎn)十進(jìn)制計算顯示程序

作者:佚名   來源:本站原創(chuàng)   點(diǎn)擊數(shù):  更新時間:2010年09月04日   【字體:

此程序是根據(jù)自己的單片機(jī)板子寫的,四位共陽數(shù)碼管。
k1-k4是板子上的4個鍵 用來進(jìn)行二進(jìn)制輸入,因為按鍵只有按下和沒有按下兩種狀態(tài),
十進(jìn)制的數(shù)值就顯示在數(shù)碼管上.
板子的硬件資料請看這里http://www.torrancerestoration.com/mcu/1019.html


#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==0&K2==0)    
{
   wx1=1;
   P1=smg[4];
   delayms(10);
   wx1=0;wx2=0;wx3=0;wx4=0;
   P2=yy[4];
   delayms(10);
 }

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

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

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

if(K2==0&K4==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==0&K4==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)閉窗口

相關(guān)文章