用74HC595驱动八位动态数码管(直接在74HC595 控制LED流水灯的程序上整合动态数码管的程序而成 )
#include "reg51.h"
#include "intrins.h"
typedef unsigned int u16;
typedef unsigned char u8;
#define GPIO_LED P2
sbit SRCLK=P3^6;
sbit RCLK=P3^5;
sbit SER=P3^4;
u8 code smgduan[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,
0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void hc595(u8 byte)
{
u8 a;
SRCLK=1;
RCLK=1;
for(a=0;a<8;a++)
{
SER=byte>>7;
byte<<=1;
SRCLK=0;
_nop_();
SRCLK=1;
}
RCLK=0;
_nop_();
RCLK=1;
}
void delay(u16 i)
{
while(i--);
}
void main()
{
u8 ledNum;
u8 j;
ledNum = ~0x01;
while(1)
{
for(j=0;j<8;j++)
{
hc595(ledNum);
P0=smgduan[j];
ledNum = _crol_(ledNum, 1);
delay(50000);
}
}
}
|