微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > MSP430G2553测试程序(温度检测)

MSP430G2553测试程序(温度检测)

时间:11-28 来源:互联网 点击:
//******************************************************************************

//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
//******************************************************************************
#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位数

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

}

上一篇:STC和ATMEL
下一篇:STM32中assert_param的使用

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top