硬件原理图:
74HC377功用图:
源程序:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
#define uint unsigned int
#define ulong unsigned long
sbit A9=P2^1; //
sbit A10=P2^2; //
sbit W_R=P3^6; //
sbit LED_CS=P1^4;
sbit A10=P2^2; //
sbit W_R=P3^6; //
sbit LED_CS=P1^4;
//数码管取表数据0-F
uchar LED_DATA[16]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E};
uchar LED_DATA[16]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E};
uchar LED1,LED2,LED3,LED4,LED5,LED6,LED7,LED8;//界说8个数码管显现数据存储地址空间
void delay(unsigned int count);//延时程序
void display(void); //数码管显现子程序
void delay(unsigned int count);//延时程序
void display(void); //数码管显现子程序
/*************延时子程序start**************/
void delay(unsigned int count)
{
unsigned int i,j;
for(i=0;i for(j=0;j<50;j++);
}
/*************延时子程序end****************/
void delay(unsigned int count)
{
unsigned int i,j;
for(i=0;i
}
/*************延时子程序end****************/
/************************/
void display(void)
{
uchar speed;//界说数码管动态扫描频率
void display(void)
{
uchar speed;//界说数码管动态扫描频率
speed=3;
P0=LED6;
A9=0;
W_R=0;
W_R=1;
A9=1;
A9=0;
W_R=0;
W_R=1;
A9=1;
P0=0xfd;
A10=0;
W_R=0;
W_R=1;
A10=1;
delay(speed);
////////////////
P0=LED5;
A9=0;
W_R=0;
W_R=1;
A9=1;
A10=0;
W_R=0;
W_R=1;
A10=1;
delay(speed);
////////////////
P0=LED5;
A9=0;
W_R=0;
W_R=1;
A9=1;
P0=0xfe;
A10=0;
W_R=0;
W_R=1;
A10=1;
delay(speed);
//////////////
P0=LED8;
A9=0;
W_R=0;
W_R=1;
A9=1;
A10=0;
W_R=0;
W_R=1;
A10=1;
delay(speed);
//////////////
P0=LED8;
A9=0;
W_R=0;
W_R=1;
A9=1;
P0=0xfb;
A10=0;
W_R=0;
W_R=1;
A10=1;
delay(speed);
/////////////
P0=LED7;
A9=0;
W_R=0;
W_R=1;
A9=1;
A10=0;
W_R=0;
W_R=1;
A10=1;
delay(speed);
/////////////
P0=LED7;
A9=0;
W_R=0;
W_R=1;
A9=1;
P0=0xf7;
A10=0;
W_R=0;
W_R=1;
A10=1;
delay(speed);
/////////////
P0=LED1;
A9=0;
W_R=0;
W_R=1;
A9=1;
A10=0;
W_R=0;
W_R=1;
A10=1;
delay(speed);
/////////////
P0=LED1;
A9=0;
W_R=0;
W_R=1;
A9=1;
P0=0xef;
A10=0;
W_R=0;
W_R=1;
A10=1;
delay(speed);
////////////
P0=LED2;
A9=0;
W_R=0;
W_R=1;
A9=1;
A10=0;
W_R=0;
W_R=1;
A10=1;
delay(speed);
////////////
P0=LED2;
A9=0;
W_R=0;
W_R=1;
A9=1;
P0=0xdf;
A10=0;
W_R=0;
W_R=1;
A10=1;
delay(speed);
///////////////
P0=LED3;
A9=0;
W_R=0;
W_R=1;
A9=1;
A10=0;
W_R=0;
W_R=1;
A10=1;
delay(speed);
///////////////
P0=LED3;
A9=0;
W_R=0;
W_R=1;
A9=1;
P0=0xbf;
A10=0;
W_R=0;
W_R=1;
A10=1;
delay(speed);
/////////////////
P0=LED4;
A9=0;
W_R=0;
W_R=1;
A9=1;
A10=0;
W_R=0;
W_R=1;
A10=1;
delay(speed);
/////////////////
P0=LED4;
A9=0;
W_R=0;
W_R=1;
A9=1;
P0=0x7f;
A10=0;
W_R=0;
W_R=1;
A10=1;
delay(speed);
}
A10=0;
W_R=0;
W_R=1;
A10=1;
delay(speed);
}
/***********主程序************/
main()
{
uint i;
main()
{
uint i;
Delay1ms(1000);
P0=0X00;
LED_CS=1;
A9=1;
A10=1;
LED_CS=1;
A9=1;
A10=1;
Delay1ms(100);
//显现12345678
LED1=LED_DATA[1];
LED2=LED_DATA[2];
LED3=LED_DATA[3];
LED4=LED_DATA[4];
LED5=LED_DATA[5];
LED6=LED_DATA[6];
LED7=LED_DATA[7];
LED8=LED_DATA[8];
LED1=LED_DATA[1];
LED2=LED_DATA[2];
LED3=LED_DATA[3];
LED4=LED_DATA[4];
LED5=LED_DATA[5];
LED6=LED_DATA[6];
LED7=LED_DATA[7];
LED8=LED_DATA[8];
while(1)
{
display();
}
}