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

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

?? accelerometer.c

?? freescale badge board 開發板測試 源程序
?? C
字號:
/*!
 * \file    accelerometer.c
 * \brief   Simple driver MPR083 using I2C
 * \version $Revision: 1.3 $
 * \author  Anthony Huereca
 */

 #include "accelerometer.h"

/*******************************************************************/
/*!
 * Initialize ADC and Accelerometer
 */
void Accel_init() 
{
  /* Set Senstivity to 1.5g */
  PTCDD_PTCDD4=1;
  PTCDD_PTCDD5=1; 
  PTCD_PTCD4 = 0;
  PTCD_PTCD5 = 0;
  
  /* Put Accelerometer in Sleep Mode */
  PTCDD_PTCDD3=1;
  PTCD_PTCD3=0;
}



/*******************************************************************/
/*!
 * Perform an IIR filter on X, Y, and Z axis
 */
void filter_data()
{
byte i;
dword X, Y, Z;

  X = x.reading[samp];
  Y = y.reading[samp];
  Z = z.reading[samp];
  
  for (i=samp;i>0;i--){
    X = (X + ((x.reading[i] + x.result[i-1])>>1))>>1;
    Y = (Y + ((y.reading[i] + y.result[i-1])>>1))>>1;
    Z = (Z + ((z.reading[i] + z.result[i-1])>>1))>>1;
  }
  
  x.result[samp] = (word)X;
  y.result[samp] = (word)Y;
  z.result[samp] = (word)Z;
}

/*******************************************************************/
/*!
 * Get Average from ADC outputs
 * Calculates ADC value for x, y, and z axis.
 */
void avg_data()
{
  byte j;
  long x_avg=0, y_avg=0, z_avg=0;
  
  for(j=1;j<max;j++) 
  {  
    // Read acceleration data
    x_avg +=  (dword)(ReadAcceleration(0x04)<<4);  // Select ADC4 (x-axis) channel
    y_avg +=  (dword)(ReadAcceleration(0x05)<<4);  // Select ADC5 (y-axis) channel 
    z_avg +=  (dword)(ReadAcceleration(0x06)<<4);  // Select ADC6 (z-axis) channel
  }
 
  x.result[0] = (word)(x_avg>>4);
  y.result[0] = (word)(y_avg>>4);
  z.result[0] = (word)(z_avg>>4); 
}

/*******************************************************************/
/*!
 * Read Values from Accelerometer
 * @return ADC Value
 */
word ReadAcceleration(byte channel)
{
  word adc;
  ADCSC1 = channel; 
  while (!(ADCSC1_COCO)){}              // Waits until ADC conversion is completed

  adc=ADCR;
  return adc;
   
}



/*******************************************************************/
/*!
 * Demo to see how hard you can shake the board from side to side
 */
void ShakeDemo() 
{
  int i;
  byte count=0;
  dword cur=0;
  byte result;

  high=0;
  PTCD_PTCD4 = 1;  /* Set for 6G Sensitivity */
  PTCD_PTCD5 = 1; 

  calibrate();
  AccelOn(Range6g);
  
  LEDScrollTouch("1.. 2.. 3.. SHAKE IT!");

  /* Take 20000 samples */
  for(i=0;i<20000;i++) 
  {
    cur=ReadAcceleration(0x05);  /* Select ADC5 (x-axis) channel */
    
    /* See if reached new high value */
    if(cur>high)
      high=cur;
   
    /* Display bar */ 
    result=(high-0x800)/128;
    PTAD=0x1F; 
    if(result>8) 
    {
      PTED=~(0xFF);
      PTDD=~(0xFF>>(16-result));
    } 
    else
    {
      PTED=~(0xFF>>(8-result));
      PTDD=~(0x00);
    }
  }
 
  PTCD_PTCD4 = 0;  /* Set accelerometer for 1.5G (Lowest Power) */
  PTCD_PTCD5 = 0; 
  
  AccelOff();  

  LEDScroll("Results: ");

  if(high==0xfff) 
  {
    LEDScroll("SHAKE MASTER!");
  }
  else if(high>0xf00) 
  {
    LEDScroll("Everything is blurry!");
  }   
  else if(high>0xd00) 
  {
    LEDScroll("Getting dizzy");
  }   
  else if(high>0xb00) 
  {
    LEDScroll("Not too bad");
  }   
  else if(high>0x900) 
  {
    LEDScroll("Did something move?");
  }
  else 
  {
    LEDScroll("That was really weak");
  }      
}

