How to send Chinese characters from 51 MCU to PC

Publisher:xi24Latest update time:2021-01-21 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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:

Reference address:How to send Chinese characters from 51 MCU to PC

Previous article:51 MCU Summary - Pull-up Resistor
Next article:Design of coaxial connection and driving device of multiple stepping motors

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号