Sunday, March 16, 2025

Instruction sets of a microcontroller

 

Instruction sets of a microcontroller


Instruction Set: 

The set of instructions that needs to be executed by a processor in a microcontroller, which defines the fundamental operation of what can be done with this microcontroller. These instructions provide direction to the microcontroller and help it execute functions like data processing, comparison of data/actions, shifting from one part of a program to another, multiplication of registers allocated with data. And they are super powerful and flexible because ARM microcontrollers do process with the data in their registers using its instruction set.

What is Instruction Set?

A microcontroller consists of a processor with an instruction set, these are just machine-level instructions that when processed have a direct effect on the microcontroller. This is what makes these instructions the building blocks in writing software that interacts with hardware, and are important for embedded systems. ARM architecture, as an example, has a huge list of instructions like arithmetic, logical, comparison and so on commands which help in performing intelligence operations over the data.




✅ Categories of Instructions:

  1. Data Transfer Instructions
  2. Arithmetic Instructions
  3. Logical Instructions
  4. Branching (Control Transfer) Instructions
  5. Bit Manipulation Instructions

 Most of the data processing instructions use a barrel shifter to pre-process the data of one of their operands. Each operation updates different flags in the cpsr (To learn more about ‘CPSR’ search “CPSR in ARM”). 

Let us discuss the instructions in detail.

🧠 8051 Microcontroller Instruction Set Overview

The 8051 Microcontroller supports a rich set of instructions, broadly divided into:

✅ Categories of Instructions:

  1. Data Transfer Instructions
  2. Arithmetic Instructions
  3. Logical Instructions
  4. Branching (Control Transfer) Instructions
  5. Bit Manipulation Instructions

1️⃣ Data Transfer Instructions

Used to move data between registers, memory, and external devices.

Instruction Description Example
MOV A, #data Move immediate data to accumulator   MOV A, #25H → A = 25H
MOV A, R0 Move register data to A MOV A, R0
MOV R1, A Move accumulator to register MOV R1, A
MOV A, @R0 Move indirect RAM to A MOV A, @R0 (R0 = 40H ⇒ A = RAM[40H])
MOV DPTR, #data16 Load 16-bit data to DPTR MOV DPTR, #1234H
MOVC A, @A+DPTR Read code memory Used in lookup tables

2️⃣ Arithmetic Instructions

Instruction Description Example
ADD A, R0 Add register to A ADD A, R0
ADD A, #data Add immediate data to A ADD A, #0AH
ADDC A, R1 Add with carry ADDC A, R1
SUBB A, R2 Subtract with borrow SUBB A, R2
INC A Increment A INC A (A = A + 1)
DEC R1 Decrement register DEC R1
MUL AB Multiply A & B A = low byte, B = high byte
DIV AB Divide A by B A = quotient, B = remainder

🔍 Example:

MOV A, #20H
MOV B, #04H
DIV AB ; A = 05H, B = 00H

3️⃣ Logical Instructions

Instruction Description Example
ANL A, R1 Logical AND ANL A, R1
ORL A, #data Logical OR with immediate ORL A, #0F0H
XRL A, R2 Exclusive-OR XRL A, R2
CLR A Clear A (A = 0) CLR A
CPL A Complement A CPL A
RL A Rotate left RL A
RR A Rotate right RR A
SWAP A Swap nibbles High <-> Low nibble

4️⃣ Branching Instructions

Instruction Description Example
SJMP label Short jump (within 128 bytes) SJMP LOOP
LJMP addr Long jump (within 64K) LJMP 3000H
AJMP addr Absolute jump AJMP 2000H
JZ label Jump if A == 0 JZ ZERO
JNZ label Jump if A ≠ 0 JNZ AGAIN
CJNE A, #data, label Compare and jump if not equal CJNE A, #25H, NEXT
DJNZ R0, label Decrement and jump if not zero DJNZ R0, LOOP
CALL addr Call subroutine LCALL SUB1
RET Return from subroutine RET
RETI Return from interrupt RETI

5️⃣ Bit Manipulation Instructions

Instruction Description Example
SETB bit Set bit to 1 SETB P1.0
CLR bit Clear bit CLR P1.1
CPL bit Complement bit CPL P1.2
ANL C, bit AND carry with bit ANL C, P1.3
ORL C, bit OR carry with bit ORL C, P1.4
MOV C, bit Move bit to carry MOV C, P1.5
MOV bit, C Move carry to bit MOV P1.6, C

🔁 Sample Program – LED Blink using P1.0

ORG 0000H
START:
    SETB P1.0    ; Turn ON LED
    ACALL DELAY
    CLR P1.0     ; Turn OFF LED
    ACALL DELAY
    SJMP START   ; Repeat forever

DELAY:
    MOV R1, #200
L1: MOV R2, #200
L2: DJNZ R2, L2
    DJNZ R1, L1
    RET
END

📌 Notes:

  • The 8051 has 128 opcodes, each 1 to 3 bytes long.
  • Instructions are executed with respect to clock cycles (machine cycles).
  • Common tools to simulate: Keil uVision, Proteus, MIDE-51, etc.


 Comparison Instructions –

