📄 temp_sensor.c
字号:
/******************************************************************************
* *
* ********** *
* ************ *
* *** *** *
* *** ++ *** *
* *** + + *** CHIPCON *
* *** + *
* *** + + *** *
* *** ++ *** *
* *** *** *
* ************ *
* ********** *
* *
*******************************************************************************
Filename: temp_sensor.c
Target: cc2430
Author: kja
Revised: 30/5-2007
Revision: 1.2
Description:
This application show the chip temperature on the LCD display. Please refer
to Design Note DN102 (SWRA101) for details.
NOTE: The offset can be expected to have a variation at +/- 10 for
individual chip samples.
******************************************************************************/
/******************************************************************************
* INCLUDES
*/
#include "app_ex.h"
#include "lcd.h"
/******************************************************************************
* CONSTANTS
*/
#define GRADIENT_C 0.01496
#define OFFSET_C -300
#define ADC14_TO_CELSIUS(ADC_VALUE) \
( (float)ADC_VALUE *(float)GRADIENT_C + OFFSET_C)
#define GRADIENT_F (9.0/5.0 * GRADIENT_C)
#define OFFSET_F (9.0/5.0 * OFFSET_C) + 32
#define ADC14_TO_FARENHEIT(ADC_VALUE) \
( (float)ADC_VALUE *(float)GRADIENT_F + OFFSET_F)
#define DEGREE_SYMBOL_ADDRESS 0x01
/******************************************************************************
* TYPEDEFS
*/
/******************************************************************************
* GLOBAL VARIABLES
*/
/******************************************************************************
* LOCAL VARIABLES
*/
/******************************************************************************
* LOCAL FUNCTIONS
*/
void initTempSensor(void);
int8 getTemperature(void);
void temp_sensor_main(void);
/******************************************************************************
* @fn initTempSensor
*
* @brief
* Initializes components for use with the temperature sensor
* application example.
*
* Parameters:
*
* @param void
*
* @return void
*
******************************************************************************/
void initTempSensor(void){
DISABLE_ALL_INTERRUPTS();
SET_MAIN_CLOCK_SOURCE(CRYSTAL);
initLcd();
}
/******************************************************************************
*
* @fn getTemperature
*
* @brief
* Return the temperature measured with the internal temperature sensor.
*
* Parameters:
*
* @param void
*
* @return temperature
*
******************************************************************************/
int8 getTemperature(void){
uint16 value;
// Ref: 1,25 V, Resolution: 14bit, Temperature Sensor
if( CHVER < REV_C )
{
// This is due to errate number #19, CC2430 revision B
ADCCON2 = ( ADC_REF_1_25_V | ADC_14_BIT | ADC_TEMP_SENS );
ADCCON1 = 0x73;
while( !ADC_SAMPLE_READY() );
}
else
{
ADCIF = 0;
ADCCON3 = ( ADC_REF_1_25_V | ADC_14_BIT | ADC_TEMP_SENS );
while( !ADCIF );
}
ADC_GET_VALUE( value );
return ADC14_TO_CELSIUS(value);
// return ADC14_TO_FARENHEIT(value);
}
/******************************************************************************
*
* @fn temp_sensor_main
*
* @brief
*
*
* Parameters:
*
* @param void
*
* @return void
*
******************************************************************************/
#ifdef COMPLETE_APPLICATION
void temp_sensor_main(void){
#else
void main(void){
#endif
byte degreeSymbol[] = {0x07, 0x05, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00};
byte lcdBuffer[16];
uint8 temperature;
initTempSensor();
initNewSymbol((char *)degreeSymbol, CHAR1_ADDRESS);
lcdUpdateLine(LINE1, (char *)"Temperature:");
while( !stopApplication() )
{
temperature = getTemperature();
sprintf((char *)lcdBuffer, "%d%cC (not cal.)", temperature, DEGREE_SYMBOL_ADDRESS);
lcdUpdateLine(LINE2, (char *)lcdBuffer);
// wait one second
halWait(250);
halWait(250);
halWait(250);
halWait(250);
}
}
/******************************************************************************
* @fn temp_sensor_init
*
* @brief
* Initializes the temperature application example.
*
* Parameters:
*
* @param APPLICATION *a
* Main application
*
* @return void
*
******************************************************************************/
#ifdef COMPLETE_APPLICATION
void temp_sensor_init(APPLICATION *a){
a->menuText = (char *)"Temp Sensor";
a->description = (char *)"";
a->main_func = temp_sensor_main;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -