adxl345 ile adımsayar yapmak

Başlatan mustan79, 29 Ocak 2015, 16:49:30

mustan79




merhaba arkadaşlar

adxl345 ivme sensörü ile adımsayar yapmaya çalışıyorum. fakat yazılımında sıkıntılarım var. kodlar aşağıdadır. yardımcı olabilirseniz sevinirim.
verici kod:
#include <16F877a.h>
#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD
//#fuses  HSPLL,NOWDT,NOPROTECT,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN      // dont change
#use    delay(clock=4000000) 
#use rs232(baud=1200,parity=N,xmit=pin_c6,rcv=pin_c7,stop=1, parity=N) //rf iletişim için

#build (reset=0x1000, interrupt=0x1008)                              // new addresses
#org 0x00,0xff {}                                             // reserved space

#use I2C(master, sda=PIN_C4, scl=PIN_C3)
#include "ADXL345.c"
#define INTS_PER_SECOND 30  // (4/4000000)*(256*(256-30))

void step_state(void);
void display_show(void);
void uyan(void);

unsigned int step_count=0;
unsigned int step_stu=0;
char pre;
int16 x,y,z;

void main()
{
   set_tris_d(0x00);
   output_high(pin_d0);
   adxl345_init();
   
   while(TRUE)
   {
      output_toggle(pin_d2);
      display_show();
      delay_us(100);
      step_state();
      delay_us(100);
      pre='D';
      uyan();
      putc(step_count);
  }
}

void step_state(void)

  switch (step_stu)
  {
    case 0:
    if (y > 200 ||  x>117)
      {
        step_stu = 1 ;
      }
      break;
    case 1:
     if (y < 127 || x>65)
      {
        step_stu = 2;
      }
      break; 
    case 2:
      if (y < 50)
      {
        step_stu = 3;
      }
      break;   
   // Both axis done, increment whole or half step depending on speed.
     case 3:
      if (y < 127)
      {
        step_stu = 4;
      }
      break;
     case 4:
      if (y > 200 || x>117)
      {
        step_stu = 5 ;
      }
      break;
     case 5:
      step_count++;
      step_stu = 0;
      break;
  }
}

void uyan(void)
{      // RF cihazını uyandırmak için
    putc(0x55);putc(0x55);putc(0x55);putc(0x55);putc(0x55);
    putc(0x00);putc(0x00);putc(0x00);putc(0x00);putc(0x00);
    putc(0xff);putc(0xff);putc(0xff);putc(0xff);putc(0xff);
    putc(pre);    // putc(pre);    putc(pre);
    return;
}

void display_show(void)

    x=adxl345_read(0x33);
    x=(x<<8)+adxl345_read(0x32);
   
    y=adxl345_read(0x35);
    y=(y<<8)+adxl345_read(0x34);
   
    z=adxl345_read(0x37);
    z=(z<<8)+adxl345_read(0x36);
 
   if(x>65000 || y>65000 || z>65000 )
   {
      x=-x; y=-y; z=-z;
   }
}

alıcı kod:
#include <16f877a.h>
#fuses xt,nowrt,nowdt,nobrownout,nolvp,nocpd,nodebug,noprotect,noput
#use delay(clock=4000000)
#use rs232(baud=1200,parity=N,rcv=pin_c7,bits=8, stop=1,stream=sensor)
#use rs232 (baud=9600,rcv=pin_d4, xmit=pin_d5, stop=1, parity=N, stream=pc )      //9600 baud rs232 ye giden gelen

#use fast_io(d)

unsigned int say;
char pre;

void main()
{
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   
   set_tris_d(0b00010000);
   output_high(pin_d0);
   fprintf(pc, "\r\n yazilim 7 step_state");

   while(true)
   {
//    for(i=0;i<3;i++)
  //    pre=fgetc(sensor);
//     if(pre[0]=='D'|| pre[1]=='D'|| pre[2]=='D')
      pre=fgetc(sensor);
      if (pre=='D')
      {
         say=fgetc(sensor);
         output_toggle(pin_d1);
         delay_ms(10);
         fprintf(pc, "\r\n deger = %u  ", say);
    }
  }
}