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 */
Previous article:Another UART implementation of MSP430
Next article:MSP430 Learning Experience---Clock
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- Isolated power supply topology (transformer introduced Buck and Boot topology)
- Why should the decoupling capacitor be placed close to the power supply when drawing PCB?
- TI C6000 Data Storage Processing and Performance Optimization
- The research institute is looking for backbones and team leaders in the field of electronics for 150,000-300,000 yuan
- EEWORLD University ---- Practical production of IoT projects: Bluetooth 4.0 BLE development - smart bulbs - universal remote control
- SensorTile.Box Kit Operation Mode Expert Mode Trial
- Boost chip
- An impedance matching problem of rf amp
- Nanxin, Qinheng, Zhaoyi, Yatli...many good boards are free to review here!
- Is there something wrong with my op amp circuit?