Msp430f149 single-chip serial C program, msp430f149 Single-Chip Microcomputer

Source: Internet
Author: User

Msp430f149 single-chip serial C program, msp430f149 Single-Chip Microcomputer
Msp430f149 single-chip microcomputer serial port C program msp430f149 single-chip microcomputer Introduction: MSP430 Series single-chip microcomputer is a kind of 16-bit ultra-low power consumption, with a streamlined Instruction Set (PROTEUS) introduced to the market in 1996 by Texas Instrument) (Mixed Signal Processor ).
Msp430f149 is an ultra-low-power MCU Based on flash memory or ROM. It provides 8 MIPS and a working voltage of 1.8 V-3.6 V. It has a flash memory of up to 60 kb and various high-performance analog and smart digital peripherals. Ultra-Low Power Consumption: 0.1 μA RAM (holding mode) 0.7 μA (Real-time clock mode) 200 μA/MIPS (Working Mode) within 6 μs, the device is quickly awakened from the standby mode. Parameter: Flash options: 1KB-60KB ROM options: 1KB-16KB RAM options: 512B-10KB GPIO options: 14, 22, 48-pin ADC options: 10 and 12-bit slope other integrated peripherals of SAR: analog comparator, DMA, hardware multiplier, SVS, 12-bit DAC (from Baidu encyclopedia)
C Language Program (using IAR for 430 ):

# Include <export x14x. h> typedef unsigned char uchar; typedef unsigned int uint; uchar RecBuf [256]; uchar Windex; uchar Rindex; void Send1Char (uchar sendchar); void PutString (uchar * ptr ); void com_init (); // initialize void com_init () {unsigned int I;/* close all IO ports in the following six lines */P1DIR = 0XFF; P1OUT = 0XFF; p2DIR = 0XFF; P2OUT = 0XFF; P3DIR = 0XFF; P3OUT = 0XFF; P4DIR = 0XFF; P4OUT = 0XFF; P5DIR = 0XFF; P5OUT = 0XFF; P6DIR = 0XF F; P6OUT = 0XFF; WDTCTL = WDTPW + WDTHOLD; // disable the watchdog P6DIR | = BIT2; P6OUT | = BIT2; // disable the level conversion P6DIR | = BIT7; P6OUT & = ~ BIT7; // turn off the level conversion P3SEL | = 0x30; // select P3.4 and P3.5 for UART communication port BCSCTL1 & = ~ XT2OFF; // XT2on do {IFG1 & = ~ OFIFG; // Clear OSCFault flag for (I = 0xFF; I> 0; I --); // Time for flag to set} while (IFG1 & OFIFG )); // OSCFault flag still set? BCSCTL2 | = SELM_2 + SELS; // MCLK = SMCLK = XT2 (safe) ME1 | = UTXE0 + URXE0; // enable USART0 to send and accept UCTL0 | = CHAR; // select the 8-character UTCTL0 | = SSEL1; // UCLK = SMCLK UBR00 = 0x45; // The baud rate is 115200 UBR10 = 0x00; // UMCTL0 = 0x00; // Modulation UCTL0 & = ~ SWRST; // initialize UART state machine IE1 | = URXIE0; // enable USART0 to receive interrupt _ EINT (); // enable global interrupt Windex = 0; Rindex = 0 ;} /*************************************** * *** Function Name: UART0_RXISR function: receives the interrupt service function of UART0, wake up the CPU here, and enable it to exit the low-power mode parameter: no return value: no *************************************** * ***/# pragma vector = UART0RX_VECTOR _ interrupt void UART0_RXISR (void) {if (RXBUF0 = 0x0d) LPM1_EXIT; else {RecBuf [Windex ++] = RXBUF0; Windex & = 0x7f; // when Windex = 0x80, changed to 0x00 ;}} /*************************************** * *** Function Name: send1Char function: Send a character parameter to the PC: sendchar -- Return Value of the character to be sent: no *************************************** * ***/void Send1Char (uchar sendchar) {while (! (IFG1 & UTXIFG0); // wait for the sending register to be empty TXBUF0 = sendchar ;} /*************************************** * *** Function Name: putSting function: Send the string parameter ptr to the PC to point to the pointer return value of the sent string: no *************************************** * ***/void PutString (uchar * ptr) {while (* ptr! = '\ 0') {Send1Char (* ptr ++); // send data} while (! (IFG1 & UTXIFG0); TXBUF0 = 0x0d; while (! (IFG1 & UTXIFG0); TXBUF0 = 0x0a; // send a line feed command *********** * ********/void main (void) {com_init (); PutString ("welcome to my blog"); PutString ("I am meizumx4! "); While (1) {LPM1 ;}}

-------------------------------------------------------
Format: N.8.1, 115200
No verification, 8 data bits, 1 Stop bits, baud rate 115200
------------------------------------------------------

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.