74HC595
输入:串行输入
输出:并行/串行输出
用74HC595做一个流水灯
电路图
程序
/*======================
测试74HC595
=======================*/ #include <REGX51.H>
#include <intrins.h> #define uchar unsigned char
#define uint unsigned int sbit st_cp = P3^;
sbit sh_cp = P2^;
sbit ds = P3^;
uchar led = 0xfe; void message_get(uchar led);
void message_send();
void delay(uchar time_delay); void main()
{
while()
{
message_get(led);
message_send();
delay();
led = _crol_(led, );
}
}
//将数据放到移位寄存器中
void message_get(uchar led)
{
uchar i = ;
for(; i < ; i ++)
{
sh_cp = ;
ds = led & 0x80;
led <<= ;
delay();
sh_cp = ;//上升沿
}
}
//将数据从移位寄存器中放到存储寄存器中
void message_send()
{
st_cp = ;
delay();
st_cp = ;//数据从移位寄存器放到数据寄存器中
}
void delay(uchar time_delay)
{
uchar x,y;
for(x = time_delay; x > ; x--)
for(y = time_delay; y > ; y--)
{}
}