How to use the serial port of AT89C51 and the serial port of the computer for communication principles and experiments

Publisher:eaff86Latest update time:2023-03-21 Source: elecfansKeywords:AT89C51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Serial communication is of great significance to the microcontroller. It can not only transmit the data of the microcontroller to the computer, but also realize the control of the microcontroller by the computer. For example, you can display the data code written into the microcontroller on the computer. For example, you can use a button, when it is pressed, a certain letter such as: AA is sent to the computer for display through the serial port of the microcontroller, which plays some functions of the emulator. When the webmaster develops data acquisition equipment, he checks the data through the serial port. Correct or not.


The 51 microcontroller has a full-duplex serial communication port, so serial communication can be easily carried out between the microcontroller and the computer. Certain conditions must be met when performing serial communication. For example, the serial port of a computer is RS232 level, while the serial port of a microcontroller is TTL level. There must be a level conversion circuit between the two. We use a special chip MAX232 for this. For conversion, although several transistors can also be used for analog conversion, it is simpler and more reliable to use a dedicated chip. We use a three-wire system to connect the serial port, which means that only three of the wires are connected to the computer's 9-pin serial port: GND on pin 5, RXD on pin 2, and TXD on pin 3. This is the simplest connection method, but it is enough for us. The circuit is as shown in the figure below. Pin 10 of MAX232 is connected to pin 11 of the microcontroller, pin 9 is connected to pin 10 of the microcontroller, and pin 15 is connected to The 20-pin connection of the microcontroller. The experimental board provided on this website has been assembled with all hardware.

The hardware circuit of serial port communication is shown in the figure above


In order to be able to see the data sent by the microcontroller on the computer side, we must use a WINDOWS software to observe. Here we use a free computer serial port debugging software.

  

Click here to download and run this serial port debugging software. This is a green software that does not require installation. You can run this software directly at the current location. The software interface is as shown above. We first need to set the serial communication parameters, adjust the baud rate to 4800, and check the hexadecimal display. The serial port is selected as COM1. Of course, the serial port of the 51 MCU experiment board provided on the website must also be connected to the COM1 of the computer. Insert the MCU with the following program programmed into the universal socket of the MCU experiment board, and turn on the power of the 51 MCU experiment board. , then as long as you press K1 once, an "AF" will be added to the receiving area interface of the serial port debugging assistant software.

" character, indicating that the microcontroller successfully sends the "AF" character to the computer. The source program of the serial port experiment is as follows:

;This is a demonstration program for the AT89C51 microcontroller experimental development board to send data AF in one direction to the serial port of a PC
; MAX232 special chip is used for RS232/TTL level conversion.
;The communication baud rate is 4800KBPS, just press K1 once (that is P3.6 pin becomes low level)
; then send a hexadecimal AF character

ORG 0000H
MOV SCON,#50H;Set to serial port 1 mode
MOV TMOD,#20H;Baud rate generator T1 works in mode 2
MOV PCON,#80H;The baud rate is doubled to 2400x2=4800BPS
MOV TH1,#0F3H ;Preset initial value (preset initial value according to baud rate 2400BPS)
MOV TL1,#0F3H; Preset initial value (preset initial value according to baud rate 2400BPS)
SETB TR1; Start timer T1
; The above completes the communication initialization setting

WRIT: JB P3.6, $; Determine whether K1 is pressed. If not, wait for
ACALL DELAY10; Delay 10 milliseconds to eliminate contact jitter
JB P3.6, WRIT; Remove interference signal
JNB P3.6, $; Wait Release the button

MOV A, #0AFH; Send the hexadecimal character AF to the serial port
MOV SBUF, A; Send the AF through the serial port

AJMP WRIT

;10 millisecond delay subroutine
DELAY10:MOV R4,#20
D2:MOV R5,#248
DJNZ R5,$
DJNZ R4,D2
RET

END


Keywords:AT89C51 Reference address:How to use the serial port of AT89C51 and the serial port of the computer for communication principles and experiments

Previous article:Design of drip detection system based on AT89C51 microcontroller
Next article:How to use C language to implement 51 microcontroller to simulate I2C bus

Recommended ReadingLatest update time:2024-11-16 13:53

Design of OLED display driver based on SSD1303 and AT89C51
1. Introduction Organic electroluminescent display (OLED) technology is the next generation of the most competitive flat panel display technology. At present, the research focus of OLED is to improve the stability of the device, the luminous efficiency and the driving technology of high-quality dynami
[Microcontroller]
Design of OLED display driver based on SSD1303 and AT89C51
AT89C51 single chip microcomputer --2. Introduction to single chip microcomputer and C language
1. Microcontroller Overview 1.1 Computer components The computer host basically relies on the CPU, memory stick, and your bus controller (motherboard). The motherboard connects to these external hardware devices through its own hardware interface, such as the mouse and keyboard. The modem is the network MCU is com
[Microcontroller]
AT89C51 single chip microcomputer --2. Introduction to single chip microcomputer and C language
Microcontroller C language tutorial: Appendix 2 AT89C51 special function register list
Appendix 2 AT89C51 special function register list (applicable to chips with the same architecture) Special function registers marked with * are bit-addressable registers.
[Microcontroller]
Microcontroller C language tutorial: Appendix 2 AT89C51 special function register list
Explanation of micro programmable controller implemented using AT89C51
  Programmable controller, also known as PLC, plays an important role in the automation industry. As for programmable controllers, the editor has introduced its theoretical knowledge in previous articles. In order to enhance everyone's understanding of programmable controllers, this article will explain the micro prog
[Microcontroller]
Explanation of micro programmable controller implemented using AT89C51
Design and simulation of LED Chinese character display screen based on AT89C51 single chip microcomputer
O Introduction LED display is a flat display screen composed of light-emitting diode dot matrix modules or pixel units. It has the advantages of high luminous efficiency, long service life, flexible configuration, rich colors and strong adaptability to indoor and outdoor environments. It is widely used for infor
[Microcontroller]
Design and simulation of LED Chinese character display screen based on AT89C51 single chip microcomputer
Design of agricultural environment temperature monitoring system based on AT89C51 microcontroller and DS18B20
Modern facility agriculture is a high-tech, high-efficiency modern agricultural production method that integrates biotechnology, engineering technology, and environmental technology. It is an effective way to adjust the agricultural industry, adapt to the development of market economy and improve the utilization rate
[Microcontroller]
Design of agricultural environment temperature monitoring system based on AT89C51 microcontroller and DS18B20
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
Guess you like

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号