📄 hal_adconversion.c
字号:
/*****************************************************************************
* *
* ********** *
* ************ *
* *** *** *
* *** +++ *** *
* *** + + *** *
* *** + CHIPCON CC2420 *
* *** + + *** CC2420 HAL LIBRARY FILE *
* *** +++ *** *
* *** *** *
* *********** *
* ********* *
* *
*****************************************************************************
* *
* A number of helpful library macros and defines for the ATmega128 *
* to be included to increase the legibility of your code and to be used *
* with CC2420DB. *
* *
*****************************************************************************
* Device: CC2420 *
* File: hal_ADConversion.h *
* Author: MBR *
* Target: ATmega128 *
* Created: 2004-02-11 *
* *
*****************************************************************************
* Revision history: *
* *
*
* *
* *
* *
****************************************************************************/
#include <include.h>
// Global SPI status byte from CC2420
BYTE spiStatusByte;
//----------------------------------------------------------------------------
// INT16 hal_ADConversion(void)
//
// Description:
// This function perfroms eight ADC conversions and establishes an
// average ADC value found by the internal Atmega128 ADC.
//
// Arguments:
// None
//
// Return value:
// The ADC value found for the ADC conversion preformed
//----------------------------------------------------------------------------
INT16 hal_ADConversion(void) {
INT16 ADC_temp;
INT16 hadcresult;
UINT8 i;
//Do the ADC conversion 8 times for better accuracy
for(i = 0; i < 8; i++) {
//Start conversion
ADCSRA |= (1 << ADSC);
//Wait for conversion done, ADIF flag active
while(!(ADCSRA & 0x10));
//Read out ADCL register
ADC_temp = ADCL;
//Read out ADCH register
ADC_temp += (ADCH << 8);
//Accumulate result (8 samples) for later averaging
hadcresult += ADC_temp;
}
// Average the 8 samples
hadcresult = hadcresult >> 3;
// Return the ADC value found
return(hadcresult);
} // hal_ADConversion
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -