Introduction: Recently, I saw a friend asking on the Internet how to send a string of Chinese characters from a microcontroller to a computer. In fact, this question is not difficult. Haha. Just set the relevant parameters better, and then define the Chinese characters as a group of characters and send them to the computer.
In order to make everyone understand more clearly, I wrote the following program to demonstrate.
Operating conditions:
1.XP operating system.
2. XP's HyperTerminal display.
3.WJ-V4.0 development board.
4. Single chip microcomputer STC89C52.
5. Crystal oscillator 11.0592M
Steps:
1. Set TMOD to set the baud rate and working mode of timer 1.
2. Set the initial value of the timer.
3. Set the serial port working mode.
4. Set the baud rate without doubling it.
5. Open TR1 to allow sending.
6. Start the timer.
7.Serial interrupt is turned on.
8. Turn on EA interrupts.
Now post the source code:
#include #define uchar unsigned char #define uint unsigned int bit FS_Bit = 0; //Send flag bit codeucharTEXT0[] = "********************************rnn"; codeucharTEXT1[] = "Welcome to the electronics enthusiasts community!rnn"; codeucharTEXT2[] = "www.wang1jin.com!rnn"; codeucharTEXT3[] = "51 free development board PCB gift!rnn"; codeucharTEXT4[] = "Gift address: http://www.wang1jin.com/shop/goods.php?id=2rnn"; codeucharTEXT5[] = "********************************rnnnnn"; void Delay_Ms(uint i); //delay function void Uart_Char(uchar Value); //Send a data void Prints(uchar *Value); //Send a set of data void main(void) { TMOD = 0x20; //Set the baud rate to 9600 and the working mode of timer 1 TL1 = 0xFD; //Set the initial value TH1 = 0xFD; SCON = 0x50; //Set the serial port working mode PCON = 0x00; TR1 = 1; //Allow sending ET0 = 1; //Start the timer ES = 1; //Serial interrupt enabled EA = 1; while(1) { Prints(TEXT0); //Send data Prints(TEXT1); Prints(TEXT2); Prints(TEXT3); Prints(TEXT4); Prints(TEXT5); Delay_Ms(60000); //Delay } } void INIT_Uart(void) interrupt 4 { if(RI) //If data is received { RI = 0; } else { TI = 0; //Send a data FS_Bit = 0; // Clear flag bit } } void Uart_Char(uchar Value) { SBUF = Value; //Send data FS_Bit = 1; //Set the send flag while(FS_Bit); } void Prints(uchar *Value) { while((*Value) != '') //If not sent { Uart_Char(*Value); //Send one bit of data Value++; //The pointer points to the next bit of data } } void Delay_Ms(uint i) { while(--i ); } Finally, let me show you the effect of the program:
Previous article:51 MCU Summary - Pull-up Resistor
Next article:Design of coaxial connection and driving device of multiple stepping motors
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Several concepts of ARM simulation JTAG/J-LINK/ULINK/ST-LINK and their differences
- [NXP Rapid IoT Review] Hello Phased Experience
- STM32F103 and MM32F103 experience
- A radio that can "hear" its own voice
- SPI ASF issue on Atmel ATSAM3X8E
- Liaoning Province's automotive electronics industry is very active
- TouchGFX Design + Make a Rubik's Cube (2)
- To achieve the amplification of weak current, the choice of operational amplifier is the key. Generally, it is selected according to the following situations.
- Electronic digital alarm clock based on GD32E231
- New version of UFUN learning board information