These instructions are used to compare or test a register with a 32-bit value. They update the cpsr flag bits according to the result, but do not affect other registers. After the bits have been set, the information can then be used to change program flow by using conditional execution.

Syntax – <instruction>{<cond>} Rn, N

CMNcompare negatedflags set as a result of Rn + N
CMPcompareflags set as a result of Rn – N
TEQtest for quality of two 32 – bit valuesflags set as a result of Rn ^ N
TSTtest bits of a 32-bit valueflags set as a result of Rn & N
 N is the result of the shifter operation. 

Example –

PRE 
          cpsr = nzcvqift_USER     
          r0 = 4   ; register to be compared
          r9 = 4  ; register to be compared
          CMP r0, r9

 POST 
cpsr = nzcvqift_USER   output generated after comparison

5. Move Instructions –

Move is the simplest ARM instruction. It copies N into a destination register Rd, where N is a register or immediate value. This instruction is useful for setting initial values and transferring data between registers.

Syntax – <instruction>{<cond>}{S} Rd, N

MOVMove a 32-bit value into a registerRd = N
MVNmove the NOT of the 32-bit value into a registerRd = ~N

Example – 
PRE
          r5 = 5    ; register value 
          r7 = 8    ; register value
          MOV  r7, r5  ;let r7 = r5

POST 
          r5 = 5       ; data in the register after moving the r5 data into r7
          r7 = 5       ; output after  move operation

Barrel Shifter

It is a device to shift a word with variable amount. It is one of the logic devices used to pre-process one of the operand/register before operating on to the ALU operations. And it is one of the best features of ARM.

Barrel Shifter

