利用软件模拟SPI实现控制74HC595

两个主要函数,注意时序就可以了

void HC595Send(uint8_t data)

{
  uint8_t j;
  for (j = 8; j > 0; j--)
{
    if(data & 0X01)
   HC595_DATA_H();
else
HC595_DATA_L();
HAL_Delay(1);
data >>= 1;
HC595_CLK_L();
HC595_CLK_H();

  }


}


void Write_74HC595(unsigned char Num,unsigned char *DataBuf)
{
    unsigned char DataBufTmp = 0;
    
    
    HC595_CLK_H();
HAL_Delay(1);
    for(; Num>0; Num--)
    {
        DataBufTmp = *DataBuf;
        HC595Send(DataBufTmp);
HAL_Delay(1);
        DataBuf++;

HC595Load();
HAL_Delay(1);
    }


HC595_DATA_L();




你可能感兴趣的:(利用软件模拟SPI实现控制74HC595)