亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? wearable.c

?? 加速度傳感器+無線測量+步態檢測代碼+avrs實現
?? C
字號:
/*****************************************************************************
 * wearable.c
 * Lab 6: Final Project
 * ECE 476: Digital Systems Design Using Microcontrollers
 * Cornell University
 * April 2008
 * Andrew Chin (hc454) and Ping-Hong Lu (pl328)
 ****************************************************************************/

/*****************************************************************************
* This program will periodically take a sample from the accelerometers and 
* then listen for a short while for a command from the base station.
*
*****************************************************************************/
#include <mega644.h>
#include <spi.h>
#include <at86rf230.h>
#include <kxp74.h>
#include <stdio.h>

#define SAMPLE_TIMEOUT 10
#define SIMPSON_THRESHOLD 11000

unsigned char sample_timer;

unsigned char led;
unsigned int led_toggle_count;

unsigned char x_step_began;
unsigned char z_step_began;
unsigned char x_step_done;
unsigned char z_step_done;
unsigned char step_count;
unsigned char step_lockout_timer;

unsigned char step_state;

int accumulated_x;
unsigned char meter_count;
unsigned char integration_samples[3];
unsigned char three_count;
int simpsons;

int pace_counter1;
int pace_counter2;
long padding;
unsigned char calibration_done;
unsigned int calibration_count;
unsigned int calibration_total;
unsigned char default_x;
unsigned char send_count;

unsigned int timer_count;
unsigned char speed;
unsigned char calculated_speed;

unsigned char every_other_step;
unsigned char half_step;



//State Machine States
#define NO_STEP         0
#define X_START         1
#define Z_START         2
#define X_DONE          3
#define Z_DONE          4
#define X_START_Z_DONE  5
#define Z_START_X_DONE  6
#define X_START_Z_START 7
#define STEP_DETECTED   8
/****************************************************************************/
// This interrupt runs when a compare-match occurs every 1 ms.  It decrements
// the sample_timer global variable which is then used to determine when the
// "sample" task runs.

interrupt [TIM0_COMPA] void ms_timer(void)  {  //Triggers once per ms
  if (sample_timer > 0) sample_timer--;

  timer_count++;
}

/****************************************************************************/
// This task runs every 15 ms and takes readings from the accelerometer and 
// makes interpretations of the user's walking/running movements.  The 
// distance calculations, which utilize the Simpson's rule, occur after every 
// three samples, with the last sample becoming the first sample point of the
// next set.  A finite state machine determines discrete steps based on the x
// and z accelerations going above and below certian thresholds.  The distance, 
// steps, and speed information is sent to the basestation every time sample runs.  

