#include
#include "cry12864.h"
#include "cry12864.c"
#include
#include
#define HMC5883L_DIR P1DIR
#define HMC5883L_IN P1IN
#define HMC5883L_OUT P1OUT
#define SCL BIT2 //IIC时钟引脚定义
#define SDA BIT3 //IIC数据引脚定义
//DRDY 不接
#define SCL_H (HMC5883L_DIR|=SCL,HMC5883L_OUT|=SCL)
#define SCL_L (HMC5883L_DIR|=SCL,HMC5883L_OUT&=~SCL)
#define SDA_H (HMC5883L_DIR|=SDA,HMC5883L_OUT|=SDA)
#define SDA_L (HMC5883L_DIR|=SDA,HMC5883L_OUT&=~SDA)
#define SlaveAddress 0x3c //定义器件在IIC总线中的从地址
//uchar ge,shi,bai,qian,wan;
unsigned char Rec_Data[6],b[5];
unsigned char x,y,z;
double Angle;
uchar Acr;
/*延时函数*/
void Delay(uint t)
{
while(t--);
}
/*起始信号*/
void IIC_Start(void)
{
SDA_H;
SCL_H;
Delay(50);
SDA_L;
Delay(50);
SCL_L;
}
/*停止信号*/
void IIC_Stop(void)
{
SDA_L;
SCL_H;
Delay(50);
SDA_H;
Delay(50);
}
/*发送应答信号*/
void IIC_SendAck(char Ack)
{
if(Ack) //ack (0:ACK 1:NACK)
SDA_H;
else SDA_L;
SCL_H;
Delay(50);
SCL_L;
Delay(50);
}
/*接收应答信号*/
char IIC_RecAck(void)
{
char CY;
HMC5883L_DIR&=~SDA;
SCL_H;
Delay(50);
if(HMC5883L_DIR&SDA)
CY=1;
else CY=0;
SCL_L;
Delay(50);
return CY;
}
/*向IIC总线发送一个字节数据*/
void HMC5883_Send_Byte(unsigned char Dat)
{
unsigned char i;
for(i=0;i