74hc165.h
#ifndef _74H165_H_
#define _74H165_H_
#include<reg51.h>
#include<intrins.h>
#define GPIO_LED P0
sbit IN_PL = P1^6;
sbit IN_Data = P1^7;
sbit SCK = P3^6;
#ifndef uchar
#define uchar unsigned char
#endif
#ifndef uint
#define uint unsigned int
#endif
uchar read74H165();
#endif
74hc165.c
#include<74H165.h>
uchar read74H165()
{
uchar i;
uchar indata;
//将数据并行输入
IN_PL = 0;
_nop_();
IN_PL = 1;
_nop_();
indata = 0; //保存的数据清零
for(i = 0; i < 8; i++)
{
indata = indata << 1;
SCK = 0;
_nop_();
indata |= IN_Data;
SCK = 1;
}
return indata;
}