sea112001 發表於 2007-10-29 17:25:11

8051擷取HM55B訊號的問題

各位前輩們好:
  可以幫我看一下程式哪裡錯誤了,這個程式是要擷取電子羅盤HM55B的XY軸磁場強度的程式,我用的單晶片是8051,編譯軟體是KEIL C,目前問題是出在8051接收不到由HM55B所發出來的狀態旗標訊號%1100,不知道是8051的指令沒送進HM55B的Din還是我的CLK設錯了,我用了好久都沒用出一個結果,請各位前輩幫個忙,另外位了簡化程式,我把擷取XY軸磁場強度和角度計算的程式以P1 port的輸出代替,希望各位前輩能幫幫忙,感激不盡。

#include"reg51.h"
#include"math.h"
#include"stdio.h"
sbit out=0x90;                                   /*out is P1_0*/
sbit in=0x91;                                   /*in is P1_1*/
sbit clock=0x92;                               /*clock is P1_2*/
sbit enable=0x93;                                /*enable is P1_3*/
int RESET=0x0000;                               /*RESET = 00000000B*/
int MEASURE=0x0008;                        /*MEASURE = 00001000B*/
int REPORT=0x000c;                           /*REPORT = 00001100B*/
int bdata READY=0x000c;                     /*READY = 00001100B*/
int bdata MOVE_OUT,MOVE_IN;          /*MOVE_OUT is command move to HM55B Din
                                                   MOVE_IN is status move to 8051
                                                   MOVE_INXY is data move to 8051*/
int x_data,y_data;
int MASK=0xf800;
sbit M_OUT=MOVE_OUT^8;
sbit M_IN=MOVE_IN^8;
sbit M_INXY=MOVE_INXY^8;
void shift_out(int);
int shift_in();
int shift_inXY();
void delay(int);

main()
{
again_me:
clock=0;
shift_out(RESET);                            /* move reset command to HM55B*/
enable=1;
shift_out(MEASURE);                       /* move measure command to HM55B*/
enable=1;
delay(40000);                                 /* stay 40ms*/
shift_out(REPORT);                       /* move report command to HM55B*/
enable=1;
shift_in();                                  /* data move to 8051*/
if(MOVE_IN==READY)                          /* if the data of move to 8051 is arighy */
{
   P1=0x23;                                     /* P1 output*/
}
   else
   {
    goto again_me;
   }
}

void shift_out (int command)               /* 8051 move command to HM55B*/
{
int i;
enable=1;
enable=0;
for(i=0;i<4;i++)
{
MOVE_OUT=command;
clock=1;
out=M_OUT;
clock=0;
command>>=1;
}
}

int shift_in ()                                     /* HM55B move status to 8051*/
{
int i;
for(i=0;i<4;i++)
{
clock=1;
M_IN=in;
clock=0;
if(i<3)
{
   MOVE_IN<<=1;
}
}
enable=1;
return (MOVE_IN);
}

void delay(int num)                       /* delay function*/
{
int i;
for(i=0;i<num;i++)
    ;
}
頁: [1]
查看完整版本: 8051擷取HM55B訊號的問題