单片机 > 单片机程序设计 > 详情

51单片机一个输出口显示多位输出

发布时间:2023-07-25 发布时间:
|

电路图


#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


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);


}


}


}



『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
交叉编译器 arm-linux-gnueabi 和 arm-linux-gnueabihf 的区别