How to program microcontroller principles and applications?

A microcontroller is a single-chip microcomputer that integrates the main components of a microcomputer on a single chip. The microcontroller was born in the mid-1970s. After 20 years of development, its cost is getting lower and its performance is getting more powerful, which makes it used in various fields and areas. Examples include motor control, barcode readers/scanners, consumer electronics, gaming devices, telephones, HVAC, building security and access control, industrial control and automation, and white goods (washing machines, microwave ovens). This article focuses on the applications and working principles of microcontrollers, including types of microcontrollers; the difference between microcontrollers and microprocessors; or the world's top microcontroller manufacturers.

According to Wiki, a microcontroller (or MCU for microcontroller unit) is a small computer located on a single integrated circuit. In modern terminology, it is similar to, but less complex than, a system-on-chip or SoC.A SoC may include a microcontroller as one of its components. A microcontroller contains one or more CPUs (processor cores) as well as memory and programmable input/output peripherals. Program memory in the form of ferroelectric RAM, NOR flash, or OTPROM is also usually included on the chip, as well as a small amount of RAM.In contrast to microprocessors used in personal computers or other general-purpose applications consisting of various discrete chips, microcontrollers are designed for embedded applications. Microcontrollers are used in automatically controlled products and devices such as automobile engine control systems, implantable medical devices, remote controls, office machines, equipment, power tools, toys and other embedded systems. By reducing size and cost, microcontrollers make it economical to digitally control more devices and processes than designs using separate microprocessors, memories, and input/output devices. Mixed-signal microcontrollers are common, integrating analog components needed to control non-digital electronic systems.

Microcontroller Functions

Microcontrollers have several major functions:

Analyzing the working principle, types and applications of microcontrollers

(1) Good reliability. As a result of the microcontroller's various functional components are integrated in the chip, especially the memory is integrated in the chip, the wiring is short, most of the data is transmitted within the chip, is not easy to external interference, enhanced anti-interference ability is strong, so that the system operates more reliably. Therefore, the reliability is obviously better than the general-purpose CPU system.

(2) Powerful control functions. In order to meet the requirements of industrial control, general-purpose microcontroller instruction system with a wealth of conditional branch transfer instructions, I/O port logic operations and bit processing functions. Usually, the logic control function and operation speed of microcontroller is higher than the same level of CPU.

(3) Easy to expand. There are many three buses and parallel and serial input/output pins for expansion, making it easy to form computer applications of various sizes.

(4) General-purpose microcontrollers do not have a monitoring program or system management software, the development of which requires a corresponding simulation system.

Types of microcontrollers

Microcontrollers can be divided into two main categories: general microcontrollers and digital signal processing microcontrollers (DSP).

Depending on the word length, the common microcontrollers today are 4 to 32. strong or weak functions for different occasions. Most of the world's largest semiconductor companies have their own microcontrollers.

Microcontroller 8051

It is a 40-pin microcontroller with Vcc of 5V connected to pin 40 and pin 20 of Vss is kept at 0V. and has input and output ports P1.0-P1.7 and has open-drain functionality. port3 has other functionalities. Pin 36 is in open-drain and pin 17 has an internal pull-up transistor inside the microcontroller. When a logic 1 is applied to port 1, a logic 1 is obtained on port 21 and vice versa. Programming of the microcontroller is very complex. Basically, we write a program in C and then convert it to a machine language that the microcontroller can understand.The RESET pin is connected to pin 9 which is connected to the capacitor.When the switch is on, the capacitor starts charging and RST is high. Applying a high level to the reset pin will reset the microcontroller. If we apply a logic zero to this pin, the program will be executed from the beginning.

Memory architecture of 8051

The memory of 8051 is divided into two parts: program memory and data memory. The program memory stores the program being executed, while the data memory temporarily stores data and results.The 8051 has been used in a variety of devices, mainly because of its ease of integration into devices. Microcontrollers are mainly used in energy management, touch screens, automotive and medical devices.

Data memory of 8051

Pin description of 8051 microcontroller

Pin 40: Vcc is the main power source of +5VDC.

Pin 20: Vss_ indicates a ground (0V) connection.

Pins 32-39: Known as Port 0 (P0.0 to P0.7) is used as an I/O port.

Pin-31: Address Latch Enable (ALE) is used to demultiplex the address data signal of port 0.

Pin-30: (EA) External access input is used to enable or disable the external memory interface. This pin is always held high if there is no external memory requirement.

Pin 29: Program Store Enable (PSEN) is used to read signals from external program memory.

Pins 21-28: Known as Port 2 (P2.0 to P2.7) _ In addition to being used as an I/O port, the high-order address bus signals are multiplexed with this quasi-bidirectional port.

Pins 18 and 19: Used to connect an external crystal to provide the system clock.

Pin 10_17: This port also has other functions, such as interrupts, timer inputs, control signals for external memory and read/write interfaces. This is a quasi-bidirectional port with an internal pull-up function.

Pin 9: This is a RESET pin that is used to set the 8051 microcontroller to its initial values when the microcontroller is working or when starting an application program boot. The RESET pin must be set high within two machine cycles.

Pin 1_8: This port does not have any other function. Port 1 is a quasi-bidirectional I/O port.

Microcontrollers are embedded inside the device to control the actions and functions of the product. Therefore, they can also be called embedded controllers. They run a specific program dedicated to a single task. They are low-power devices with dedicated input devices and small LED or LCD display outputs. Microcontrollers can take inputs from the devices they control and maintain control by sending device signals to different parts of the device. The microcontroller for a TV is a good example. It takes inputs from the remote control and outputs its outputs on the TV screen.

Like a traditional computer, a microcontroller relies on different functions to do its job. These functions include:

Memory

RAM is used to store data and other results created while the microcontroller is working. However, once power is removed from the microcontroller, it does not permanently store data and its memory is lost.The RAM contains a Special Function Register (SFR). This is a pre-configured memory provided by the microcontroller manufacturer. It controls the behavior of specific circuits such as serial communications and analog-to-digital converters.

Read-only memory

Special tasks that the microcontroller performs as a program are stored in ROM (Read-Only Memory) forever.ROM lets the microcontroller know that certain actions should trigger a specific response. For example, the ROM lets the microcontroller in a TV know that pressing a channel button will change the display on the screen.The size of the program stored in the ROM depends on the size of the ROM. Some microcontrollers accept the addition of ROM in the form of an external chip, while others come with built-in ROM.

Program counter

A program counter allows a minicomputer to execute a program based on a series of different programming instructions. Every time a line of instruction is executed, the program counter is incremented by 1. This helps to keep track of the counter's position within the line of code.

Inputs and outputs

Unlike computers that are controlled by a mouse or keyboard, microcontrollers have a unique way of interacting with people through inputs and outputs. Typical input and output devices on a microcontroller include LED displays, switches and sensors that determine humidity, temperature and light levels. Most embedded systems do not have a screen or keyboard for direct human-computer interaction. Instead, microcontrollers have multiple input and output pins or GPIOs that are configured for different input and output devices.

For example, you can configure one pin as an input on a microcontroller that operates by sensing temperature, while another pin is configured as an output and connected to a thermostat that triggers an air conditioner or heater to turn on and off based on a preset Setting the temperature range. The input and output dynamics are completely machine-to-machine, and no direct human interaction is required to make decisions.