#ifndef _IIC_H
#define _IIC_H
#include "user.h"
typedef unsigned char BYTE;
typedef unsigned short WORD;
#define   uchar unsigned char
#define   uint unsigned int

/*模拟I2C端口输出输入定义*/
#define I2C_GPIO		        GPIOB
#define I2C_SCL_PIN			GPIO_Pin_3
#define I2C_SDA_PIN			GPIO_Pin_2

#define SCL_H         (I2C_GPIO->ODR |= I2C_SCL_PIN)
#define SCL_L         (I2C_GPIO->ODR &= (uint8_t)( ~I2C_SCL_PIN ))

#define SDA_H         (I2C_GPIO->ODR |= I2C_SDA_PIN)
#define SDA_L         (I2C_GPIO->ODR &= (uint8_t)( ~I2C_SDA_PIN ))

#define SDA_OUT       GPIO_Init(I2C_GPIO,I2C_SDA_PIN,GPIO_Mode_Out_PP_High_Fast)//((I2C_GPIO->DDR)|=(uint8_t)(I2C_SDA_PIN))
#define SDA_IN        GPIO_Init(I2C_GPIO,I2C_SDA_PIN,GPIO_Mode_In_PU_No_IT)//((I2C_GPIO->DDR)&=(uint8_t)(~I2C_SDA_PIN))
#define SDA_read      (I2C_GPIO->IDR  & (uint8_t)(I2C_SDA_PIN))


extern uint32_t T;
enum{yes=1,no=0};
void Delay5us(void);
void HMC5883_InitPin(void);
bool HMC5883_Start(void);
void HMC5883_Stop(void);
bool HMC5883_WaitACK(void);
void HMC5883_SendACK(bool ack);
bool HMC5883_SendByte(BYTE dat);
BYTE HMC5883_RecvByte();
bool Single_Write_HMC5883(uchar SlaveAddress,uchar REG_Address,uchar REG_data);
uchar Single_Read_HMC5883(uchar SlaveAddress,uchar REG_Address);
void Multiple_Read_HMC5883(uchar SlaveAddress,uchar *BUFF);
bool Init_HMC5883();
#endif
