/*该程序为两片74HC595级联实现8位7段LED动态显示的驱动测试程序
在8个7段LED上显示"01234567"*/
#include
#define uchar unsigned char
uchar bdata OutByte; /*定义待输出字节变量*/
sbit Bit_Out=OutByte^7; /*定义输出字节的最高位,即输出位*/
sbit Bout=P2^0; /*位输出引脚*/
sbit Sclk=P2^1; /*位同步脉冲输出*/
sbit SLclk=P2^2; /*锁存脉冲输出*/
uchar code Segment[]={
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77, /*共阴7段LED段码表*/
0x7c,0x39,0x5e,0x79,0x71,0x76,0x73,0x3e,0x00};
void OneLed_Out(uchar i,uchar Location) /*输出点亮一个7段LED显示器*/
{
uchar j;
OutByte=Location; /*先输出位码*/
for(j=1;j<=8;j++)
{
Bout=Bit_Out;
Sclk=0;Sclk=1;Sclk=0; /*位同步脉冲输出*/
OutByte=OutByte<<1;
}
OutByte=Segment[i]; /*再输出段码*/
for(j=1;j<=8;j++)
{
Bout=Bit_Out;
Sclk=0;Sclk=1;Sclk=0; /*位同步脉冲输出*/
OutByte=OutByte<<1;
}
SLclk=0;SLclk=1;SLclk=0; /*一个锁存脉冲输出*/
}
void main()
{
uchar i=0;
uchar Location=1; /*定义位码*/
while(1)
{
OneLed_Out(i,Location);
i=i+1;
Location=Location<<1;
if(i==8) /*8次一轮*/
{
i=0;
Location=1;
}
}
}