Many of us have heard of the terms microcontroller and microprocessor. For those who work with electronics, microcontrollers are a fascinating subject.
However, many of us believe that microcontrollers are only used to create robots and microprocessors are only used to build computers, and that it is nearly impossible to do these things in Bangladesh. As a result, they do not even consider working with microcontrollers and microprocessors.
But the advancements in digital control systems or automatic control systems today owe a great deal to microcontrollers and microprocessors. Therefore, we need to work more on controlling systems.
Table of Contents
What is a Microcontroller?
A microcontroller is a combination of two English words: “micro” and “controller.” In Bengali, “micro” means small, and “controller” means to control. Therefore, it can be understood as a small device that controls.
It can actually be called a small computer. It includes a processor, RAM, memory, input/output ports all in one place.
μC stands for microcontroller, and MCU stands for Microcontroller Unit.
What is the Function of a Microcontroller?
In simple terms, its function is to perform specific tasks following specific rules. By specific rules, we mean programming. The microcontroller will output exactly as we instruct it through programming. It is also called a programmable device. You can program it as many times as you like.
A microcontroller primarily converts analog tasks into digital ones. So what are analog tasks? Analog tasks refer to those performed by various ICs, transistors, diodes, and other devices. A microcontroller can perform all these tasks together through digital signals (0,1).
Suppose we want to build a 7-segment clock. For this, we would need a 7-segment driver IC, a time counter circuit, a time-setting circuit, etc. The interesting thing is that we can easily accomplish this task with just a microcontroller.
Types of Microcontrollers
Based on Processing Word Size
- 4-bit Microcontroller
- 8-bit Microcontroller
- 16-bit Microcontroller
- 32-bit Microcontroller
Based on Instruction Set
- RISC Microcontroller
- CISC Microcontroller
Based on Memory Connection
- Internal Memory Microcontroller
- External Memory Microcontroller
Based on Microcontroller Memory Architecture
- Harvard Architecture Microcontroller
- Von-Neumann Architecture Microcontroller
What is a Microprocessor?
A microprocessor is essentially a digital integrated circuit (IC) that typically receives data and instructions through an input bus, processes the data according to the instructions, generates a result, and sends that result to the output device through an output bus.
It generates various control signals to control input/output devices. The logical and arithmetic operations of a computer are performed by the microprocessor. The microprocessor is an important part of a computer system that functions as the Central Processing Unit (CPU). For example: Intel 8085, MC 68000, Z80 are some popular microprocessors.
Difference Between Microcontroller and Microprocessor
- A microcontroller is essentially a single-chip computer that includes a processor, RAM, ROM, input/output ports, etc. On the other hand, a microprocessor is an integrated circuit that functions as the Central Processing Unit (CPU) in a computer. For this reason, it is sometimes referred to as a CPU.
- Examples of microcontrollers include Intel 8051, Atmel ATmega16, etc. Examples of microprocessors include Intel x86 family microprocessors like 8086, 80816, 80286, 80386, etc.
- A microcontroller contains a complete processor inside it, such as RAM, ROM, I/O Port, etc. A microprocessor contains parts like ALU, General Purpose register, Accumulator, Program Counter, Flag register, Data and Counter Bus, etc.
Brief Discussion on Microcontroller Structure
The basic components that make up a microcontroller are shown in the diagram below. Different manufacturers design microcontrollers in different ways. We will now look at the structural framework of a simple and basic microcontroller.
CPU
CPU stands for Central Processing Unit, which is primarily made up of ALU, Accumulator, Control Unit, Flag, Stack Pointer, and some General-purpose registers. The logical tasks of the microcontroller are performed in the ALU of the CPU.
Instructions from RAM are transferred to the Instruction Register. Assembly language instructions are translated into machine language, and the necessary logical tasks are completed in the ALU. Finally, the results are sent to memory, i.e., the Output Register.
Memory:
Semiconductor memory is used internally in the microcontroller, where RAM and ROM are present. RAM is temporary memory that is erased when the power supply is turned off, while data in ROM is stored permanently.
Input/Output Ports
The microcontroller receives signals from various sensors as input, and the microcontroller’s output can be connected to devices like LCD displays, seven-segment displays, stepper motors, sensors, etc.
The ports through which these signals are received and sent are called input/output ports. These ports are one or more registers in the microcontroller, whose bits are logically connected to the external pins of the microcontroller. Users can set these ports as input or output through programming.
Ports are of two types:
1. Serial Port: Used for serial data communication
2. Parallel Port: Used for parallel data communication
Timer and Counter
Most microcontrollers have one or, in some cases, more than one timer/counter. It mainly calculates time, measures delays, etc. Its primary function is to measure frequency and clock functions. It is mainly an 8-bit or 16-bit register.
Digital to Analog Converter
It converts digital signals to analog signals and controls various analog devices.
Analog to Digital Converter
Analog signals from various analog sensors and devices enter the microcontroller. However, we know that the CPU of a microcontroller cannot read analog data. Therefore, these signals need to be converted into digital signals. This is what the converter does.
Interrupt Controller:
During the execution of a program, when the normal flow of the program is interrupted to perform another task, this is called an interrupt. After completing the task, the processor returns to the main program. This is essentially the function of an interrupt controller.
Watchdog Timer:
The watchdog timer is used for the complex security system and various important aspects of the microcontroller. When a microcontroller experiences an error during operation, causing the program or hardware to malfunction, the watchdog timer continuously monitors this situation and automatically resets and restarts the system if any issue is detected.
What to Consider When Buying a Microcontroller?
- Processor Word Size: The ALU of a microcontroller can process a single instruction’s logical and arithmetic operations based on the bit size, known as the microcontroller’s word size. Microcontrollers with word sizes of 4, 8, 16, and 32 bits are available in the market. You should choose a microcontroller with an appropriate clock frequency according to your needs.
- Operating Speed: The microcontroller should be selected based on the system’s required clock frequency.
- Consider the required amount of RAM and ROM when selecting a microcontroller.
- Choose a microcontroller based on the input-output pins and timers.
Some Popular Microcontroller Brands and Their Introductions
- Microchip PIC/dsPIC.
- Arduino (built with AVR).
- Atmel (AVR/ARM).
- Toshiba/Samsung/Intel, etc.
There are many other brands as well.
Microchip PIC
PIC16F series includes models like 16F877, 16F72, 16F628, 16F676, and many others. Additionally, there are the PIC18F, PIC24F, and PIC32F series. Although they are different from each other, they are not entirely dissimilar. The 16F877A model is the most widely used.
Each microcontroller has its own features. We need to select them based on the type of work.
What Programming Languages Are Used for Microcontrollers?
There are many types of programming languages for microcontrollers. However, it is recommended to learn Programming in C. C is often referred to as the “mother” of programming languages. Many programmers start their journey with C language. The best compiler for Microchip is Micropro PIC, which is primarily used to compile programs.
Microcontroller Programming Write or Burn Method
After correctly writing the program or code in C programming software, it needs to be loaded into the microcontroller. A device called PIC Programmer/PIC Burner is required to load the program. It must be installed on the computer. You can find the software by searching online.
Some General Discussion on PIC 16F877A
Input/Output = RA, RB, RC, RD, RE (0 to N)
AN(O to N) = Analog to Digital ADC pin
SDA, SCL = I2C protocol.
TX, RX = USART protocol.
PSP(O to N) = PSP protocol.
INT(O to N) = External interrupt.
PGC, PGD, PGM = Program Load Pin.
CCP = Capture/Compare/PWM
OSC1, OSC2 = Crystal.