/************************************************************************
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为低电平,上升沿数据锁存
}