The serial port of AT89C51 communicates with the serial port of the computer

Publisher:静逸闲云Latest update time:2015-01-26 Source: laoguKeywords: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 single-chip microcomputer. It can not only transmit the data of the single-chip microcomputer to the computer, but also realize the control of the single-chip microcomputer by the computer. For example, you can display the data code written into the single-chip microcomputer on the computer. For example, you can use a button, and when you press it, a certain letter such as AA will be sent to the computer for display through the serial port of the single-chip microcomputer, which plays some functions of the emulator. When the webmaster develops the data acquisition equipment, he uses the serial port to check whether the data is correct or not.

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

 

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

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

  

    Click here to download and run the serial port debugging software. This is a green software. No installation is required. You can run this software directly at the current location. The software interface is as shown above. We must first set the parameters of the serial port communication, adjust the baud rate to 4800, and check the hexadecimal display. Select COM1 as the serial port. Of course, the serial port of the 51 single-chip microcomputer experiment board provided by the website must also be connected to the computer's COM1. Insert the single-chip microcomputer with the following program burned into the universal socket of the single-chip microcomputer experiment board, and turn on the power of the 51 single-chip microcomputer experiment board. At this time, just press K1 once, and an "AF" character will be added to the receiving area interface of the serial port debugging assistant software, indicating that the single-chip microcomputer successfully sent the "AF" character to the computer. The source program of the serial port experiment is as follows:

;This is a demonstration program for sending data AF from the AT89C51 microcontroller experimental development board to the serial port of a PC in one direction
; it uses the MAX232 dedicated chip for RS232/TTL level conversion.
;The communication baud rate is 4800KBPS. As long as K1 is pressed once (that is, the P3.6 pin becomes low level)
, ;a hexadecimal AF character will be sent.

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; Double the baud rate 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,$; Check if K1 is pressed, if not, wait
ACALL DELAY10; delay 10 milliseconds to eliminate contact jitter
JB P3.6,WRIT; remove interference signal
JNB P3.6,$; wait for the button to be released

MOV A,#0AFH; send the hexadecimal character AF to the serial port
MOV SBUF,A; send 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:The serial port of AT89C51 communicates with the serial port of the computer

Previous article:About embedding assembly in KEIL C51 and calling between C51 and A51
Next article:AT89C2051 internal structure and function

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

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

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号