MnemonicsDescriptionShiftResultShift amount
LSLlogical shift leftxLSLyx<<y#0-31 or Rs
LSRlogical shift rightxLSRy(unsigned) x>>y#1-32 or Rs
ASRarithmetic right shiftxASRy(signed) x>>y#1-32 or Rs
RORrotate rightxRORy((unsigned) x>>y) | (x<<(32 – y)#1-31 or Rs
RRXrotate right extendedxRRX(c flag << 31) | ((unsigned) x>>1)none
x represents the register being shifted and y represent the shift amount
N shift operationsSyntax
Immediate#immediate
RegisterRm
Logical shift left by immediateRm, LSL #shift_imm
Logical shift left by registerRm, LSL Rs
Logical shift right by immediateRm, LSR #shift_imm
Logical shift right by registerRm, LSR  Rs
Arithmetic shift right by immediate Rm, ASR #shift_imm
Arithmetic shift right by registerRm, ASR Rs
Rotate right by immediateRm, ROR #shift_imm
Rotate right by registerRm, ROR Rs
rotate right with extendRm, RRX

Example –

  • This example of a  MOVS instruction shifts register r1 left by one bit.
  • This multiplies register r1 by a value 21

PRE
          cpsr = nzcvqiFt_USER
          r0 = 0x00000000
          r1 = 0x80000004
          MOVS   r0, r1, LSL #1

POST 
          cpsr = nzCvqiFt_USER
          r0 = 0x00000008
          r1 = 0x80000004

  • The C flag is updated in the CPSR because the S suffix is present in the instruction mnemonics.

Advantages of Instruction sets of a microcontroller

  • Efficiency: An architectures such as that of ARM uses Reduced instruction sets (RISC) that facilitates fast and efficient operations.
  • Low Power Consumption: Power consumption is typically very important in embedded systems and therefore the system has been designed with optimum power use in mind.
  • Versatility: Different forms of instructions are possible to accomplish a number of operations.

Disadvantages of Instruction sets of a microcontroller

  • Limited Flexibility: Some micro operations involve many instructions as the level of operation becomes high hence more complex.
  • Hardware Dependent: The various microcontroller families around have their individual instruction sets something that makes them incompatible.

"This Content Sponsored by Buymote Shopping app

BuyMote E-Shopping Application is One of the Online Shopping App

Now Available on Play Store & App Store (Buymote E-Shopping)

Click Below Link and Install Application: https://buymote.shop/links/0f5993744a9213079a6b53e8

Sponsor Content: #buymote #buymoteeshopping #buymoteonline #buymoteshopping #buymoteapplication" 

Monday, March 10, 2025

8051 Microcontroller Architecture

 For many years, the 8051 microcontroller architecture is vital and important component in embedded systems design due to its common use. 

Its strong architecture and multiple uses in a variety of industries from consumer electronics to industrial automation are the main causes of its appeal.

What is 8051 Microcontroller?


An 8051 microcontroller is an 8-bit Harvard architecture microcontroller and it consists of a CPU, RAM, ROM, I/O ports, timers, and serial communication ports all combined on one chip.

 It can control simple to highly complex operations in embedded systems since it can carry out instructions which are retrieved from its internal memory.

Types or Classification


The 8051 microcontroller family consists of several variations, including the original 8051, the 8031 (which has less functionality), and the upgraded 8052. Each variant offers a different peripheral configuration and memory size to meet the needs of a particular application.





Explanation

A microcontroller uses all the functions of a microprocessor into a single integrated circuit, acting as a miniature computer. It depends extensively on on-chip features including RAM, ROM, I/O ports, timers, serial ports, clock circuits, and interrupts to support a variety of applications. Microcontrollers find application in a wide range of automatically operated gadgets, including power tools, toys, office equipment, medical equipment, remote controls, car engine control systems, and other embedded systems.

The microcontroller has all of these peripherals built in, but the microprocessor requires us to interface extra circuitry outside for things like RAM, ROM, I/O ports, timers, serial ports, clock circuits, and other peripherals. Allow us to briefly examine the 8051 microcontroller pin diagram.

Working Principle

The microcontroller retrieves, decodes, and sequentially executes instructions from memory. It can carry out operations according to preprogrammed logic by interacting with external devices via I/O ports and timers.

Components

The internal basic components of the architecture of the 8051 microcontroller are:

CPU

The central processing unit, or CPU, functions as any processing machine's brain. It coordinates and oversees every operation performed by the microcontroller. The user has no control over how the CPU operates. It executes from storage, interprets the program that is kept in ROM, and then carries out its intended function. The CPU controls the many register types that the 8051 microcontroller has to offer.

Interrupts: The interrupt subroutine is called by the microcontroller when a high-priority program requests to access the system buses. This causes interruptions in the program that is now executing. An interrupt can be used to delay the present process using In order to complete a subroutine task and then resume the main program.

Different 8051 microcontroller interrupt types:

Let's look at the 8051 microcontroller's five interrupt sources:

  • Timer 0 overflow interrupt (TF0)
  • Timer 1 overflow interrupt (TF1)
  • External hardware interrupt (INT0)
  • External hardware interrupt (INT1)
  • Serial communication interrupt (RI/TI)

Memory

To do an operation The microcontroller needed a program. The tasks that the microcontroller is supposed to accomplish are guided by this software. A portion of the on-chip memory was needed for the microcontroller's installed program to be stored. Memory was also needed by the microcontroller in order to store operands and data for brief periods of time. In addition to 128 bytes of data memory (RAM), the microcontroller 8051 includes 4 KB of code or program memory, or 4 KB ROM.

Bus

A Bus is a collection of wires that is used as a data transfer or communication channel. Eight, sixteen, or more cables are included in the various bus arrangement. As a result, a bus can support 8 bits, or 16 bits total.

Bus types in an 8051 microcontroller

Let's show the two bus types that the 8051 microcontroller uses:

  • Address Bus: The 16-bit address bus is a component of 8051 microcontrollers. Transferring data from the central processing unit to memory is its usual use.
  • Data bus: The data bus of an 8051 microcontroller has eight bits. Transferring data from one peripheral place to another is often the usage for it.

Oscillator

It requires a timer to function because the microcontroller is a digital device. An on-chip oscillator is externally linked or connected for the microcontroller to execute timer functions. An embedded system is used a microcontroller to control device functionality. The two 16-bit counters and timers are operated by the 8051. The oscillator inside the microcontroller is utilized to operate the timers and counters.

Construction of 8051 Micro Controller

The 8051 microcontroller, which is made with CMOS technology, combines every part into a single silicon chip for dependability and compactness.

  • Central Processing Unit (CPU): executes all instructions.
  • Random Access Memory (RAM): Used to store variables and data.
  • Program instructions are stored in ROM (Read-Only Memory).
  • I/O Ports: Device interfaces with outside sources.
  • Timer/Counter: Produces time lags and tally outside occurrences.
  • Serial Communication Ports: Enables data communication in serial fashion.

Important Terminologies

  • Harvard Architecture: Data and program memory are kept apart.
  • Interrupts: A way to bring the main program to a brief stop for pressing tasks.
  • Bit-addressable RAM: Makes individual memory bits accessible.

Examples of 8051 MicroController 


the following examples is operated using of the 8051 microcontroller: 

  • Automation Systems: Management of industrial operations is one example of such application.
  • Consumer electronics, including washing machines and remote controllers.
  • Embedded Systems: electronics in cars, medical equipment.

"This Content Sponsored by Buymote Shopping app

BuyMote E-Shopping Application is One of the Online Shopping App

Now Available on Play Store & App Store (Buymote E-Shopping)

Click Below Link and Install Application: https://buymote.shop/links/0f5993744a9213079a6b53e8

Sponsor Content: #buymote #buymoteeshopping #buymoteonline #buymoteshopping #buymoteapplication" 

Friday, March 7, 2025

Difference between Microprocessor and Microcontroller

 

"This Content Sponsored by Buymote Shopping app

BuyMote E-Shopping Application is One of the Online Shopping App

Now Available on Play Store & App Store (Buymote E-Shopping)

Click Below Link and Install Application: https://buymote.shop/links/0f5993744a9213079a6b53e8

Sponsor Content: #buymote #buymoteeshopping #buymoteonline #buymoteshopping #buymoteapplication" 

ECG, EEG, EMG, Holter Monitoring, Fetal ECG/Fetal Monitoring and Digital Patient Data Recorders

  PART A – TWO-MARK QUESTIONS AND ANSWERS 1. What is a biomedical recording system? A biomedical recording system is an electronic syste...