//74HC595操练程序
//串入并出完成16流水灯作用
//2009.12.28
#include”reg52.h”
sbit shcp=P2^0; //数据在上升沿进入移位寄存器
sbit date1=P2^1; //串行数据输入端
sbit clock=P2^2; //上升沿时将数据输出到并行端口
unsigned char tab[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
unsigned char tab1[]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
void delay(unsigned int delay)
{
unsigned char i;
for(;delay>0;delay–)
for(i=0;i<125;i++);
}
void send_data(unsigned char date) //发送数据
{
unsigned char i;
for(i=0;i<8;i++) //把每一位数据移入寄存器
{
date=date<<1;
date1=CY;
shcp=0;
shcp=1;
}
}
void main()
{
unsigned char k;
for(k=0;k<16;k++)
{
send_data(tab[k]);
send_data(tab1[k]);
{clock=0;clock=1;};
delay(1000);
}
}