/********************************************************
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:
Previous article:MSP430 self-destruction function design
Next article:MSP430 MCU Theory Review Knowledge Points
- 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
- Embedded system design of MCU, how to run SDRAM?
- Video: Introduction to mmWave Sensors
- Thank you for being there + thank you for your wife's protection
- The electrical engineer blew up the company because of a resignation dispute...
- Free sharing of analog high-definition AHD and TVI and CVI to HDMI and VGA and CVBS solution schematics
- [Anxinke NB-IoT Development Board EC-01F-Kit] 1. Unboxing and Hardware Appreciation
- TI C66x DSP instruction set jump instruction B
- November 24 live broadcast review: NXP's embedded human machine interface solution detailed explanation (including video playback, ppt, Q&A)
- BLDC Motor Control Algorithm - FOC Brief Introduction
- PyPortal weather and clock display