硬件說明:ATmega48/88/168的PB5是SPI時鐘輸出,接74HC595/74HC165的移位時鐘輸入端;PB4是SPI的MISO數(shù)據(jù)輸人,接74HC165的數(shù)據(jù)輸出;PB3是SPI的MOSI數(shù)據(jù)輸出,接74HC595的串行數(shù)據(jù)輸入端SER;PB2接74HC595/74HC165的
AVR單片機(jī)I/O口讀74HC165接口程序*******************************/#include#define SER_IN PD3#define SER_CK PB2#define SER_SL PB3uint16_t SerIn(void){uint16_t ret=0,i;//數(shù)據(jù)鎖存,在shift/load輸入一脈沖PIO
PIC16F877A將其SCK(串行時鐘)和SDO(串行數(shù)據(jù)輸出)分別與74HC165的CP和Ds引腳相連,送出時鐘信號和串行數(shù)據(jù)。74HC165將接收到的串行數(shù)據(jù)轉(zhuǎn)換成并行數(shù)據(jù),通過并行數(shù)據(jù)輸出口D0~D7連接到共陰極數(shù)碼管,從而實(shí)現(xiàn)在SPI方