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
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
- 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
- MSP430 Launchpad MSP430g2452 SHT10 Temperature and Humidity Sensor
- Establishment of RF chip/modem chip design team
- F28335 uses external SRAM for program simulation
- Looking for experts in Helmholtz coil magnetic field
- Do you know about the programmer and emulator of msp430?
- How to use the VGA_SYNC_N signal in the VGA of DE1-SOC?
- ATA-1000 Series Broadband Amplifier & ATA-2000 Series High Voltage Amplifier Series Comparison
- CCS Tips: Remove the prompt when burning DSP/BIOS
- SEED-DEC6416 is available for purchase, second-hand is also acceptable
- Calculation of stack usage in C2000 DSP