The basic 51 microcontroller has four parallel ports, which also includes a serial port.
When there are not enough interfaces, people will think of using external chips for expansion.
However, although various textbooks, reference books, and online articles introduce many ways to expand the parallel port, almost no one is interested in methods to expand the serial port.
Occasionally I see one that is also expanded using "giant" chips such as 8250 and 8251.
Using these chips will occupy many of the more scarce parallel ports of the microcontroller, which is basically not worth the cost, not to mention the need to set complex control words.
By using a simple three-state gate, you can expand the serial port for the microcontroller, and only occupy one or two pins of the microcontroller as control leads.
This method has never been seen in various books, magazines, or online articles before. It can be said to be an original creation.
Haha, I'm just a little proud, please don't criticize me.
In fact, it is very simple, just like using 74LS373 or 74LS244 to expand the parallel port, just add the appropriate three-state gate to the serial port.
You can choose 74LS125 (low level opens the door) or 74LS126 (high level opens the door).
It is also possible to use other chips with three-state outputs, such as: 74LS244, 74LS373, etc.
It’s just that the control lines of these chips are controlled in groups, rather than individually one door at a time, which makes it a bit inconvenient.
The following is the circuit diagram of expanding two serial port channels designed by Erlundao:
Image link: http://xiangce.baidu.com/picture/detail/64e03b5b7608f83bacba4eb956749736c1c3430d
In order to simplify the control and make the introduction more comprehensive, two types of three-state gates are used in the figure. It is also possible to use the same one.
Both groups of three-state gates use P3.4 as the control signal.
When P3.4 outputs a high level, 74LS126 opens, channel 1 is turned on, and the microcontroller can serially output 74LS164 to drive the digital tube;
When P3.4 outputs a low level, 74LS125 opens, channel 2 is turned on, and the microcontroller can communicate with other serial port devices in full-duplex.
If necessary, you can also connect a TTL-RS232 level conversion chip (or RS485 bus chip) to the right of 125 for long-distance communication.
The picture shows a virtual terminal connected to PROTEUS software, which is used to represent another serial communication device.
I wrote a short program in assembly language to control the serial port expansion circuit to work.
;==================================================
ORG 0000H
SJMP START
ORG 0023H
AJMP S_INT
START:
MOV TMOD, #20H
MOV TH1, #0FDH ; Set the baud rate to 9600@11.0592MHz
MOV TL1, #0FDH
SETB TR1
MOV IE, #90H ; Open serial port interrupt
CLR P3.4 ; select 74LS125 (channel 2)
MOV SCON, #50H; serial port mode 1, can receive
SJMP$
;----------------------------------
S_INT: ;Serial port interrupt program
JNB RI, S_END
CLR RI
MOV A, SBUF; take out the received data
;---------------------
SETB P3.4 ; select 74LS126 (channel 1)
MOV SCON, #0 ;Serial communication mode 0
MOV B, #16
DIV AB
XCH A, B
ADD A, #(TAB - $ - 3)
MOVC A, @A + PC; Get seven-segment code
MOV SBUF, A ;Serial port output
JNB TI, $ ; Wait for sending to complete
CLR TI
MOV A, B
ADD A, #(TAB - $ - 3)
MOVC A, @A + PC
MOV SBUF, A
JNB TI, $
CLR TI
;---------------------
CLR P3.4 ; select 74LS125 (channel 2)
MOV SCON, #50H; serial port mode 1, can receive
MOV SBUF, #'O'
JNB TI, $
CLR TI
MOV SBUF, #'K'
JNB TI, $
CLR TI
MOV SBUF, #13 ;
JNB TI, $
CLR TI
MOV SBUF, #10 ;
JNB TI, $
CLR TI
;---------------------
S_END:
RETI
TAB: ; Common positive segment code table
DB 0C0H, 0F9H, 0A4H, 0B0H, 099H, 092H, 082H, 0F8H;0~7
DB 080H, 090H, 088H, 083H, 0C6H, 0A1H, 086H, 08EH;8~F
END
;==================================================
After the program is executed, the screenshot is as follows:
Image link: http://xiangce.baidu.com/picture/detail/e59dd034244a30296b66430ce57b73137ef91a4d
Under program control, the 51 MCU monitors channel 2 at any time. Once the virtual terminal sends a byte of serial data, the MCU will send back 'OK'
At this time, it is a duplex serial communication between the microcontroller and the host computer.
Then, the microcontroller turns to serial port channel 1 and outputs two groups of seven-segment codes in mode 0, so that the external 74LS164 displays the high and low four bits of the data just received.
At this time, it is a simple SPI communication method.
As can be seen in the figure, the digital tube displays 41, which is the phenomenon when typing 'A' in the virtual terminal window. 41 is the ASCII code of the character A.
The virtual terminal does not display the typed content, it only displays the information sent by the microcontroller. In the figure, you can see the displayed OK, Enter, and Line Feed.
Both 74LS125 and 74LS126 are 14-pin integrated chips, which are much smaller than 40-pin dedicated serial port chips such as 8250 and 16550A.
Each chip (125 or 126) contains four independently working three-state gates. In fact, using one chip 125 or 126 can also realize the above two-channel serial communication.
Note: If one chip is used, the level signals of channel control are the same, which requires using two pins of the microcontroller to control the two channels separately.
It is also feasible to use more three-state gates to expand the microcontroller's serial ports.
The serial port expansion solution, hardware circuit and software designed by Zuoerlundao have been tested in actual circuits and can communicate normally.
Previous article:51 MCU P0 port
Next article:51 MCU expansion external interrupt
Recommended ReadingLatest update time:2024-11-23 07:55
- Popular Resources
- Popular amplifiers
- Siemens PLC Programming Technology and Application Cases (Edited by Liu Zhenquan, Wang Hanzhi, Yang Kun, etc.)
- 西门子S7-12001500 PLC SCL语言编程从入门到精通 (北岛李工)
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- Implementing a Deep Learning Framework with Python (Zhang Juefei, Chen Zhen)
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- PCB design (layout, layout, routing) specifications for switching power supplies
- Qualcomm wins injunction, Chinese court bans sale of several iPhones
- RF microwave - Qorvo has a good interpretation of this material [gallium arsenide and gallium nitride]
- Looking for a sound amplification circuit
- [Flower carving hands-on] Interesting and fun music visualization series of small projects (26) - LED hypercube
- The domestic Gaoyun FPGA GWIN-4B development board cannot use the MSPI pin. Please help
- Shanghai is a cold and indifferent society now,,,,,I don't want to say more
- sp485 communication reception is 0x00
- Xunwei 4412 development board Qt network programming-UDP implementation of server and client
- AD Wiring "hitting a wall"! ? ?