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
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
- Popular Resources
- Popular amplifiers
- 西门子S7-12001500 PLC SCL语言编程从入门到精通 (北岛李工)
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
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