📄 accelerometer.c
字号:
/*
*********************************************************************************************************
* uC/OS-II
* The Real-Time Kernel
*
* (c) Copyright 2004, Micrium, Weston, FL
* All Rights Reserved
*
*
* BOARD SUPPORT PACKAGE (BSP)
* Frescale MCF51QE
*
* File : accelerometer.c
* By : Eric Shufro
*********************************************************************************************************
*/
#include <includes.h>
/*
*********************************************************************************************************
* CONSTANTS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* PROTOTYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* Accelerometer_Init()()
*
* Description: This function initializes the on-chip ATC peripheral for use with the
* on-board tri-axis accelerometer.
*
* Arguments : None.
*
* Returns : None.
*
* Note(s) : None.
*********************************************************************************************************
*/
void Accelerometer_Init (void)
{
SCGC1 |= SCGC1_ADC_MASK; /* Ensure ADC clock is enabled */
ADCCFG = ADCCFG_MODE0_MASK | ADCCFG_ADIV0_MASK; /* Input clock divide by 2, 12 bit conversions */
}
/*
*********************************************************************************************************
* Accerlometer_Rd()
*
* Description: This function reads the ATC value for the specified channel
*
* Arguments : channel The ATC channel to read. One of the following channels
* should be specified:
* ATC_RD_X
* ATC_RD_Y
* ATC_RD_Z
*
* Returns : The RAW ATC channel value for the selected channel. 0 when channel is invalid.
*
* Note(s) : None.
*********************************************************************************************************
*/
CPU_INT16U Accelerometer_Rd (CPU_INT08U channel)
{
CPU_INT08U timeout;
timeout = 100; /* Configure a timeout value to prevent an infinite loop */
switch (channel) { /* Select the specified ATC channel to read */
case ATC_RD_X:
ADCSC1 = ATC_RD_X;
break;
case ATC_RD_Y:
ADCSC1 = ATC_RD_Y;
break;
case ATC_RD_Z:
ADCSC1 = ATC_RD_Z;
break;
default:
return (0); /* Invalid channel argument, return 0 */
break;
}
while (((ADCSC1 & ADCSC1_COCO) == 0) && (timeout > 0)) { /* Wait until conversion is complete */
timeout--;
}
return (ADCR);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -