msp430用ADC10來測片內(nèi)溫度兩極管的電壓
MSP430用ADC10來測片內(nèi)溫度兩極管的電壓
#include"msp430x22x4.h"
//此程序是用ADC10來測片內(nèi)溫度兩極管的電壓
//執(zhí)行程序來查看ADC10MEM寄存器的值,
//并用V(temp)=0.00355*TempC+0.986公式來計算片子溫度
//最后ad采樣值存在ad_value,溫度值存在value中,設(shè)置斷點查看各個計數(shù)值
//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;//關(guān)看門狗
BCSCTL1=CALBC1_1MHz;//設(shè)定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通道,為片內(nèi)溫度傳感器
ADC10CTL0=REFON+SREF_1;//打開1.5V正參考,地為負參考
ADC10CTL0|=ADC10ON+ADC10SHT_3+ADC10IE;//打開ADC10內(nèi)核,設(shè)定采樣保持時間為64個ADC10CLK,使能ADC10中斷
ADC10CTL0|=ENC+ADC10SC;//啟動AD轉(zhuǎn)換
_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中斷服務(wù)
__interruptvoidadc_isr(void)
{
ad_value=ADC10MEM;
_BIC_SR_IRQ(CPUOFF);
}