[mw_shl_code=c,true]
#define SCL_H GPIOB->BSRR = SCL_PIN /* GPIO_SetBits(GPIOB , GPIO_Pin_6) */
#define SCL_L GPIOB->BRR = SCL_PIN /* GPIO_ResetBits(GPIOB , GPIO_Pin_6) */
#define SDA_H GPIOB->BSRR = SDA_PIN /* GPIO_SetBits(GPIOB , GPIO_Pin_7) */
#define SDA_L GPIOB->BRR = SDA_PIN /* GPIO_ResetBits(GPIOB , GPIO_Pin_7) */
#define SCL_read GPIOB->IDR & SCL_PIN /* GPIO_ReadInputDataBit(GPIOB , GPIO_Pin_6) */
#define SDA_read GPIOB->IDR & SDA_PIN /* GPIO_ReadInputDataBit(GPIOB , GPIO_Pin_7) */
[/mw_shl_code]
以上是宏定义
[mw_shl_code=c,true]u8 IIC_ReadByte(void) //数据从高位到低位//
{
u8 i=8;
u8 ReceiveByte=0;
SDA_H;
while(i--)
{
ReceiveByte<<=1;
SCL_L;
delay_us(1);
SCL_H;
delay_us(1);
if(SDA_read)
{
ReceiveByte|=0x01;
}
}
SCL_L;
return ReceiveByte;
} [/mw_shl_code]
这个是期中的一个函数 |