本文主要是我在开发过程中对于3级连接的74HC165的驱动代码
#define CPEN_NSS_LOW() gpio_bit_reset(GPIOA, GPIO_PIN_4)
#define CPEN_NSS_HIGH() gpio_bit_set(GPIOA, GPIO_PIN_4)
#define OUT_H165() gpio_input_bit_get(GPIOA, GPIO_PIN_6)
#define CLK_LOW() gpio_bit_reset(GPIOA, GPIO_PIN_5)
#define CLK_HIGH() gpio_bit_set(GPIOA, GPIO_PIN_5)
#define NPL_LOW() gpio_bit_reset(GPIOE, GPIO_PIN_14)
#define NPL_HIGH() gpio_bit_set(GPIOE, GPIO_PIN_14)
void Read_BoardID(u16 *testBoard,u8 *floorID)
{
u8 buf[3]={0x00};
u8 i=0;
CLK_HIGH();
NPL_LOW();
Nop();
NPL_HIGH();
for(i =0;i<8;i++)
{
floorID[0]<<=1;
if(OUT_H165() == 1)
{
floorID[0] |=0x01;
}
CLK_LOW();
Nop();
CLK_HIGH();
}
for(i =0;i<8;i++)
{
buf[1]<<=1;
if(OUT_H165() == 1)
{
buf[1] |=0x01;
}
CLK_LOW();
Nop();
CLK_HIGH();
}
for(i =0;i<8;i++)
{
buf[2]<<=1;
if(OUT_H165() == 1)
{
buf[2] |=0x01;
}
CLK_LOW();
Nop();
CLK_HIGH();
}
testBoard[0] = buf[2]|buf[1]<<8;
CLK_LOW();
}
/*
获取适配板ID和被测板卡ID*/
u16 GetIDQ()
{
char buf[64];
u16 TestBoardId[1]={0x0000};
u8 FloorId[1] = {0x00};
ReadID_Init();
Read_BoardID(TestBoardId,FloorId);
Read_BoardID(TestBoardId,FloorId);
sprintf(buf,"0x00%02X%04X",FloorId[0],TestBoardId[0]);
SysFdCanSendData(Freme_ID, (u8*)buf, strlen(buf));
return 0;
}