MSP430F149 MCU implements uart data receiving interrupt

Publisher:和谐共融Latest update time:2018-07-11 Source: eefocusKeywords:MSP430F149 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

/********************************************************
Program function: MCU keeps sending data to PC and the corresponding
          ASCII characters of 0~127 are displayed on the screen
------------------------------------------------------
Communication format: N.8.1, 9600
------------------------------------------------------
Test description: Open the serial port debugging wizard, set the communication format correctly, and observe the screen
******************************************************/


#include


typedef unsigned char uchar;
typedef unsigned int uint;


extern void Delays(void);
extern uchar GetChar(void);
extern void PutChar(uchar c);
extern void PutString(uchar *ptr);
extern void InitUART(void);


static uchar pstr = 'A';


/************************Main function**********************/
void main(void)
{
    uchar *tishi = " MCU sends 0~127 to PC and the\
                    \n screen will display their corresponding\
                    \n ASCII code as follows:";
    uchar value = 0;
    //uchar c;
    int i = 10;
    int j = 100;
    
    WDTCTL = WDTPW + WDTHOLD; // 关狗
    
    InitUART();
    _EINT(); //Enable global interruptwhile
    
    (i--)
    {    
        while (!(IFG1 & UTXIFG0));
        TXBUF0 = value++;
        value &= 0x7f; // Ensure that value is less than 128
        while (!(IFG1 & UTXIFG0));
        TXBUF0 = '\n';
        Delays();
    }
    
    PutString(tishi);


    while(j--)
    {
        PutChar(pstr);    
        //if(IFG1 & URXIFG0) //If a character is received
          //c = RXBUF0;
        //PutChar(c);        
        Delays();   
    }
 
    while(1)
    {
        Delays();            
    }
}


#include


typedef unsigned char uchar;
typedef unsigned int uint;


void Delays(void);
uchar GetChar(void);
void PutChar(uchar c);
void PutString(uchar *ptr);
void InitUART(void);




/*******************************************
Function name: GetChar
Function: Send character to the development board
Parameter: None
Return value: char
********************************************/
uchar GetChar(void)
{
      uchar c;
      
      while(URXIFG0 == 1);
      c = RXBUF0;
      
      return c; //Send the received character 
}


/***********************************************
Function name: PutChar
Function: Send character to the development board
Parameter: uchar
Return value: None
**************************************************/
void PutChar(uchar c)
{
      while (!(IFG1 & UTXIFG0));
      TXBUF0 = c; //Send the received characters 
}


/***********************************************
Function name: PutStingFunction
: Send string to PCParameter
: NoneReturn
value: None
********************************************/
void PutString(uchar *ptr)
{
      while(*ptr != '\0')
      {
            while (!(IFG1 & UTXIFG0)); // Is TX buffer free?
            TXBUF0 = *ptr++; // Send data
      }
      while (!(IFG1 & UTXIFG0));
      TXBUF0 = '\n';
}
/*******************************************
Function name: Delays
Function: Delay for a while
Parameters: None
Return value: None
********************************************/
void Delays(void)
{
    uchar i=20;
    uint j;


    while(i--)
    {
            j=2000;
            while(j--);
    }
}
/*******************************************
Function name: InitUART
Function: Initialize UART port
Parameters: None
Return value: None
********************************************/
void InitUART(void)
{
    P3SEL |= 0x30; // P3.4,5 = USART0 TXD/RXD
    ME1 |= URXE0 + UTXE0; // Enable USART0 T/RXD
    UCTL0 |= CHAR; // 8-bit character
    UTCTL0 |= SSEL0; // UCLK = ACLK
    UBR00 = 0x03; // 32k/9600 - 3.41
    UBR10 = 0x00; //
    UMCTL0 = 0x4A; // Modulation
    UCTL0 &= ~SWRST; // Initialize USART state machine
    IE1 |= URXIE0; // Enable receive interrupt of USART0
}


#pragma vector=UART0RX_VECTOR
__interrupt void UART0_RXISR(void)
{
    uchar *Pstring = " Receive Data :";
    pstr = RXBUF0;
    PutString(Pstring);
    PutChar(pstr);

}


The serial port debugging assistant displays the following:


Keywords:MSP430F149 Reference address:MSP430F149 MCU implements uart data receiving interrupt

Previous article:MSP430 self-destruction function design
Next article:MSP430 MCU Theory Review Knowledge Points

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号