#include "stm8s207s8.h"#define HC165_IN_RXD cbi(PD_ODR,6);cbi(PD_CR1,6);cbi(PD_CR2,6); //数据口#define HC165_GET_RXD gbi(PD_IDR,6)#define HC165_OUT_TXD sbi(PD_DDR,5);sbi(PD_CR1,5);sbi(PD_CR2,5); //脉冲口#define HC165_SET_TXD sbi(PD_ODR,5)#define HC165_CLR_TXD cbi(PD_ODR,5)#define HC165_OUT_PL sbi(PE_DDR,2);sbi(PE_CR1,2);sbi(PE_CR2,2); //锁存口#define HC165_SET_PL sbi(PE_ODR,2)#define HC165_CLR_PL cbi(PE_ODR,2)u8 hc165GetDat(void){ u8 i,dat=0; HC165_CLR_PL; HC165_SET_PL; for(i=0;i<8;i++) { HC165_CLR_TXD; dat=dat<<1; if(HC165_GET_RXD) { dat|=0x01; } HC165_SET_TXD; } return dat;}void hc165Init(void){ HC165_OUT_PL; HC165_OUT_TXD; HC165_IN_RXD;}
|