📄 fet140_sd16_tempsingconv.c
字号:
//******************************************************************************
// MSP-FET430P140 Demo - SD16, Using the temperature sensor
//
// This example shows how to use the intergrated temperature sensor channel A6
// to measure temperature. In this example, a single conversion is performed of
// the temperature sensor.
// The temperature is then calculated in degrees C and F, based on the
// conversion value. Test by setting and running to a break point at "_NOP()"
// To view the temperature open a watch window in C-Spy and view DegC and
// DegF.
//
// MSP430FE427
// ---------------
// | A6|
// | |
//
//
// Harman Grewal
// Texas Instruments, Inc
// Oct, 2004
// IAR Embedded Workbench Version: 2.21B
//******************************************************************************
#include "msp430xE42x.h" // Standard Equations
static unsigned int ADCresult;
static unsigned long int DegC, DegF, DegK;
void main(void)
{
volatile unsigned int i;
WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer
FLL_CTL0 |= XCAP14PF; // Set load capacitance for xtal.
for (i = 0; i < 20000; i++); // Delay - to allow watch crystal to stabilize.
SD16CTL = SD16REFON+SD16SSEL0; // Turn on SD16 Ref,SMCLK
SD16CCTL2 |= SD16SNGL+SD16IE ; // Single Conv, Enable Interrupt
SD16INCTL2 |= SD16INCH_6; // Select Channel A6
_EINT(); // Enable interrupts
for ( i=0; i<0xFFFF; i++) // Delay for reference start-up
{
}
while (1)
{
SD16CCTL2 |= SD16SC; // Start conversion
_BIS_SR(LPM0_bits); // Enter LPM0
// DegK = (Vsensor)/1.32mV/K
// DegC = DegK - 273, Vref = 1200 mV
// Vsensor = (Vref)*(ADCresult-32768)/65536)
// DegK -> ((ADCresult - 32768)*909)/65536
DegK = ((((long)ADCresult-32768)*909)/65536);
DegC = DegK - 273;
DegF = ((DegC * 9/5)+32); // Calculate DegF
_NOP(); //SET BREAKPOINT HERE
}
}
#pragma vector=SD16_VECTOR
__interrupt void SD16ISR (void)
{
ADCresult = SD16MEM2; // Move results, IFG is cleared
_BIC_SR_IRQ(LPM0_bits); // Clear LPM0
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -