新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > MSP430G2553測試程序(溫度檢測)

MSP430G2553測試程序(溫度檢測)

作者: 時間:2016-11-28 來源:網(wǎng)絡(luò) 收藏
//******************************************************************************

//HW UART(J4)!!!!!! 特別注意,板子上J4有2個跳線要豎放,設(shè)為HW UART模式
//ADC檢測,并通過串口發(fā)送到PC
//MSP430G2533 Demo - USCI_A0, 9600 UART Echo ISR, DCO SMCLK
//http://jiwm.blog.163.com
//Baud rate divider with 1MHz = 1MHz/9600 = ~104.2
//ACLK = n/a, MCLK = SMCLK = CALxxx_1MHZ = 1MHz
//
//MSP430G2xx3
//-----------------
///||XIN|-
//| ||
//--|RSTXOUT|-
//||
//|P1.2/UCA0TXD|------------>
//|| 9600 - 8N1
//|P1.1/UCA0RXD|<------------
//
// IAR Embedded Workbench Version: 5.40
//******************************************************************************
#include"msp430g2553.h"
long temp;
long IntDegF;
long IntDegC;
unsigned int i;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;// Stop WDT
ADC10CTL1 = INCH_10 + ADC10DIV_3;// Temp Sensor ADC10CLK/4
ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON + ADC10IE;//The ADC10OSC, generated internally,
//is in the 5-MHz range, but varies with individual devices, supply voltage, and temperature. See the device-specific data sheet for the ADC10OSC specification.
DCOCTL = 0x00;// Set DCO 1MHz
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
P1SEL = BIT1 + BIT2 ;// P1.1 = RXD, P1.2=TXD
P1SEL2 = BIT1 + BIT2 ;// P1.1 = RXD, P1.2=TXD
UCA0CTL1 |= UCSSEL_2;// USCI clock source=SMCLK
UCA0BR0 = 104;// 1MHz 9600Refer to Page 435 of X2xx Guide
UCA0BR1 = 0;// 1MHz 9600
UCA0MCTL = UCBRS0;// Modulation UCBRSx = 1
UCA0CTL1 &= ~UCSWRST;// **Initialize USCI state machine**
__enable_interrupt();// Enable interrupts.
IE2 |= UCA0RXIE;// Enable USCI_A0 RX interrupt
//__bis_SR_register(LPM0_bits + GIE);// Enter LPM0, interrupts enabled
for(;;)
{ADC10CTL0 |= ENC + ADC10SC;// Sampling and conversion start
}


}
#pragma vector=USCIAB0RX_VECTOR//串口中斷
__interrupt void USCI0RX_ISR(void)
{
if ((UCA0RXBUF == c)||(UCA0RXBUF == C))// C or c received?
{
//IE2 |= UCA0TXIE;// Enable USCI_A0 TX interrupt
while (!(IFG2&UCA0TXIFG));// USCI_A0 TX buffer ready?
{
UCA0TXBUF=((IntDegC/10240)+48);//10位數(shù)

}
while (!(IFG2&UCA0TXIFG));// USCI_A0 TX buffer ready?
{
UCA0TXBUF=((IntDegC/1024)+48);//個位數(shù)

}

while (!(IFG2&UCA0TXIFG));// USCI_A0 TX buffer ready?
{
UCA0TXBUF=46;//.

}
while (!(IFG2&UCA0TXIFG));// USCI_A0 TX buffer ready?
{
UCA0TXBUF=((IntDegC*10/1024)+48);//小數(shù)

}
while (!(IFG2&UCA0TXIFG));// USCI_A0 TX buffer ready?
{
UCA0TXBUF=13;//換行

}


}
else
{

本文引用地址:http://butianyuan.cn/article/201611/322871.htm


//IE2 |= UCA0TXIE;// Enable USCI_A0 TX interrupt
UCA0TXBUF = 13;//換行
}
}

// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{
temp = ADC10MEM;
//IntDegC = ((temp - 673) * 423) / 1024;//-278~144 ,精度降低了
IntDegC = ((temp - 673) * 423); //改進后的

}



評論


技術(shù)專區(qū)

關(guān)閉