void sample(void)  {
  unsigned char x,y,z;

  set_sensor_clock();  //Set clock phase & polarity for accelerometers
  tx_frame_length = 0;

  // Take 313 cycles to calibrate the default x sensor reading
  if (calibration_done == 0 && calibration_count != 312)
  {
    x = get_sensor(1, CONVERT_XAXIS);
    calibration_total += x;
    calibration_count++;
    
    // After taking the final calibration sample, take the average and
    // set calibration flag as done
    if (calibration_count == 312)
    {
      default_x = calibration_total / 312;
      calibration_done = 1; 
      PORTD.2 = 0;
    }
    return;
  }
  
  // Variable used to detect if data stack has overrun the alloted size
  if (padding != 0)
    printf("data corruption occurred\n\r");
  
//4/19  printf("calibrated x is: %d meter count is %d\n\r", default_x, meter_count);
//  printf("speed is %d timer count is: %d\r", speed, timer_count);


  if (step_lockout_timer > 0)
    step_lockout_timer--;

  x = get_sensor(1, CONVERT_XAXIS);
  //printf("x value is %d\n\r", x);
  
  // Update the triple set for doing simpson's rule calculation of area
  // under the curve
  integration_samples[three_count] = x;
  
  // On the third sample, calculate the simpsons
  if (three_count == 2)//x > 74 || x < 70
  {
    if ((integration_samples[0] > (default_x - 4) &&
         integration_samples[0] < (default_x + 3))&&
        (integration_samples[1] > (default_x - 4) &&
         integration_samples[1] < (default_x + 3))&&
        (integration_samples[2] > (default_x - 4) &&
         integration_samples[2] < (default_x + 3)))
    {
      // standing still with slight movements, ignore
    }
    else
    { 
      simpsons = (int)((int)integration_samples[0]-default_x + 
                      ((int)integration_samples[1]-default_x)* 4 +
                       (int)integration_samples[2]-default_x)* 16 / 3;
      // If the user is fast walking or running, scale the x readings up and
      // set the step detection to every other detection
      if (pace_counter1 < 50 && pace_counter1 > 0)
      {
        simpsons = simpsons * 1.35;
        every_other_step = 1;
      }
      else
      {
        simpsons = simpsons * 0.9;
        every_other_step = 1;
      }
      // Don't let an underflow occur from too many negative x readings            
      if ((accumulated_x + simpsons) > 0)
      {
        accumulated_x += simpsons;
      }
      // If the total x distance is enough to count as one step
      if (accumulated_x > SIMPSON_THRESHOLD)
      {
        accumulated_x = accumulated_x - SIMPSON_THRESHOLD;
        meter_count++;
        // save value
        calculated_speed = ((2237/timer_count) > 10 ? calculated_speed : ((char)(2237/timer_count)));
        // Increase speed incrementally to avoid unrealistic jumps from 
        // inaccurate speed calculations
        if (calculated_speed > speed)
          speed++;
        else if (calculated_speed < speed)
          speed--;
        else ;
        
        timer_count = 0;
        // Remove any erroneous x readings that cause the accumulated_x to go 
        // 2 x the threshold
        while (accumulated_x > SIMPSON_THRESHOLD) accumulated_x -= SIMPSON_THRESHOLD;
      }
    }
  }
  
  // Send the meters, step count, and speed over RF
  {
      send_count = 0;
      tx_frame_length = 3;
      transmit_frame[0] = meter_count;
      transmit_frame[1] = step_count;
      transmit_frame[2] = speed;
    
      set_transceiver_clock();
      if (RF_quick_listen() == 1)  {
        RF_upload_frame();
        if (receive_frame[0] == DATA_REQ)  {
          PORTD.7 = ~PORTD.7;
          RF_rx_to_tx();
          RF_download_frame();
          RF_transmit_frame();
          RF_wait_for_transmit();
        }
      }
      receive_frame[0] = 0;
      RF_tx_to_rx();
  }      
  send_count++;

  delay_us(1);

  y = get_sensor(1, CONVERT_YAXIS);

  delay_us(1);

  z = get_sensor(1, CONVERT_ZAXIS); 
  
  delay_us(1);

  //printf("x y z %d %d %d\n\r", x, y, z);
    
  // State machine for step detection
  switch (step_state)
  {
    // Look for breaking either the x or z threshold
    case NO_STEP:
      if (step_lockout_timer != 0)
      {
        break;
      }
      if (x > 90)
      { 
        step_state = X_START;
        break;
      }
      if (z < 75)
      {
        step_state = Z_START;
        break;
      }
      break;
    // Look for finishing the x step or breaking the z threshold
    case X_START:
      if (x < 80)
      {
        step_state = X_DONE;
        break;
      }
      if (z < 75)
      {
        step_state = X_START_Z_START;
        break;
      }
      break;   
    // Look for finishing the z step or breaking the x threshold
    case Z_START:
      if (z > 80)
      {
        step_state = Z_DONE;
        break;
      }
      if (x > 90)
      { 
        step_state = X_START_Z_START;
        break;
      }
      break;  
    // Look for finishing the x or z steps
    case X_START_Z_START:
      if (x < 80)
      {
        step_state = Z_START_X_DONE;
        break;
      }
      if (z > 80)
      {
        step_state = X_START_Z_DONE;
        break;
      }
      break;    
    // Look for finishing the x step
    case X_START_Z_DONE:
      if (x < 80)
      {
        step_state = STEP_DETECTED;
        break;
      }
      break;    
    // Look for finishing the z step
    case Z_START_X_DONE:
      if (z > 80)
      {
        step_state = STEP_DETECTED;
        break;
      }    
      break;  
    // Look for breaking either the z threshold
    case X_DONE:
      if (z < 75)
      {
        step_state = Z_START_X_DONE;
        break;
      }
      break;    
    // Look for breaking either the x threshold
    case Z_DONE:
      if (x > 90)
      { 
        step_state = X_START_Z_DONE;
        break;
      }      break;  
    // Both axis done, increment whole or half step depending on speed.
    case STEP_DETECTED:
      if (every_other_step == 1)
      {
        if (half_step == 1)
        {
          step_count++;
          half_step = 0;
        }
        else
          half_step = 1;
      }
      else
        step_count++;
      
      step_state = NO_STEP;
      step_lockout_timer = 9;
      pace_counter1 = pace_counter2;
      pace_counter2 = 0;
      break; 
    default: 
      break;
  }


//  printf("pace counter = %d\n\r", pace_counter1);

  pace_counter2++;
  three_count++;
  if (three_count == 3)
  {
    integration_samples[0] = integration_samples[2];
    three_count = 1;
  }

/*
  if (led_toggle_count++ == 8)
  {
    led_toggle_count = 0;
    if (led == 0)
    {
      led = 1;
      PORTD.2 = 0;
    }             
    else
    {
      led = 0;
      PORTD.2 = 1;
    }
  }
*/
}

