做單片機(jī)開(kāi)發(fā)的時(shí)候經(jīng)常需要用到模擬spi接口,這種寫(xiě)法不錯(cuò)的,網(wǎng)上很多類(lèi)似的,我也拿來(lái)主義了。本文引用地址:http://m.butianyuan.cn/article/201611/318265.htm#define MOSI_H GPIO_SetBits(GPIOB, GPIO_Pin_10)#define MOSI_L GPIO_ResetBits(GPIOB, GPIO_Pin_10)#define SCLK_H GPIO_SetBits(GPIOB, GPIO_Pin_13)#define SCLK_L GPIO_ResetBits(GPIOB, GPIO_Pin_13)#define MISO GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_11)unsigned char SPI_SendByte(unsigned char dt){u8 i;u8 temp=0;for(i=8;i>0;i--){if(dt&0x80)MOSI_H;else MOSI_L;dt<<=1;SCLK_H;__nop();__nop();__nop();temp<<=1;if(MISO)temp++;__nop();__nop();__nop();SCLK_L;}return temp;}
評(píng)論