74HC595:数据从串转并,以下程序,实现流水灯效果
#include <reg52.h>
#include <intrins.h>
typedef unsigned char u8;
typedef unsigned int u16;
void delay( u16 i ){
while( i-- );
}
#define GPIO_DIG P0
sbit SRCLK = P3^6; //移位寄存器时钟
sbit STORE_RCLK = P3^5; //存储寄存器时钟
sbit SER = P3^4; //串口输入数据
void hc595_send_data( u8 input_data ) {
u8 i;
SRCLK = 1;
STORE_RCLK = 1;
for( i = 0 ; i < 8; i++ ){
SER = input_data >> 7; //从最高位开始传送
input_data <<= 1; //把次高位移到最高位
SRCLK = 0; //时序脉冲
_nop_();
_nop_();
SRCLK = 1;
}
STORE_RCLK = 0; //时序脉冲
_nop_();
_nop_();
STORE_RCLK = 1; //把寄存器的数据 送到输出口
}
void main (){
u8 led_num;
led_num = 0x01; //先让D11点亮
while( 1 ) {
hc595_send_data( led_num );
led_num = _crol_( led_num, 1 );
delay( 50000 );
delay( 50000 );
}
}
|