stm32使用三片74HC595級聯(lián)程序代碼
Function: Read_74HC595
Description: 讀取n片74HC595的輸入數(shù)據(jù)
Calls: HC595_delay;GPIO_ResetBits;GPIO_SetBits;
Data Accessed: 無
Data Updated: 無
Input:
HC595x:用戶使用的595端口,類型定義在74HC595.h中
ChipNum: 用戶使用的595端口上連接的芯片個數(shù)
Output:
DataBuf: 輸出數(shù)據(jù)存放緩沖區(qū)
Return: 無
Others: 此模塊為Stm32單片機中使用,調試時在72M系統(tǒng)時鐘下
*************************************************************************/
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為低電平,上升沿數(shù)據(jù)鎖存
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); //時鐘高電平,上升沿數(shù)據(jù)移位
HC595_delay(5);
DataBufTmp = DataBufTmp << 1;
}
DataBuf++;
}
GPIO_SetBits(HC595x.Lck.Port, HC595x.Lck.Pin); //設置LCK為高電平,上升沿數(shù)據(jù)鎖存
HC595_delay(10);
GPIO_ResetBits(HC595x.Lck.Port, HC595x.Lck.Pin); //設置LCK為低電平,上升沿數(shù)據(jù)鎖存
}
評論