发布时间:2019-08-27 19:38:07
8位数码管动态显示,单片机直接片选,先显示201903,再显示abcdef,再显示123456,用C语言编程 ,重复循环,仿真试试。
#include<reg51.h>
#define uchar unsigned char
// 此表为 LED 的字模 0 1 2 3 4 5 6 7 8 9 a b c d e f
unsigned char code LED7Code[] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71};
void delay(uchar z)
{
uchar i,j;
for(i=0;i<120;i++)
for(j=0;j<z;j++);
}
void main()
{
uchar k;
while(1)
{
for(k=0;k<50;k++)
{
P0=0xff;
P2=LED7Code[0];
P0=0xfe;
delay(5);
P0=0xff;
P2=LED7Code[0];
P0=0xfd;
delay(5);
P0=0xff;
P2=LED7Code[2];
P0=0xfb;
delay(5);
P0=0xff;
P2=LED7Code[0];
P0=0xf7;
delay(5);
P0=0xff;
P2=LED7Code[1];
P0=0xef;
delay(5);
P0=0xff;
P2=LED7Code[9];
P0=0xdf;
delay(5);
P0=0xff;
P2=LED7Code[0];
P0=0xbf;
delay(5);
P0=0xff;
P2=LED7Code[3];
P0=0x7f;
delay(5);
}
for(k=0;k<50;k++)
{
P0=0xff;
P2=LED7Code[0];
P0=0xfe;
delay(5);
P0=0xff;
P2=LED7Code[0];
P0=0xfd;
delay(5);
P0=0xff;
P2=LED7Code[10];
P0=0xfb;
delay(5);
P0=0xff;
P2=LED7Code[11];
P0=0xf7;
delay(5);
P0=0xff;
P2=LED7Code[12];
P0=0xef;
delay(5);
P0=0xff;
P2=LED7Code[13];
P0=0xdf;
delay(5);
P0=0xff;
P2=LED7Code[14];
P0=0xbf;
delay(5);
P0=0xff;
P2=LED7Code[15];
P0=0x7f;
delay(5);
}
for(k=0;k<50;k++)
{
P0=0xff;
P2=LED7Code[0];
P0=0xfe;
delay(5);
P0=0xff;
P2=LED7Code[0];
P0=0xfd;
delay(5);
P0=0xff;
P2=LED7Code[1];
P0=0xfb;
delay(5);
P0=0xff;
P2=LED7Code[2];
P0=0xf7;
delay(5);
P0=0xff;
P2=LED7Code[3];
P0=0xef;
delay(5);
P0=0xff;
P2=LED7Code[4];
P0=0xdf;
delay(5);
P0=0xff;
P2=LED7Code[5];
P0=0xbf;
delay(5);
P0=0xff;
P2=LED7Code[6];
P0=0x7f;
delay(5);
}
}
}