Temperature measurement and serial port transmission of Launchpad

Publisher:SHow111timeLatest update time:2017-01-03 Source: eefocusKeywords:Launchpad Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

 1 #include  "msp430g2553.h"

 2 

 3 void sendChar(unsigned char c)

 4 {

 5   while(!(IFG2&UCA0TXIFG));

 6   UCA0TXBUF=c;

 7 }

 8 

 9 void sendStr(unsigned char *s)

10 {

11       while(*s!='\0')

12       {

13               sendChar(*s);

14               s++;

15       }

16 }

17 

18 void main(void)

19 

20 {

21 

22 unsigned char i;

23 unsigned char temp;

24 unsigned long tempAverage;

25 unsigned long tempMeasured[8];

26 

27 WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

28 

29  BCSCTL1 = CALBC1_1MHZ;                    // Set DCO

30  DCOCTL = CALDCO_1MHZ;

31  BCSCTL2 &= ~(DIVS_3);

32 

33 

34  P1SEL = BIT1 + BIT2 ;                     // P1.1 = RXD, P1.2=TXD

35  P1SEL2 = BIT1 + BIT2 ;                     // P1.1 = RXD, P1.2=TXD

36 

37  UCA0CTL1 |= UCSSEL_2;                     // SMCLK

38  UCA0BR0 = 104;                            // 1MHz 9600

39  UCA0BR1 = 0;                              // 1MHz 9600

40  UCA0MCTL = UCBRS0;                        // Modulation UCBRSx = 1

41  UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**

42 

43  //IE2 |= UCA0RXIE;   // Enable USCI_A0 RX interrupt

44  

45 ADC10CTL1 = INCH_10 + ADC10DIV_3; // Temp Sensor ADC10CLK/4 Select the internal temperature sensor channel, divided by 4

46   ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON ;

47   __delay_cycles(1000);                     // Wait for ADC Ref to settle 

48   ADC10CTL0 |= ENC + ADC10SC;

49   

50 _EINT();

51  

52 sendStr("\n======== LaunchPad Thermometer=======\n");

53 

54 //__bis_SR_register(LPM0_bits + GIE);       // Enter LPM0, interrupts enabled

55 

56 

57  while(1)

58  {

59     if(i>7)

60     {

61             tempAverage=0;

62             for(;i>0;i--)

63                 tempAverage+=tempMeasured[i-1];

64             tempAverage >>= 3;

65             temp=(unsigned char)( ((tempAverage - 630) * 761) / 1024 );

66 sendStr("\n Temperature in Fahrenheit: ");

67             sendChar(temp%100/10+48);

68             sendChar(temp%10+48);

69 sendStr(" | Celsius temperature: ");                        

70                         temp=(temp-32)*5/9; 

71             sendChar(temp%100/10+48);

72             sendChar(temp%10+48);

73             sendChar('\n');

74 

75     }

76     else

77     {

78 ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start Sampling and conversion

79          tempMeasured[i]=ADC10MEM;

80          i++;

81     }

82 

83  __delay_cycles(100000);

84 

85 

86  }

87 }

88 

89 //  Echo back RXed character, confirm TX buffer is ready first

90 /*

91 #pragma vector=USCIAB0RX_VECTOR

92 __interrupt void USCI0RX_ISR(void)

93 {

94  while (!(IFG2&UCA0TXIFG));                // USCI_A0 TX buffer ready?

95  UCA0TXBUF = UCA0RXBUF;                    // TX -> RXed character

96 }

97 

98 */


Keywords:Launchpad Reference address:Temperature measurement and serial port transmission of Launchpad

Previous article:Another UART implementation of MSP430
Next article:MSP430 Learning Experience---Clock

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号