HC595是一个串入并出的移位驱动型芯片,在一些扩展I/O和控制驱动类的电路里常常用到,以下是它的一段控制程序,简单而方便移植:
//控制管脚的宏定义 #define Ctrl_Out P3DIR |= BIT1 + BIT2 + BIT3; #define Ctrl_0 P3OUT &= ~(BIT1 + BIT2 + BIT3) #define SRCLK_1 P3OUT |= BIT1 #define SRCLK_0 P3OUT &= ~BIT1 #define SER_1 P3OUT |= BIT2 #define SER_0 P3OUT &= ~BIT2 #define RCLK_1 P3OUT |= BIT3 #define RCLK_0 P3OUT &= ~BIT3 void HC595_output_Byte(unsigned char HC595_data) { unsigned char i; Ctrl_Out; Ctrl_0; for(i = 0; i < 8; i++) { SRCLK_0; if(HC595_data & 0x80) SER_1; else SER_0; SRCLK_1; HC595_data <<= 1; } RCLK_1; for(i = 10; i > 0; i--) ;//延迟一点时间 RCLK_0; }