單片機實驗板2011_V1.0 - 74HC377控制數(shù)碼管顯示
硬件原理圖:
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;
//數(shù)碼管取表數(shù)據(jù)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個數(shù)碼管顯示數(shù)據(jù)存儲地址空間
void delay(unsigned int count);//延時程序
void display(void); //數(shù)碼管顯示子程序
void delay(unsigned int count);//延時程序
void display(void); //數(shù)碼管顯示子程序
/*************延時子程序start**************/
void delay(unsigned int count)
{
unsigned int i,j;
for(i=0;i
}
/*************延時子程序end****************/
/************************/
void display(void)
{
uchar speed;//定義數(shù)碼管動態(tài)掃描頻率
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;
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];
while(1)
{
display();
}
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();
}
}
評論