#include <reg51.h>
#include<intrins.h>
typedef unsigned int u16;
typedef unsigned char u8;
sbit SRCLK=P3^6;
sbit RCLK=P3^5;
sbit SER=P3^4;
u8 s; //为什么要全局变量?不用全局变量会报错。
u8 ledduan[]={0x3C,0x52,0xA5,0x93,0x93,0xA5,0x52,0x3C,0x00,0xFE,0x10,0x10,0x10,0xFE,0x00,0x00,0x00,0x00,0x7F,0x49,0x49,0x49,0x49,0x00,
0x00,0x00,0xFE,0x02,0x02,0x02,0x02,0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x02,0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x3C,0x00,0x3C,0x52,0xA5,0x93,0x93,0xA5,0x52,0x3C,0x00,0xFE,0x10,0x10,0x10,0xFE,0x00,0x00,0x00,0x00,0x7F,0x49,0x49,0x49,0x49,0x00,
0x00,0x00,0xFE,0x02,0x02,0x02,0x02,0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x02,0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x3C,0x00,};
u8 ledwei[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
void delay(u16 t)
{
while(t--);
}
void Hc595SendByte(u8 dat)
{
u8 a;
SRCLK=0;
RCLK=0;
for(a=0;a<8;a++)
{
SER=dat>>7;
dat<<=1;
SRCLK=1;
_nop_();
SRCLK=0;
}
RCLK=1;
_nop_();
RCLK=0;
}
void main()
{
u8 i;
u8 e;
e=0;
while(1)
{
P0=0x7f;
//为什么不能在这里定义s呢?一定要全局?
for(s=0;s<100;s++)
{
for(i=0;i<8;i++)
{
P0=ledwei[i];
Hc595SendByte(ledduan[i+e]);
delay(1);
Hc595SendByte(0x00);
}
}
e += 1;
if (e==48)
{
e=0;
}
}
}