1 #include "msp430g2553.h"
2
3 typedef unsigned char uchar;
4 typedef unsigned int uint;
5
6 #define LED BIT0
7 #define TXD BIT1 // TXD on P1.1
8 #define RXD BIT2 // RXD on P1.2
9 #define POUT P1OUT
10
11 #define BITTIME_1b 13*4 //1 bit width
12 #define BITTIME_1b5 13*6 //1.5 bit width
13
14 flying bitcnt;
15 uint uart_buf;
16 int Send_flag;
17
18 uchar *str=" Hello EEWorld! \r";
19
20 void FaultRoutine(void)
21 {
22 while(1); // Exception hang
23 }
24
25 void ConfigClocks(void)
26 {
27 if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
28 FaultRoutine(); // If calibration data is erased
29 // run FaultRoutine()
30 BCSCTL1 = CALBC1_1MHZ; // Set range
31 DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation
32 BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO
33 IFG1 &= ~OFIFG; // Clear OSCFault flag
34 BCSCTL2 = 0; // MCLK = DCO = SMCLK
35 }
36
37 void ConfigPins(void)
38 {
39 P1DIR |= TXD+LED;
40 P1DIR &= ~RXD; // P1.3 input, other outputs
41 P1OUT |= TXD; // clear output pins
42
43 }
44
45
46 //Send a byte
47 void send_char(uchar tchar)
48 {
49 TACTL = TACLR + TASSEL_2 + ID_3; //Select SMCLK clock; clear TAR
50 CCR0 = BITTIME_1b5; //crr0 timing interval is 1 bit time width
51 CCTL0 |= CCIE; //Open CCR0 interrupt
52 bitcnt = 10; //Number of bits to be sent
53 uart_buf = 0x0100; //8+N+1
54 uart_buf |= tchar; //stop bit and start bit;
55 uart_buf <<=1;
56 Send_flag = 0;
57 TACTL |= MC_1; //Start TA, UP mode.
58 _BIS_SR(GIE);
59 while(!Send_flag); //wait until send complete
60 Send_flag = 1;
61 }
62
63 //Send a string
64 void send_String(uchar *tstr)
65 {
66 while(*tstr)
67 send_char(*tstr++);
68 }
69
70
71 void send_IRQ(void)
72 {
73 if(bitcnt>0)
74 {
75 if(uart_buf & 0x01)
76 POUT |= TXD;
77 else
78 POUT &= ~TXD;
79 uart_buf >>= 1;
80 bitcnt--;
81 }
82 else
83 {
84 TACTL &= ~MC_3; //Close the TA when a Byte send over. ??
85 CCTL0 &= ~CCIE; //Disable CCR0 interrupt
86 Send_flag = 1;
87 }
88
89 }
90
91
92
93 void main( void )
94 {
95 // Stop watchdog timer to prevent time out reset
96 uint i;
97
98
99
100 WDTCTL = WDTPW + WDTHOLD;
101 ConfigClocks();
102 ConfigPins();
103
104
105 while(1)
106 {
107 send_String(str);
108
109 for(i=50000;i>0;i--);
110 for(i=50000;i>0;i--);
111 for(i=50000;i>0;i--);
112 for(i=50000;i>0;i--);
113 POUT ^= LED; // Flip LED
114 }
115 }
116
117 // Timer A0 interrupt service routine
118 #pragma vector=TIMER0_A0_VECTOR
119 __interrupt void Timer_A (void)
120 {
121
122
123 send_IRQ();
124 }
Previous article:MSP430 MCU ADC analog-to-digital conversion operation
Next article:Temperature measurement and serial port transmission of Launchpad
- 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
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
- ASML predicts that its revenue in 2030 will exceed 457 billion yuan! Gross profit margin 56-60%
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- The gift redemption speed is really fast
- DSP 28335Control Suit lighting experiment
- What are some good ways to protect the algorithm programs in the equipment in the industrial control industry?
- VMM Image Measurement Software
- msp430F149 PWM adjustment
- Album information compilation: Power supply simulation, those who need it, please enter!
- Detection circuit
- A scientist who continues to live as a cyborg
- Adafruit IO Time Tracking Cube
- Look at this board, guys.