while(1)
{
Multiple_Read_HMC5883();//連續(xù)讀出數(shù)據(jù),存儲(chǔ)在Rec_Data[]中
X=Rec_Data[0]<<8 | Rec_Data[1];//Combine MSB and LSB of X Data output register
Z=Rec_Data[2]<<8 | Rec_Data[3];//Combine MSB and LSB of Z Data output register
Y=Rec_Data[4]<<8 | Rec_Data[5];//Combine MSB and LSB of Y Data output register
Angle= atan2((double)Y,(double)X)*(180/3.14159265)+180;//單位:角度 (0~360)
Angle*=10;
Acr=(uint)Angle;
LCD_set_xy(2,0);
Send_DATA(Acr%10000/1000+0x30,1);
Send_DATA(Acr%1000/100+0x30,1);
Send_DATA(Acr%100/10+0x30,1);
Send_DATA('.',1);
Send_DATA(Acr%10+0x30,1);