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

51單片機(jī)一個輸出口顯示多位輸出

作者:余春雨老師   來源:本站原創(chuàng)   點擊數(shù):  更新時間:2014年04月26日   【字體:

電路圖

#include"reg51.h"
sbit LE0=P3^0;
sbit LE1=P3^1;
sbit LE2=P3^2;
sbit LE3=P3^3;
int i,j,k;
int xx[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void yanchi(int ms)
{
  while(ms--)
    {
     for(i=0;i<100;i++);
    }
}
void main()
{
  while(1)
    {
      for(j=0;j<10000;j++)
        { 
          P2=xx[j/1000];//千
          LE3=0;
          yanchi(1);
          LE3=1;
          yanchi(1);
          LE3=0;  
          P2=xx[(j%1000)/100];//百
          LE2=0;
          yanchi(1);
          LE2=1;
          yanchi(1);
          LE2=0;
          P2=xx[(j%100)/10];//十
           LE1=0;
          yanchi(1);
          LE1=1;
          yanchi(1);
          LE1=0;         
          P2=xx[j%10];//個
          LE0=0;
          yanchi(1);
          LE0=1;
          yanchi(1);
          LE0=0;         
          yanchi(100);
        } 
    }
}
 
 
 
 
#include"reg51.h"
#include<intrins.h>
int i,j,k,ss;
int xx[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void yanchi(int ms)
{
  while(ms--)
    {
     for(i=0;i<100;i++);
    }
}
void main()
{
  while(1)
    {
      for(j=9900;j<10000;j++)
        {           
       
          P2=xx[j%10];//個
          P1=0X01;
          yanchi(1);      
          P1=0x00; 
   
          P2=xx[(j%100)/10];//十
          P1=0x02;       
          yanchi(1);
          P1=0x00;        
 
          P2=xx[(j%1000)/100];//百
          P1=0x04;
          yanchi(1);
          P1=0x00;
           
          
          P2=xx[j/1000];//千
          P1=0x08;
          yanchi(1);
          P1=0x00;
          
          if (j==9999)
              ss++;
          P2=xx[ss%10];//萬
          P1=0x10;
          yanchi(1);
          P1=0x00;
          P2=xx[(ss%100)/10];//十萬
          P1=0x20;
          yanchi(1);
          P1=0x00;
          P2=xx[(ss%1000)/100];//百萬
          P1=0x40;
          yanchi(1);
          P1=0x00;
          P2=xx[ss/1000];//千萬
          P1=0x80;
          yanchi(1);
          P1=0x00;
          
          yanchi(10);
          
        } 
    }
}
 
關(guān)閉窗口

相關(guān)文章