stm32使用三片74HC595级联程序代码

宣传s.jpg

 

/************************************************************************
  Function:       Read_74HC595
  Description:    读取n片74HC595的输入数据
  Calls:          HC595_delay;GPIO_ResetBits;GPIO_SetBits;
  Data Accessed:  无
  Data Updated:   无
  Input:         
                  HC595x:用户使用的595端口,类型定义在74HC595.h中
                 ChipNum: 用户使用的595端口上连接的芯片个数
  Output:        
                 DataBuf: 输出数据存放缓冲区
  Return:         无
  Others:         此模块为Stm32单片机中使用,调试时在72M系统时钟下
*************************************************************************/

void Write_74HC595(HC595 HC595x,unsigned char ChipNum,unsigned char *DataBuf)
{
    unsigned char i = 0;
    unsigned char DataBufTmp = 0;
   
    GPIO_ResetBits(HC595x.Lck.Port, HC595x.Lck.Pin); //设置LCK为低电平,上升沿数据锁存
   
    for(; ChipNum>0; ChipNum--)
    {
        DataBufTmp = *DataBuf;
        for(i=0; i<8; i++)
        {
            GPIO_ResetBits(HC595x.Clk.Port, HC595x.Clk.Pin); //时钟低电平
           
            if (DataBufTmp & 0x80)
            {
                GPIO_SetBits(HC595x.Data.Port, HC595x.Data.Pin);   //输出1
            }
            else
            {
                GPIO_ResetBits(HC595x.Data.Port, HC595x.Data.Pin); //输出0
            }
           
            HC595_delay(5);
           
            GPIO_SetBits(HC595x.Clk.Port, HC595x.Clk.Pin); //时钟高电平,上升沿数据移位
   
            HC595_delay(5);
           
            DataBufTmp = DataBufTmp << 1;
        }
        DataBuf++;
    }
    GPIO_SetBits(HC595x.Lck.Port, HC595x.Lck.Pin);   //设置LCK为高电平,上升沿数据锁存
    HC595_delay(10);
    GPIO_ResetBits(HC595x.Lck.Port, HC595x.Lck.Pin); //设置LCK为低电平,上升沿数据锁存
}


资料下载地址;链接:http://pan.baidu.com/s/1pJ1mdL5 密码:akkv

sitemap