51 MCU serial port expansion method

Publisher:TapirLatest update time:2018-05-07 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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:


51 MCU serial port expansion method - Non-famous blogger - Electronic Information Corner


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:


51 MCU serial port expansion method - Non-famous blogger - Electronic Information Corner


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' to the virtual terminal.


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.


Reference address:51 MCU serial port expansion method

Previous article:51 MCU P0 port
Next article:51 MCU expansion external interrupt

Recommended ReadingLatest update time:2024-11-23 07:55

Motor speed measurement and control program based on 8051 single chip microcomputer
With the single-chip microcomputer 8031 ​​as the core, the 8279 chip is used to realize key input and the digital tube is used to display the measured speed. The input voltage analog quantity is converted into digital quantity by ADC0809 (the relevant interface has been connected inside the experimental box) to contro
[Microcontroller]
51 single chip microcomputer - digital tube, button, matrix button C language entry programming
Digital Tube:         Digital tubes can be divided into seven-segment digital tubes and eight-segment digital tubes according to the number of segments. Eight-segment digital tubes have an additional DP (decimal point) diode. They can also be divided into common anode digital tubes (lit at low level) and common cathod
[Microcontroller]
51 single chip microcomputer - digital tube, button, matrix button C language entry programming
Touch screen chip ADS7846/ADS7843 driver (C51)
/* Touch.c 8051 MCU drives ADS7846/ADS7843 chip ADS7846/7843 chip is suitable for 4-wire touch screen. It communicates with CPU through standard SPI protocol. It is simple to operate and has high precision. When the touch screen is pressed (i.e. a touch event occurs), ADS7846 sends an interrupt reques
[Microcontroller]
External interrupt C51 program
When there is no interrupt, it is displayed as a running light. External interrupt 0 makes the left and right 4 LEDs flash alternately, and external interrupt 1 makes the LEDs flash. #include reg51.h unsigned char code design ={0xff,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0x00}; void Delay(unsigned int i){        uns
[Microcontroller]
89c51 8-bit LED dynamic scanning clock program
89c51 8-bit LED dynamic scanning clock program //Use 12MHz crystal oscillator, P0 port output segment code, P2 port for column scan, use common anode LED digital tube  //  #include "reg51.h"  code char dis_7 ={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xff};  /* Common anode LED segment code table "0" "1" "2"
[Microcontroller]
80C51 microcontroller drives UZZ9001 read and write operations by simulating SPI port
#include    #include absacc.h #include intrins.h #include math.h sbit CS = P2^0; sbit CLK = P2^1; sbit DATA= P2^2; /*Macro definition of 8155 port A, port B and control port*/ #define PA8155 XBYTE #define PB8155 XBYTE #define COM8155 XBYTE // Display code for ; unsigned char code Table ={0X0FC,
[Microcontroller]
51 microcontroller drive control design for LCD1602 liquid crystal display
The serial A/D converter TLC549 is used to collect the input signal voltage source and convert it into a digital signal for the 51 microcontroller. After data processing by the microcontroller, it is sent to the 1602 liquid crystal display. The error is less than 1%. #include #include #define uint unsigned int #defi
[Microcontroller]
51 microcontroller drive control design for LCD1602 liquid crystal display
Design of Metronome Based on AT89C51 Single Chip Microcomputer
1 Hardware Circuit Principle The metronome uses the AT89C51 single-chip microcomputer as the control center, and is composed of an LED display module, an adjustment keyboard module, and a sound output module. Figure 1 is the circuit schematic diagram of the metronome. The AT89C51 single-chip microcomputer produ
[Microcontroller]
Design of Metronome Based on AT89C51 Single Chip Microcomputer
Latest Microcontroller Articles
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号