Programming method and application of single chip microcomputer serial interface

Publisher:月光男孩Latest update time:2015-03-23 Source: diangonKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Serial communication is widely used in single-chip microcomputer systems and modern single-chip microcomputer measurement and control systems. This article mainly studies the programming methods of serial interfaces and understands the commonly used serial communication applications. We should first master the basic knowledge of serial ports, including the characteristics of each working mode and the receiving and sending logic, and master the setting methods of serial port control registers. On this basis, we can understand the basic methods of serial port programming by studying the examples in this article.
1. Typical applications of serial communication

Communication between the MCU and the PC. For example, the data collected by the MCU measurement and control system is sent to the host computer through the RS-232 interface. As shown in Figures 1 and 2. Usually, auxiliary software is required, such as Figure 3 serial port debugging assistant and Figure 4 host computer communication software.

 


Figure 1 MCU serial port connection

Figure 2 Communication between MCU and PC

Figure 3 Serial port debugging assistant

Figure 4 Host computer communication software
2. Example of serial interface programming method

Example 1: Use serial port working mode 0 to expand an 8-bit parallel I/O port, where 74LS164 is a serial-input-parallel-output chip that drives the common-anode LED digital tube to display 0~9.

Answer: The basic principle of expansion is shown in Figure 5


Figure 5: Serial port mode 0 expansion

 

The encoding principle is shown in Figure 6.


Figure 6 LED coding principle diagram

The subroutine to display the numbers 0-9 is shown below.

DSPLY:MOV   DPTR, #TABLE

      MOVC A, @A+DPTR

      MOV SBUF, A

      JNB TI, $

      CLR IT

      RIGHT

TABLE:DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H;Digital codes from 0 to 9

Example 2: Dual-machine communication. As shown in Figure 7, connect two CS-III microcontroller experiment boards, set the baud rate to 9600, connect the TXD and RXD ports of the transmitter and receiver, connect the TXD port of the transmitter to the RXD port of the receiver, and the RXD port of the receiver to the TXD port of the transmitter, and connect the ground terminals of the two machines.


Figure 7 Schematic diagram of two-machine communication

Answer: Serial communication applications generally require the correct setting of the serial port working mode, calculation of the baud rate, initialization of the baud rate setting and serial port initialization, as well as related register settings. The serial communication flow chart is shown in Figure 8.


Figure 8 Two-machine communication flow chart

Keywords:MCU Reference address:Programming method and application of single chip microcomputer serial interface

Previous article:System expansion of single chip microcomputer
Next article:MCU serial interface working mode

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

A brief analysis of the main factors that determine the performance and power consumption of ARM core MCUs
After ARM launched the Cortex-M0+ core, its 32-bit MCU cores increased to 4. Not long ago, NXP also announced that it had obtained the Cortex-M0+ processor license, becoming the only semiconductor manufacturer that can provide a complete series of Cortex-M0, Cortex-M0+, Cortex-M3 and Cortex-M4 core MCUs . Freescale al
[Power Management]
STC15F2 series MCU UART1 uses timer 1 as baud rate generator
#include reg51.h #include "main.h" #include "intrins.h" //Use T2 timer 2 to control the baud rate of serial port 1 #define FOSC 18432000L //System frequency #define BAUD 9600 //Serial port 1 baud rate #define TM2 (65536-(FOSC/4/BAUD)) #define NONE_PARITY 0 //No parity #define ODD_PARITY 1 //Odd parity #define E
[Microcontroller]
Microcontroller buzzer control program and drive circuit
Buzzers are divided into piezoelectric buzzers and electromagnetic buzzers based on their structure. Piezoelectric buzzers use piezoelectric ceramics to make sounds, and the current is relatively small. Electromagnetic buzzers use coils to vibrate and make sounds, and their size is relatively small. According to the
[Microcontroller]
Microcontroller buzzer control program and drive circuit
51 MCU--External interrupt 1 controls the LED on and off
#include "reg51.h"   typedef unsigned int u16;    typedef unsigned char u8;   sbit k4=P3^3; //P33 is the pin of external interrupt 1, one pin of the button is connected to the interrupt pin sbit led1=P2^1; /*********************************************************************************** * Function name: delay * F
[Microcontroller]
High level reset and low level reset of microcontroller
There are two types of microcontroller reset circuits: low-level reset and high-level reset. 1. High level reset: Schematic diagram Principle: At the moment of power-on, if the capacitor is not charged, it is considered a short circuit. At this time, the Reset port voltage is 5V. The capacitor is charged to 0.7 time
[Microcontroller]
High level reset and low level reset of microcontroller
51 single chip independent button k1 controls the digital tube shift k2 controls the value addition
Press the independent button K1 to move the digital tube to the left, and press the independent button K2 to increase the value of the digital tube by 1. typedef unsigned char u8; u8 code smgwei ={0x00,0x04,0x08,0x0c,0x10,0x14,0x18,0x1c}; u8 code smgduan ={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; sbit key
[Microcontroller]
8051 MCU Basics 2: Core and Memory (RAM, Flash) Architecture
References: ① Keil Help ② "STC MCU Principles and Applications - Analysis and Design from Devices, Assembly, C to Operating Systems" by He Bin ③MCS-51 Series Microcontrollers and Their Applications (6th Edition) by Sun Yucai and Sun Huafang The 8051 microcontroller architecture mainly includes: CPU (computing uni
[Microcontroller]
8051 MCU Basics 2: Core and Memory (RAM, Flash) Architecture
Design of wireless controller based on MC9S08QG8 low-end microcontroller
Wireless communication is part of people's daily life. In offices, schools or homes, we are exposed to wireless communication devices such as laptops, printers, cameras, handheld devices, LED lighting, etc. Controllers and home appliances, etc. The complexity of these devices is related to the types of tasks they
[Analog Electronics]
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号