Robofun 機器人論壇

 找回密碼
 申請會員
搜索
熱搜: 活動 交友 discuz
查看: 4840|回復: 0
打印 上一主題 下一主題

8051擷取HM55B訊號的問題

[複製鏈接]
跳轉到指定樓層
1#
發表於 2007-10-29 17:25:11 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
各位前輩們好:
  可以幫我看一下程式哪裡錯誤了,這個程式是要擷取電子羅盤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++)
    ;
}
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

小黑屋|手機版|Archiver|機器人論壇 from 2005.07

GMT+8, 2024-4-28 15:18 , Processed in 0.132587 second(s), 8 queries , Apc On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表