您的位置 首页 知识

MSP430G2553测验程序(温度检测)

******************************************************************************HWUART(J4)!!!!!!特别注意,板

//******************************************************************************

//HW UART(J4)!!!!!! 特别注意,板子上J4有2个跳线要竖放,设为HW UART形式
//ADC检测,并经过串口发送到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
//******************************************************************************
#includemsp430g2553.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位数

}
while (!(IFG2&UCA0TXIFG));// USCI_A0 TX buffer ready?
{
UCA0TXBUF=((IntDegC/1024)+48);//个位数

}

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

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

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

}


}
else
{


//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); //改善后的

}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/zhishi/256283.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部