74HC595 driver

table of Contents

One, chip introduction

Second, the drive circuit

Third, the driver

Fourth, the measured waveform

Five, two pieces of cascade


 

One, chip introduction

The chip used in this example is Philips 74HC595 chip

The chip supports 100M operating frequency

Definition of each pin

 

 

Q0~Q7: Parallel data output terminal;

GND: ground pin;

Q7S: Serial data output (used when multi-chip cascade);

MR: Reset pin, when the pin is connected to a low level, the chip's internal data storage register data is cleared and reset. If not used, it is generally connected to a high level;

SHCP: The clock input of the shift register, when the rising edge is received, the internal data of the shift register is shifted backward as a whole;

STCP: Data storage register clock input, when the rising edge is detected, the data storage register is enabled, and the data received by the chip is output to the Q0~Q7, Q7S pins. It can be understood as a latch signal, when the data is sent to the chip Send a rising edge to the pin after completion;

OE: Output enable pin. When it is high level, the output pin of the chip is high configuration, when it is low level, the output pin of the chip is high (low) level. This pin can be used to control the parallel output pin at the same time. Level, such as controlling LED flashing, etc. When this function is not used, it is usually connected to low level;

DS: Serial data input

VCC: Power supply pin

Functional block diagram: It can be seen from the functional block diagram that 74HC595 contains a shift register, a storage register and a three-state output controller.

Logic block diagram and timing diagram

 

Second, the drive circuit

 

Third, the driver

.c file

/*******************************************************************************

* 名称: void HC595_Init(void)

* 功能: 74HC595的初始化操作;

* 说明: 总共3个端口,SER-PC1,RCLK(ST)-PC2,SRCLK(SH)-PC3;

*******************************************************************************/

void HC595_Init(void)
{
    //将595所有引脚设为推挽输出
    Gpio_InitIOExt(DS_SER_PORT, DS_SER_PIN, GpioDirOut, TRUE, FALSE, FALSE, FALSE);
    Gpio_InitIOExt(ST_CP_PORT, ST_CP_PIN, GpioDirOut, TRUE, FALSE, FALSE, FALSE);
    Gpio_InitIOExt(SH_CP_PORT, SH_CP_PIN, GpioDirOut, TRUE, FALSE, FALSE, FALSE);

    //将所有指示灯都关闭
    HC595Send(HC595_LED_Leakage,FALSE);
    HC595Send(HC595_LED_LED_Run,FALSE);
    HC595Send(HC595_LED_LED_Gun,FALSE);
    HC595Send(HC595_LED_Signal2,FALSE);
    HC595Send(HC595_LED_Overload,FALSE);
    HC595Send(HC595_Relay,FALSE);
}



void GPIO_WriteHigh(u8 _port,u8 _pin)
{
    Gpio_SetIO(_port,_pin,TRUE);
}


void GPIO_WriteLow(u8 _port,u8 _pin)
{
    Gpio_SetIO(_port,_pin,FALSE);
}

/*******************************************************************************

* 名称: void HC595Send(HC595_TypeDef _location,u8 _state)

* 功能: 8位串行输出函数;

* 说明: 第一个为点灯的位置,第二个为目标的状态

*******************************************************************************/
void HC595Send(HC595_TypeDef _location,u8 _state)
{
    static u8 current_data = 0;
    u8 data = 0;
    if(_state == TRUE)
    {
        current_data|=(0x01<<_location);
    }
    else
    {
        current_data&=(~(0x01<<_location));
    }
    data = current_data;
    for(u8 i=0;i<8;i++)
    {
        GPIO_WriteLow(SH_CP_PORT,SH_CP_PIN);
        __NOP();
        __NOP();
        if(data&0x80)
            GPIO_WriteHigh(DS_SER_PORT,DS_SER_PIN);
        else
            GPIO_WriteLow(DS_SER_PORT,DS_SER_PIN);
        GPIO_WriteHigh(SH_CP_PORT,SH_CP_PIN);
        data = data<<1;
    }
    __NOP();
    __NOP();
    GPIO_WriteLow(ST_CP_PORT,ST_CP_PIN);
    __NOP();
    __NOP();
    GPIO_WriteHigh(ST_CP_PORT,ST_CP_PIN);
    Delay_Tim_1ms(1);
}

 

.h file

/* 595控制端口定义 */

#define SH_CP_PORT 2
#define SH_CP_PIN 7

#define ST_CP_PORT 3
#define ST_CP_PIN 1

#define DS_SER_PORT 3
#define DS_SER_PIN 2

typedef enum
{
    HC595_LED_Leakage = 1,
    HC595_LED_LED_Run = 2,
    HC595_LED_LED_Gun = 3,
    HC595_LED_Signal2 = 4,
    HC595_LED_Overload = 5,
    HC595_Relay = 6,
} HC595_TypeDef;

 

Fourth, the measured waveform

Five, two pieces of cascade

 

 

Guess you like

Origin blog.csdn.net/zhuimeng_ruili/article/details/112537225