74HC595练习程序
时间:11-13
来源:互联网
点击:
//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);
}
}
//串入并出实现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);
}
}
74HC595练习程 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)