分两个版本,实现的功能类似
注意:要想八个八段数码管都显示内容则必须将延时降低并且方式是来回快速刷新
#include <reg52.h>
sbit ce = P1^3;
sbit le1 = P1^4;
sbit le2 = P1^5;
char code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
char code select[] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
void delay( unsigned int xms){
unsigned char i,j;
for(i=xms;i>0;i--)
for(j=300;j>0;j--);
}
void main(){
unsigned char display_number = 0;
unsigned char select_number = 0;
ce = 0;
le1 = 0;
le2 = 0;
while(1){
le1 = 1;
P0 = ~table[display_number];
le1 = 0;
le2 = 1;
P0 = select[select_number];
le2 = 0;
delay(6);
++display_number;
display_number %= 8;
++select_number;
select_number %= 8;
}
}
#include <reg52.h>
sbit ce = P1^3;
sbit le1 = P1^4;
sbit le2 = P1^5;
char code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
char code select[] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
void delay( unsigned int xms){
unsigned char i,j;
for(i=xms;i>0;i--)
for(j=300;j>0;j--);
}
void main(){
unsigned char display_number = 0;
unsigned char select_number = 0;
ce = 0;
le1 = 0;
le2 = 0;
while(1){
le2 = 1;
P0 = select[select_number];
le2 = 0;
delay(2000);
le1 = 1;
P0 = ~table[display_number];
le1 = 0;
delay(2000);
++display_number;
display_number %= 10;
}
}
网友评论