Basic knowledge of peripheral circuit control of single chip microcomputer

In "embedded programming of the basic structure of the microcontroller, working principle" , "embedded peripheral circuit of embedded programming microcontroller" and "single-chip programming language and development environment" , we learned the hardware and programming language of the microcontroller and the development environment Wait. This article will take you through the basics of peripheral circuit control of the microcontroller.

(SFR) Special FuncTIon Registers

The MCU has the same function as the box. We call it a register to temporarily store data. The types of registers include program counters, general-purpose registers, and SFRs (Special Function Registers).

SFR is mainly used to set the working mode of peripheral function circuits (counter or serial port, general-purpose I/O, etc.), confirm its working status, and control it. In other words, SFR is not just a "box" for saving data. By changing the data stored in the "box", not only can the peripheral function circuit be changed, but the data in the "box" will also change with the working state of the peripheral function circuit.

Basic knowledge of controlling peripheral function circuits

The following takes general-purpose I/O as an example to illustrate the control of the peripheral function circuit of the single-chip microcomputer. General purpose I/O has the following features:

Output function: can output high level voltage or low level voltage

Input function: can read the voltage level input to the pin

First look at the control of the output function. Pin A in Figure 1 is a general purpose I/O.

If register to pin A (SFR)

Writing a 0 will cause the output voltage of pin A to be low (0V).

Writing a 1 will cause the output voltage of pin A to be high (5V).

Figure 1: Output function of general purpose I/O

Figure 1: Output function of general purpose I/O

If pin A of Figure 1 is connected to an LED, a circuit that controls the LED can be constructed (see Figure 2). At this time, when 0 is written to the register (SFR), the LED is turned on, and when 1 is input, the LED is turned off. Although this is a very simple action, it reflects the basic principle of the microcontroller to control various peripheral functional circuits. With this function, it is possible to perform the same switching function as the ON/OFF of the motor (since the normal current cannot be passed through the driving circuit of the single-chip microcomputer, a motor driving circuit made of a FET or a transistor must be separately prepared). In addition, more complex controls can be accomplished if multiple general purpose I/O ports are used.

Figure 2: LED control circuit for general purpose I/O

Figure 2: LED control circuit for general purpose I/O

Next, look at the input function (Figure 3).

If a low level voltage (0V) is input to pin A, 0 is read from the register (SFR).

If a high level voltage (5V) is input to pin A, a 1 is read from the register (SFR).

That is, by reading the value of the register (SFR), it can be judged whether the external voltage is a low level voltage or a high level voltage.

Figure 3: Input function of general purpose I/O

Figure 3: Input function of general purpose I/O

Junction Boxes

Cable Box,Junction Boxes,Cable Connection Box,Waterproof Cable Box

Jiangmen Krealux Electrical Appliances Co.,Ltd. , https://www.krealux-online.com