//主程序********
//*********************************************************
void main()
{ // bit sign_bit;
unsigned int i;
int x,y,z;
double angle,W;
delay(500);//500ms
InitLcd();
Init_HMC5883();
while(1) //循环
{
Multiple_Read_HMC5883(); //连续读出数据,存储在BUF中
//---------显示X轴
x=BUF[0] << 8 | BUF[1]; //Combine MSB and LSB of X Data output register
z=BUF[2] << 8 | BUF[3]; //Combine MSB and LSB of Z Data output register
y=BUF[4] << 8 | BUF[5]; //Combine MSB and LSB of Y Data output register
W=sqrt(pow(x,2)+pow(y,2));
angle= atan2((double)z,(double)W) * (180 / 3.14159265) +180; // angle in degrees
angle*=10;
conversion(angle); //计算数据和显示
DisplayOneChar(2,0,'A');
DisplayOneChar(3,0,':');
DisplayOneChar(4,0,qian);
DisplayOneChar(5,0,bai);
DisplayOneChar(6,0,shi);
DisplayOneChar(7,0,'.');
DisplayOneChar(8,0,ge);
for (i=0;i<10000;i++); //延时
}
}
|