msp430用ADC10来测片内温度两极管的电压
扫描二维码
随时随地手机看文章
MSP430用ADC10来测片内温度两极管的电压
#include"msp430x22x4.h"
//此程序是用ADC10来测片内温度两极管的电压
//执行程序来查看ADC10MEM寄存器的值,
//并用V(temp)=0.00355*TempC+0.986公式来计算片子温度
//最后ad采样值存在ad_value,温度值存在value中,设置断点查看各个计数值
//MSP430F2274
//-----------------
///||XIN|-
//|||
//--|RSTXOUT|-
//||
//|P1.0|-->LED
floatad_value;
floatvalue;
inta[]={0xc0,0xf9,0xa4,0xb0,0x99,0xa92,0x82,0xf8,0x80,0x90};/*共阳*/
//inta[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};/*共阴*/
intp1,p2,p3,p4;
intm,i;
voiddelay()
{
for(i=0;i<=100;i++);
}
intmain(void)
{
WDTCTL=WDTPW+WDTHOLD;//关看门狗
BCSCTL1=CALBC1_1MHz;//设定DCO为1MHZ
DCOCTL=CALBC1_1MHZ;
P3SEL=0x00;
P3DIR=0xff;
P3OUT=BIT0+BIT1+BIT2+BIT3;
P4SEL=0x00;
P4DIR=0xff;
P4OUT=0x00;
TACTL|=TASSEL0;
TACTL|=TACLR;
CCTL0|=CCIE;
CCR0=32768;
ADC10CTL1=INCH_10;//选择第10通道,为片内温度传感器
ADC10CTL0=REFON+SREF_1;//打开1.5V正参考,地为负参考
ADC10CTL0|=ADC10ON+ADC10SHT_3+ADC10IE;//打开ADC10内核,设定采样保持时间为64个ADC10CLK,使能ADC10中断
ADC10CTL0|=ENC+ADC10SC;//启动AD转换
_BIS_SR(GIE+CPUOFF);//开总中断并进入低功耗
value=((ad_value*1.5/1023)-0.986)/0.00355;//计算温度
p1=(int)value/10;
p2=(int)value%10;
m=(int)(value*100)%100;
p3=m/10;
p4=m%10;
while(1)
{
P3OUT=BIT3;
P4OUT=a[p1];
delay();
P3OUT=BIT2;
P4OUT=a[p2];
delay();
P3OUT=BIT2;
P4OUT=0x7f;
delay();
P3OUT=BIT1;
P4OUT=a[p3];
delay();
P3OUT=BIT0;
P4OUT=a[p4];
delay();
}
}
#pragmavector=ADC10_VECTOR//ADC10中断服务
__interruptvoidadc_isr(void)
{
ad_value=ADC10MEM;
_BIC_SR_IRQ(CPUOFF);
}