/****************************************************************************/
// This function correctly initializes the necessary control registers and 
// I/O ports as well as initializes global variables to zero.  Lastly, it
// enables all interrupts.

void initialize(void) {
  DDRD.2 = 1;
  PORTD.2 = 1;

  DDRD = 0xFF;
  DDRA = 0xFF;
  PORTA = 0x00;
  PORTD.7 = 1;
  sample_timer = 0;

  // Initialize Mega64's SPI settings
  init_spi();
  // Initialize accelerometer's SPI
  init_sensor_spi();
  set_sensor_clock();
  // Get accelerometers in proper mode
  init_sensors();
  // Initialize transceiver SPI
  RF_init_spi();
  delay_us(100);
  set_transceiver_clock();
  // Put transceiver in receiver mode
  RF_init_transmitter();

  sample_timer = SAMPLE_TIMEOUT;
  TCCR0A = 0b00000010;  //OC0A & OC0B disconnected, WGM set up for CTC mode
  TCCR0B = 0b00000011;  //Timer set up to osc/64... count to 125 for 1 ms
  OCR0A = 125;
  // Interrupt on compare match A
  TIMSK0 = 0b00000010;

  led = 0;
  led_toggle_count = 0;
  x_step_began = 0;
  z_step_began = 0;
  x_step_done = 0;
  z_step_done = 0;
  step_count = 0;
  step_lockout_timer = 0;
  integration_samples[0] = 0;
  integration_samples[1] = 0;
  integration_samples[2] = 0;
  three_count = 0;

  step_state = NO_STEP;
  
  accumulated_x = 0;
  meter_count = 0;
  
  calibration_done = 0;
  calibration_count = 0;
  calibration_total = 0;
  default_x = 0;

  padding = 0;
  pace_counter1 = 0;
  pace_counter2 = 0;
  send_count = 0;
  
  timer_count = 0;
  speed = 0;
  calculated_speed = 0;

  every_other_step = 0;  
  half_step = 0;

  //set up UART
  UCSR0B = 0x18 ;
  UBRR0L = 51 ;
  printf("starting...\n\r") ;

  //Enable interrupts
  #asm
    sei
  #endasm
}

/****************************************************************************/
// The main function starts by running a delay to allow the other components 
// time to reach a steady state.  It then calls the initialization function
// and runs whenever the interrupt has counted down the sample_timer variable
// to zero.

void main(void)  {
  delay_ms(2000);
  initialize();

  while(1)  {
    if (sample_timer == 0)  {
      sample_timer = SAMPLE_TIMEOUT;
      sample();
    }
  }

}

/****************************************************************************/

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲综合999| 国产成人精品www牛牛影视| 一区二区三区日韩精品| 国产精品毛片久久久久久| 久久夜色精品一区| 国产网站一区二区三区| 久久久久久免费| 国产亚洲一本大道中文在线| 久久综合五月天婷婷伊人| 欧美一卡2卡三卡4卡5免费| 日韩一区二区三区在线视频| 欧美电影免费观看高清完整版 | 久久成人综合网| 蜜桃久久av一区| 国产一区激情在线| 国产成人综合亚洲91猫咪| 国产成人免费视频网站| 成人激情图片网| 色综合亚洲欧洲| 一区二区在线观看不卡| 亚洲亚洲精品在线观看| 丝袜美腿亚洲色图| 久久国产综合精品| 国产成人8x视频一区二区| 99视频精品全部免费在线| 在线观看精品一区| 日韩欧美国产精品| 亚洲国产精品二十页| 亚洲精品成人天堂一二三| 亚洲va中文字幕| 国产综合久久久久久鬼色| 东方欧美亚洲色图在线| 91老师国产黑色丝袜在线| 欧美性极品少妇| 日韩视频123| 国产精品乱子久久久久| 亚洲激情第一区| 精品在线播放免费| av在线播放一区二区三区| 欧美性videosxxxxx| 日韩美女天天操| 国产精品丝袜黑色高跟| 亚洲国产综合色| 黄色成人免费在线| 91免费看`日韩一区二区| 欧美肥胖老妇做爰| 欧美激情艳妇裸体舞| 亚洲国产一区二区三区| 精品一区二区三区在线观看| 成人国产一区二区三区精品| 在线电影一区二区三区| 国产精品国产三级国产普通话蜜臀 | 欧美日韩在线综合| 久久网站热最新地址| 亚洲激情图片qvod| 国产专区欧美精品| 欧美亚洲动漫制服丝袜| 国产丝袜欧美中文另类| 日韩国产高清影视| 91视频一区二区三区| 欧美xxx久久| 亚洲一区二区美女| 成人一道本在线| 欧美一级夜夜爽| 亚洲黄网站在线观看| 粉嫩高潮美女一区二区三区| 日韩午夜在线观看| 亚洲综合色噜噜狠狠| 顶级嫩模精品视频在线看| 777a∨成人精品桃花网| 亚洲精品视频在线看| 国产成人一区在线| 欧美zozozo| 午夜精品福利在线| 色94色欧美sute亚洲13| 久久婷婷国产综合国色天香| 天天av天天翘天天综合网色鬼国产| 成人美女视频在线观看18| 精品国产髙清在线看国产毛片 | 精品在线一区二区| 欧美日韩一二三区| 亚洲视频你懂的| 成人午夜私人影院| 国产欧美一区二区精品性色| 免费成人性网站| 欧美在线|欧美| 亚洲人成网站精品片在线观看| 国产精品主播直播| 精品国产髙清在线看国产毛片| 日本成人超碰在线观看| 欧美色图免费看| 亚洲午夜日本在线观看| 91免费看视频| 亚洲精品成人悠悠色影视| 91免费视频网| 亚洲免费电影在线| av午夜精品一区二区三区| 欧美国产精品一区二区三区| 国产一区福利在线| 国产欧美视频一区二区| 国产一区二区三区高清播放| 久久一区二区三区四区| 国产一区二区三区在线观看免费 | 精品一区二区在线免费观看| 欧美一区二区人人喊爽| 日本中文字幕一区二区视频 | 香蕉加勒比综合久久| 精品污污网站免费看| 天堂久久一区二区三区| 欧美精品自拍偷拍| 免费看欧美美女黄的网站| 91精品久久久久久久91蜜桃| 日韩电影一二三区| 欧美成人一区二区三区片免费| 热久久国产精品| 日韩免费一区二区| 国产精品一区二区三区网站| 久久精品亚洲精品国产欧美kt∨| 国产999精品久久久久久绿帽| 国产精品久久久久精k8| 日本二三区不卡| 亚洲成av人影院在线观看网| 51精品久久久久久久蜜臀| 久久se这里有精品| 国产午夜精品福利| 色综合欧美在线视频区| 亚洲第一二三四区| 日韩精品一区二区三区中文精品| 国产精品中文欧美| 亚洲日本在线视频观看| 欧美日韩中文字幕一区二区| 看片的网站亚洲| 国产欧美一区二区精品秋霞影院| 91免费观看在线| 视频一区视频二区中文字幕| 精品欧美一区二区三区精品久久 | 91成人网在线| 日韩精品一级中文字幕精品视频免费观看 | 麻豆视频一区二区| 国产蜜臀av在线一区二区三区| 色噜噜狠狠一区二区三区果冻| 日韩精品每日更新| 欧美国产禁国产网站cc| 欧美写真视频网站| 久久精品国产精品亚洲红杏| 国产精品高清亚洲| 欧美乱妇20p| 成人性色生活片| 亚洲高清免费在线| 亚洲国产成人私人影院tom | 亚洲一卡二卡三卡四卡无卡久久 | 自拍偷拍亚洲欧美日韩| 欧美一区二区视频在线观看| 波多野结衣在线一区| 偷拍亚洲欧洲综合| 欧美国产在线观看| 91精品国产丝袜白色高跟鞋| 99视频国产精品| 久久精品国产秦先生| 亚洲免费色视频| 国产亚洲人成网站| 欧美二区三区的天堂| 99在线精品免费| 国产一区二区中文字幕| 亚洲成人你懂的| 成人欧美一区二区三区| 精品国产一区二区三区久久久蜜月| 91在线视频网址| 精品在线播放免费| 污片在线观看一区二区| 日韩毛片精品高清免费| 精品粉嫩超白一线天av| 欧美色图在线观看| 成人激情动漫在线观看| 蜜乳av一区二区三区| 亚洲国产日韩一级| 亚洲视频一区在线| 亚洲国产经典视频| 精品伦理精品一区| 欧美一区国产二区| 欧美在线综合视频| 91日韩一区二区三区| 国产高清无密码一区二区三区| 日韩二区三区在线观看| 亚洲一区二区在线观看视频 | 国产精品1区二区.| 日本视频免费一区| 亚洲国产一区二区在线播放| 最新国产成人在线观看| 国产日韩欧美一区二区三区乱码| 日韩一区二区在线观看| 91麻豆精品国产| 欧美午夜精品久久久久久孕妇 | 欧美一级夜夜爽| 欧美精品在线观看一区二区| 欧美丝袜自拍制服另类| 欧美中文字幕一区| 欧美性受极品xxxx喷水| 色8久久精品久久久久久蜜| 91美女在线观看|