📄 lab-06-adc12.c
字号:
//******************************************************************************
// MSP430xG461x Demo - ADC12, Sample A10 Temp and Convert to oC and oF
//
// This example shows how to use the intergrated temperature sensor to measure
// temperature. When the temperature diode channel (A10) is selected for
// conversion, the internal reference is automatically turned on as the source
// for the sensor. Note however, that it is NOT automatically selected for the
// conversion. Any available reference can be used for the conversion. In
// this example, a single conversion is performed of the temperature diode.
// The temperature is then calculated in degrees C and F, based on the A/D
// conversion value. Test by setting and running to a break point at
// "__no_operation()". To view the temperature open a watch window with the
// debugger and view DegC and DegF.
//
// Note: This example does not perform a calibration on the temperature sensor
// A calibration of the temperature senosr may be necessary in an application.
// see the device datasheet for the temperature sensor specification.
// ACLK = 32kHz, MCLK = SMCLK = default DCO 1048576Hz, ADC12CLK = ADC12OSC
//
// MSP430xG461x
// -----------------
// /|\| XIN|-
// | | | 32kHz
// --|RST XOUT|-
// | |
// | |- A10
//
// FengLF
// LSD SCIENCE& TECHNOLOGY CO.,LTD
// 2007.06
// Built with IAR Embedded Workbench Version: 3.42A
//******************************************************************************
#include "msp430xG46x.h"
volatile unsigned int i;
volatile unsigned int ADCresult;
volatile unsigned long int DegC, DegF;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
ADC12CTL0 = ADC12ON + REFON + REF2_5V + SHT0_6;
// 设置 ADC12, 参考电压2.5V,采样周期25.6uS
ADC12CTL1 = SHP; // 内部定时采样
ADC12MCTL0 = INCH_10 + SREF_1; // 选择采样通道 A10, Vref+
ADC12IE = 0x01; // 使能 ADC12IFG.0
for (i = 0; i < 0x3600; i++); // 延时
ADC12CTL0 |= ENC; // 使能转换
__enable_interrupt(); // 开中断
while(1)
{
ADC12CTL0 |= ADC12SC; // 开始采样
__bis_SR_register(LPM0_bits); // 进入低功耗 LPM0
// DegC = (Vsensor - 986mV)/3.55mV
// Vsensor = (Vref)(ADCresult)/4095)
// DegC -> ((ADCresult - 1615)*704)/4095
DegC = ((((long)ADCresult-1615)*704)/4095);
DegF = ((DegC * 9/5)+32); // 计算采样结果 DegF
__no_operation(); // 设置断点 ,观察结果
}
}
#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR(void)
{
ADCresult = ADC12MEM0; // 保存结果
__bic_SR_register_on_exit(LPM0_bits); //退出低功耗 LPM0
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -