74HC595練習(xí)程序
//74HC595練習(xí)程序
//串入并出實(shí)現(xiàn)16流水燈效果
//2009.12.28
#include"reg52.h"
sbit shcp=P2^0; //數(shù)據(jù)在上升沿進(jìn)入移位寄存器
sbit date1=P2^1; //串行數(shù)據(jù)輸入端
sbit clock=P2^2; //上升沿時(shí)將數(shù)據(jù)輸出到并行端口
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) //發(fā)送數(shù)據(jù)
{
unsigned char i;
for(i=0;i<8;i++) //把每一位數(shù)據(jù)移入寄存器
{
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);
}
}