/*******************************************************************/
/*!
 * Demonstrate the Accelerometer
 * Moves dot around on the LED matrix in response to tilting the board left or right
 * or forward and back
 * 
 * Also determines if board is flat or upright when Demo starts and adjusts
 * how tilting moves the dot based on that
 */
void TiltDemo()
{
  calibrate();

  LEDScroll("Tilt");

  /* Continue until E8 is pressed */
  while(LastKeyPressed()!=8) 
  {
    AccelOn(Range15g); 
  
    /* Get current position */  
    avg_data();  
    
    AccelOff();   
     
    /* Badge held Flat */
    if(z.init<21000) 
    {
      position_flat();
    }
    /* Badge held straight up */ 
    else if (x.init<21000) 
    {
      position_upright();     
    }
    /* 
     * Badge held sideways or odd direction. 
     * Default to flat mode 
     */
    else 
    {
      x.init=34000;
      y.init=34000;
      position_flat();     
    }
 
    /* Output dot */
    PTAD  = (byte) y_output;
    
    if(x_output>0x0080) 
    {
      PTED = ~(0x00);  
      PTDD  = (byte) ~(x_output>>8); 
    }
    else 
    {
      PTDD = ~(0x00);  
      PTED = (byte) ~(x_output);  
    }
  
    /* Do a Delay so LED dot moves slow */
    
    /* Turn on RTC Clock */
    SCGC2_RTC=1;
  
    /* Turn on RTC Interrupt for .1 seconds */
    rtc_init(0xD);
    
    /* Go to sleep */
    asm (stop #0x2000);
    
    /* Turn off RTC Interrupt */      
    RTCSC  = 0x00;
  
    /* Turn off RTC Clock */
    SCGC2_RTC=0;
  }
}

/*******************************************************************/
/*!
 * Get default values from accelerometer
 */
void calibrate() 
{   
  AccelOn(Range15g); 
  
  avg_data(); 
  
  AccelOff(); 
  
  x.init=x.result[0];
  y.init=y.result[0];
  z.init=z.result[0];

  /* Initizalize variables for TiltDemo */
  y_output=0x0004;
  x_output=0x0080;  
}



/*******************************************************************/
/*!
 * Detect tilting in the X-direction to move mouse 
 */
byte MouseX(dword xinit)
{
  y.init=xinit;

  AccelOn(Range15g); 
  
  /* Get current position */
  avg_data();  
  
  AccelOff();   
     
  /* If tilting far right move mouse fast to right */ 
  if(y.result[0]<(y.init-(2*SENSITIVITY))) 
  { 
    x_output=8;
  }   
  /* If tilting slightly right move mouse slowly to right */   
  else if(y.result[0]<(y.init-SENSITIVITY)) 
  { 
      x_output=1;
  }  
  /* If tilting far left move mouse fast to left */    
  else if(y.result[0]>(y.init+(2*SENSITIVITY)))
  {
     x_output=-8;
  }
  /* If tilting slightly left move mouse slowly to left */         
  else if(y.result[0]>(y.init+SENSITIVITY))
  {
     x_output=-1;
  }
  /* If not tilting than don't move mouse */       
  else 
  {
    x_output=0;
  }
  return x_output;
}

/*******************************************************************/
/*!
 * Detect tilting in the Y-direction to move mouse 
 */
byte MouseY(dword yinit)
{
  x.init=yinit;

  AccelOn(Range15g); 
  
  /* Get current position */
  avg_data();  
   
  AccelOff();   
    
  /* If tilting far up, move mouse fast up */  
  if(x.result[0]<(x.init-(2*SENSITIVITY))) 
  { 
    y_output=8;
  }
  /* If tilting slightly up, move mouse slowly up */  
  else if(x.result[0]<(x.init-SENSITIVITY)) 
  { 
    y_output=1;
  }
  /* If tilting far down, move mouse fast down */     
  else if(x.result[0]>(x.init+(2*SENSITIVITY)))
  {
     y_output=-8;
  }
  /* If tilting slightly down, move mouse slowly down */        
  else if(x.result[0]>(x.init+SENSITIVITY))
  {
     y_output=-1;
  }
  /* If not tilting than don't move mouse */          
  else 
  {
    y_output=0;
  }
  return y_output;
}


/*******************************************************************/
/*!
 * Detect tilting when the board is laid flat
 */
void position_flat() 
{
  unsigned long x_min, x_max, y_min, y_max;

  y_min = y.init-SENSITIVITY;
  y_max = y.init+SENSITIVITY;  
  x_min = x.init-SENSITIVITY;
  x_max = x.init+SENSITIVITY; 
  
  /* Check to see if need to shift dot on the x-axis on LED 
   *  (y-axis output from accelerometer) 
   */
  if(y.result[0]<y_min) 
  { 
    /* If tilting to left move LED to the left */
    if(!(x_output&0x8000)) 
    {
      /* Shift over if not reached edge of LED */
      x_output=(word)(x_output<<1);
    }   
  } 
  else if(y.result[0]>y_max)
  {
    /* If tilting to right move LED to the right */
    if(!(x_output&0x0001)) 
    {
      /* Shift over if not reached edge of LED */
      x_output=(word)(x_output>>1);
    } 
  }
    
  /* Check to see if need to shift dot on the y-axis on LED 
   *  (x-axis output from accelerometer) 
   */
  if(x.result[0]<x_min) 
  { 
    /* If tilting down move LED down */    
    if(!(y_output&0x0010)) 
    {
      /* Shift over if not reached edge of LED */
      y_output=(byte)(y_output<<1);
    }   
  }
  else if(x.result[0]>x_max)
  {
    /* If tilting up move LED up */
    if(!(y_output&0x0001)) 
    {
      /* Shift over if not reached edge of LED */
      y_output=(byte)(y_output>>1);
    } 
  }    
}

/*******************************************************************/
/*!
 * Detect tilting when the board is held upright
 */
void position_upright() 
{
  unsigned long z_min, z_max, y_min, y_max;
  
  z_min = z.init-SENSITIVITY;
  z_max = z.init+SENSITIVITY;  
  y_min = y.init-SENSITIVITY;
  y_max = y.init+SENSITIVITY; 
  
  /* Check to see if need to shift dot on the x-axis on LED 
   *  (y-axis output from accelerometer) 
   */
  if(y.result[0]<y_min) 
  { 
    /* If tilting to left move LED to the left */
    if(!(x_output&0x8000)) 
    {
      /* Shift over if not reached edge of LED */
      x_output=(word)(x_output<<1);
    }   
  } 
  else if(y.result[0]>y_max)
  {
    /* If tilting to right move LED to the right */
    if(!(x_output&0x0001)) 
    {
      /* Shift over if not reached edge of LED */
      x_output=(word)(x_output>>1);
    } 
  }
    
  /* Check to see if need to shift dot on the y-axis on LED 
   *  (z-axis output from accelerometer) 
   */
  if(z.result[0]<z_min) 
  { 
    /* If tilting down move LED down */
    if(!(y_output&0x0001)) 
    {
      /* Shift over if not reached edge of LED */
      y_output=(byte)(y_output>>1);
    }   
  }
  else if(z.result[0]>z_max)
  {
      /* If tilting up move LED up */    
    if(!(y_output&0x0010)) 
    {
      /* Shift over if not reached edge of LED */
      y_output=(byte)(y_output<<1);
    } 
  }    
}


/*******************************************************************/
/*!
 * Get accelerometer out of sleep mode, turn on ADC clock,
 * and configure ADC
 */
void AccelOn(char sensitivity)
{
  int i;

  switch(sensitivity) 
  {
    case Range15g:
      PTCD_PTCD4 = 0;  
      PTCD_PTCD5 = 0; 
      break;
    case Range2g:
      PTCD_PTCD4 = 0;  
      PTCD_PTCD5 = 1; 
      break;
    case Range4g:
      PTCD_PTCD4 = 1;  
      PTCD_PTCD5 = 0; 
      break;
    case Range6g:
      PTCD_PTCD4 = 1;  
      PTCD_PTCD5 = 1; 
      break;
    default:
      PTCD_PTCD4 = 0;  
      PTCD_PTCD5 = 0; 
      break;                  
  }
  
  /* Wake up accelerometer */
  PTCD_PTCD3=1;
  
  /* Turn on ADC Clock */
  SCGC1_ADC=1;
   
  /* Configure ADC since reset when turned clock off */
  // Bus clock as clock source, 12-bit conversion and divisor=4
  ADCCFG = 0x44;   
  
  /* Delay to allow time for accel chip to wake up */
  for(i=0;i<3000;i++) 
  { 
    asm("nop");
  }  
}

/*******************************************************************/
/*!
 * Put accelerometer into sleep mode and turn off ADC clock
 */
void AccelOff()
{
  PTCD_PTCD4 = 0;  
  PTCD_PTCD5 = 0; 

  /* Put accelerometer into sleep mode */
  PTCD_PTCD3=0; 
  
  /* Turn off ADC Clock */ 
  SCGC1_ADC=0;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
美女视频黄 久久| 日本伊人色综合网| 久久伊人蜜桃av一区二区| 欧美精品1区2区3区| 欧美日韩亚洲另类| 欧美日韩亚洲另类| 日韩一区二区免费电影| 欧美xxxxxxxx| 久久久久久黄色| 中文字幕欧美国产| 成人免费一区二区三区视频 | 亚洲色欲色欲www| 国产精品卡一卡二| 最新国产精品久久精品| 1024国产精品| 亚洲成av人**亚洲成av**| 亚洲成av人片在www色猫咪| 午夜精品国产更新| 国产尤物一区二区| 91亚洲国产成人精品一区二区三| 91国产丝袜在线播放| 欧美刺激午夜性久久久久久久| 欧美一区二区网站| 久久婷婷国产综合国色天香| 国产精品久久久久婷婷二区次| 亚洲人成在线播放网站岛国| 日本sm残虐另类| 国产成人无遮挡在线视频| 972aa.com艺术欧美| 91麻豆精品91久久久久久清纯 | 国产不卡一区视频| 91在线视频观看| 欧美一级理论性理论a| 中文字幕久久午夜不卡| 亚洲一区二区三区小说| 国产一区二区三区免费播放| 成人国产精品免费观看视频| 欧美久久久久中文字幕| 国产欧美日韩久久| 日韩精品免费视频人成| yourporn久久国产精品| 欧美一级理论片| 一个色综合网站| 国产福利一区二区三区| 欧美一二三四在线| 亚洲一区在线播放| 成人天堂资源www在线| 日韩欧美激情四射| 亚洲妇女屁股眼交7| 国产成人自拍在线| 91精品国产综合久久久久| 亚洲欧美一区二区三区国产精品| 麻豆精品视频在线观看视频| 色综合久久88色综合天天免费| 精品国产乱码久久久久久1区2区 | 99精品国产热久久91蜜凸| 日韩视频免费观看高清完整版在线观看| 国产偷国产偷亚洲高清人白洁| 免费在线观看不卡| 欧美无砖专区一中文字| 中文字幕日韩一区| 成人一级黄色片| 久久精品人人爽人人爽| 国内精品久久久久影院色| 欧美一区日本一区韩国一区| 亚洲图片一区二区| 欧美性xxxxx极品少妇| 亚洲欧美色综合| av在线播放一区二区三区| 国产午夜亚洲精品不卡 | 欧美国产综合色视频| 蜜桃在线一区二区三区| 制服丝袜亚洲精品中文字幕| 午夜视频一区在线观看| 欧美色手机在线观看| 一区二区三区在线观看网站| 在线视频国内一区二区| 一区二区三区在线免费视频| 欧美亚洲高清一区二区三区不卡| 亚洲欧美日韩中文字幕一区二区三区| 成人福利视频在线| 亚洲少妇30p| 色老头久久综合| 一区二区激情小说| 欧美高清你懂得| 免费成人av在线| 久久视频一区二区| 成人午夜激情影院| 亚洲资源在线观看| 777午夜精品免费视频| 老司机午夜精品| 国产日产精品1区| 色综合天天综合网天天看片| 亚洲自拍欧美精品| 精品久久久久久久久久久久久久久久久 | 国产91丝袜在线18| 亚洲视频免费观看| 在线播放一区二区三区| 黑人巨大精品欧美一区| 国产精品欧美一区二区三区| 色一情一伦一子一伦一区| 亚洲小说春色综合另类电影| 在线播放国产精品二区一二区四区| 男男视频亚洲欧美| 国产精品国产精品国产专区不片| 色狠狠色狠狠综合| 韩国精品久久久| 一区二区三区日韩在线观看| 51午夜精品国产| 成人性生交大片免费看视频在线| 夜夜嗨av一区二区三区中文字幕| 欧美一级久久久| 成人av手机在线观看| 日韩精品一卡二卡三卡四卡无卡| 精品动漫一区二区三区在线观看| 9i看片成人免费高清| 免播放器亚洲一区| 亚洲欧美自拍偷拍| 欧美一区二区久久| 91热门视频在线观看| 捆绑调教美女网站视频一区| 成人免费在线播放视频| 久久―日本道色综合久久| 色94色欧美sute亚洲13| 国产91清纯白嫩初高中在线观看| 天堂成人免费av电影一区| 中文字幕一区二区日韩精品绯色| 欧美一级理论性理论a| 欧美在线|欧美| 成人午夜视频福利| 国产馆精品极品| 精品无人码麻豆乱码1区2区 | 日本最新不卡在线| 亚洲欧美日韩国产另类专区| 日韩视频一区在线观看| 精品视频一区 二区 三区| 99免费精品视频| 精品写真视频在线观看| 日韩成人一级片| 午夜激情久久久| 亚洲一区二区三区四区五区中文 | 亚洲精品日日夜夜| 国产精品视频麻豆| 国产精品美女久久久久av爽李琼 | 久久先锋资源网| 日韩精品中文字幕在线不卡尤物| 欧美日韩国产高清一区| 欧洲国产伦久久久久久久| 在线观看成人免费视频| 一本到不卡免费一区二区| 91麻豆国产香蕉久久精品| 成人黄色av电影| 91日韩精品一区| 色菇凉天天综合网| 欧美日韩国产综合久久| 91精品国产色综合久久不卡电影| 欧美日韩高清一区| 欧美一级专区免费大片| 精品嫩草影院久久| 久久九九久精品国产免费直播| 国产天堂亚洲国产碰碰| 国产精品每日更新在线播放网址| 中文字幕av一区 二区| 亚洲欧洲av另类| 亚洲小说春色综合另类电影| 日韩电影在线一区二区| 久久99国产精品久久99果冻传媒| 国产综合色视频| 99在线精品一区二区三区| 色综合天天综合狠狠| 欧美日韩在线播| 日韩精品一区二区在线观看| 国产亚洲综合色| 夜夜夜精品看看| 激情五月激情综合网| 99久久综合色| 欧美日本一区二区在线观看| 精品国产乱码久久久久久久久| 国产精品美女www爽爽爽| 亚洲一级二级在线| 国内精品第一页| 91久久精品一区二区三| 精品人在线二区三区| 亚洲女人的天堂| 狠狠狠色丁香婷婷综合久久五月| 一本色道亚洲精品aⅴ| 欧美一区二区三区婷婷月色| 国产欧美精品一区二区色综合朱莉| 亚洲综合在线五月| 国产福利91精品一区| 欧美午夜精品一区| 欧美国产日韩亚洲一区| 五月婷婷另类国产| 波多野结衣欧美| 日韩欧美成人一区二区| 亚洲狠狠爱一区二区三区| 成人少妇影院yyyy| 日韩一卡二卡三卡国产欧美| 亚洲视频一二区| 国产不卡在线播放|