Tuesday, 10 September 2024

8051 MICROCONTROLLER TUTORIAL FROM BASICS TO ADVANCED CONCEPTS

Hi friends do you know that today we are exploiting the advance technology used in our mobiles phones, smart phones and the technology due to which the computer is present in every home today is because of the a revolutionary thought in the small semiconductor company Intel Corporation for the making of a general purpose  programmable device based on an instruction set.It could be programmed and the program can be easily executed using some other components and ICs. It was called Intel 4004 microprocessor. It uses a RAM memory, ROM memory, Keypad  interface ICs, Latches ,etc. It occupy very less space as compared to the other computers hardware used in early days. It was like a CPU in computers on a small chip. It make the size of computers very less when its new and upgraded version started to manufacturing. It laid the foundation of most popular x86 instruction set for future products and it is most common in all intel CPUs. Today mobile phones uses a RISC (Reduced Instruction Set Computer) like ARM cortex processors whose architecture is completely different then conventional processors.
The 8051 also incorporates the basic or primitive version of x86 Architecture and  it is more fun to learn about this Microcontroller. I will be updating this article from time to time so stay tuned.

Have you ever wondered how electronic devices make decisions, control motors, display information, or communicate with other devices? The answer lies in tiny programmable chips known as microcontrollers.

Before the era of smartphones, artificial intelligence, and high-speed processors, engineers developed simple yet powerful devices that revolutionized embedded systems. One such device is the **8051 Microcontroller**, which remains one of the most popular microcontrollers ever developed.

Even today, the 8051 is widely taught in engineering colleges because it provides an excellent foundation for understanding embedded systems, computer architecture, and low-level programming.

This tutorial will take you from the history of the 8051 to its architecture, programming, interfacing, and practical applications.

---

# Chapter 1: Evolution of Microprocessors and Microcontrollers

## The Beginning

In 1971, Intel introduced the world's first commercially available microprocessor:

* Intel 4004
* 4-bit processor
* 2300 transistors
* Clock speed around 740 kHz

The Intel 4004 required external:

* RAM
* ROM
* Input/Output circuits
* Timers

As technology progressed, Intel introduced:

* Intel 8008
* Intel 8080
* Intel 8085
* Intel 8086

These processors eventually led to the famous x86 architecture used in modern computers.

---

## Why Microcontrollers Were Needed

A microprocessor acts only as a CPU.

To create a complete system, additional components are required:

* RAM
* ROM
* Timers
* Input/Output Ports
* Interrupt Controllers

This increased:

* Cost
* Circuit complexity
* PCB size

To solve this issue, manufacturers integrated all these peripherals into a single chip called a **Microcontroller**.

---

## Birth of the 8051

In 1980, Intel introduced the **8051 Microcontroller**.

It combined:

* CPU
* RAM
* ROM
* Timers
* Serial Communication
* I/O Ports

inside a single chip.

This made embedded system development easier and cheaper.

The 8051 quickly became an industry standard.

---

# Chapter 2: What is a Microcontroller?

A microcontroller is a compact computer on a chip.

It contains:

1. CPU
2. Memory
3. Timers
4. Communication Interfaces
5. Input/Output Ports

### Real-Life Examples

Microcontrollers are found in:

* Washing Machines
* Microwave Ovens
* Air Conditioners
* Automotive Electronics
* Security Systems
* Medical Equipment
* Industrial Automation

---

# Chapter 3: Features of 8051

Standard 8051 contains:

| Feature              | Specification |
| -------------------- | ------------- |
| CPU                  | 8-bit         |
| ROM                  | 4 KB          |
| RAM                  | 128 Bytes     |
| I/O Ports            | 32            |
| Timers               | 2             |
| Serial Port          | 1             |
| Interrupts           | 5             |
| Oscillator Frequency | Up to 12 MHz  |

---

# Chapter 4: 8051 Architecture

The major blocks are:

```
          +----------------+
          |      CPU       |
          +--------+-------+
                   |
     +-------------+-------------+
     |             |             |
     v             v             v

+---------+   +---------+   +---------+
| Program |   | Data    |   | Timers  |
| Memory  |   | Memory  |   | Counters|
+---------+   +---------+   +---------+

     |             |             |
     +-------------+-------------+
                   |
             +-----------+
             | I/O Ports |
             +-----------+
```

---

# Chapter 5: Pin Diagram

8051 consists of 40 pins.

### Ports

#### Port 0 (P0.0–P0.7)

* Multiplexed address/data bus
* Open drain

#### Port 1 (P1.0–P1.7)

* General-purpose I/O

#### Port 2 (P2.0–P2.7)

* Higher address bus

#### Port 3 (P3.0–P3.7)

Special functions:

| Pin  | Function |
| ---- | -------- |
| P3.0 | RXD      |
| P3.1 | TXD      |
| P3.2 | INT0     |
| P3.3 | INT1     |
| P3.4 | T0       |
| P3.5 | T1       |
| P3.6 | WR       |
| P3.7 | RD       |

---

# Chapter 6: Internal Memory Organization

8051 follows Harvard Architecture.

Program and data memories are separate.

---

## RAM Structure

128 Bytes Internal RAM

### Register Banks

```
Bank 0 : 00H–07H
Bank 1 : 08H–0FH
Bank 2 : 10H–17H
Bank 3 : 18H–1FH
```

---

### Bit Addressable RAM

```
20H – 2FH
```

Each bit can be accessed individually.

---

### General Purpose RAM

```
30H – 7FH
```

Used for variables and data storage.

---

# Chapter 7: CPU Registers

## Accumulator (A)

Most arithmetic operations use A register.

Example:

```assembly
MOV A,#25H
```

---

## B Register

Used in multiplication and division.

Example:

```assembly
MUL AB
DIV AB
```

---

## Program Counter (PC)

Stores address of next instruction.

---

## Stack Pointer (SP)

Points to stack location.

Default value:

```assembly
07H
```

---

## Data Pointer (DPTR)

16-bit register.

Used for external memory access.

---

# Chapter 8: Clock and Machine Cycle

8051 requires crystal oscillator.

Typical crystal:

```text
11.0592 MHz
```

Machine Cycle:

```text
1 Machine Cycle = 12 Clock Cycles
```

At 12 MHz:

```text
Machine Cycle = 1 µs
```

---

# Chapter 9: Instruction Set

Instructions are divided into:

### Data Transfer

```assembly
MOV
PUSH
POP
XCH
```

### Arithmetic

```assembly
ADD
ADDC
SUBB
INC
DEC
MUL
DIV
```

### Logical

```assembly
ANL
ORL
XRL
CLR
CPL
```

### Branching

```assembly
SJMP
AJMP
LJMP
JZ
JNZ
DJNZ
```

---

# Chapter 10: Assembly Programming

## Program 1: Add Two Numbers

```assembly
MOV A,#25H
ADD A,#15H
```

Result:

```text
A = 3AH
```

---

## Program 2: LED Blinking

```assembly
START:
MOV P1,#00H

LOOP:
SETB P1.0
ACALL DELAY

CLR P1.0
ACALL DELAY

SJMP LOOP
```

---

# Chapter 11: Timers

8051 contains:

* Timer 0
* Timer 1

Modes:

| Mode   | Bits              |
| ------ | ----------------- |
| Mode 0 | 13-bit            |
| Mode 1 | 16-bit            |
| Mode 2 | 8-bit Auto Reload |
| Mode 3 | Split Timer       |

Applications:

* Delay generation
* Event counting
* Pulse measurement

---

# Chapter 12: Interrupts

Interrupt allows CPU to respond immediately to events.

Available Interrupts:

| Interrupt | Vector Address |
| --------- | -------------- |
| INT0      | 0003H          |
| Timer0    | 000BH          |
| INT1      | 0013H          |
| Timer1    | 001BH          |
| Serial    | 0023H          |

Benefits:

* Faster response
* Efficient CPU utilization

---

# Chapter 13: Serial Communication

8051 supports UART communication.

Important Registers:

### SCON

Serial Control Register

### SBUF

Serial Buffer Register

---

Example:

```assembly
MOV SBUF,#'A'
```

Transmits character A.

---

# Chapter 14: Interfacing Examples

## LED Interfacing

Output Device

```text
P1 → Resistor → LED
```

---

## Switch Interfacing

Input Device

```text
Switch → Port Pin
```

---

## LCD Interfacing

Common LCD:

```text
16x2 LCD
```

Used for displaying:

* Text
* Numbers
* Status messages

---

## Seven Segment Display

Displays digits:

```text
0 – 9
```

Applications:

* Counters
* Clocks
* Measurement systems

---

## ADC Interfacing

Converts analog signal into digital data.

Examples:

* Temperature sensors
* Pressure sensors
* Potentiometers

---

# Chapter 15: Applications of 8051

The 8051 has been used in:

### Consumer Electronics

* Television
* Washing Machine
* Microwave

### Industrial Systems

* PLC Controllers
* Motor Control
* Process Automation

### Automotive Systems

* Dashboard Control
* Lighting Systems
* Sensor Monitoring

### Communication Systems

* Modems
* Data Loggers
* Serial Communication Devices

---

# Chapter 16: Advantages of 8051

### Advantages

* Easy to learn
* Low cost
* Large community support
* Rich instruction set
* Excellent for beginners

### Limitations

* Limited RAM
* Limited Flash memory
* Slower than modern controllers

---

# Chapter 17: Modern Successors

Today, 8051 has largely been replaced by:

* ARM Cortex-M Series
* AVR Controllers
* PIC Microcontrollers
* ESP32
* STM32
* RISC-V Microcontrollers

However, the 8051 remains one of the best platforms for learning embedded systems fundamentals.


The 8051 microcontroller represents one of the most important milestones in embedded electronics. Although modern processors are far more powerful, the concepts learned from the 8051—such as memory organization, interrupts, timers, serial communication, and low-level programming—form the foundation of embedded system design.

For students and beginners, mastering the 8051 provides a strong understanding of how computers interact with the physical world. Once these concepts are understood, transitioning to modern platforms such as ARM Cortex-M, STM32, ESP32, and RISC-V becomes significantly easier.

The 8051 is not merely an old microcontroller—it is a gateway to understanding the entire field of embedded systems.

Friday, 26 June 2015

BRUSHED DC MOTOR SPEED CONTROLLER


We often need to control the speed of DC Brushed motor in many situations.The commercially available speed controller are very costly so why not make a cheap motor speed controller easily at home.The main idea behind controlling the speed of DC Brushed motor is that the RPM or speed of Rotor of DC motor is directly proportional to the square of voltage applied across the terminals of the dc motor, hence by decreasing or increasing the voltage across the terminals of the motor we car easily increase or decrease the speed of the motor.Now question arises how to vary the voltage across the terminals of motor. A circuit can be designed to vary the voltage across the terminals of motor using some transistors and some potentiometer. Here is the circuit diagram-

The above circuit is the DC motor speed controller circuit in which two transistors are connected in dalington configuration. Here the list of components used-
:: one 10k ohm Resistor (R1)
:: one 10k ohm potentiometer or preset (RV1)
:: one 10 ohm resistor (R2)
:: one 2N3904 Transistor (Q1)
:: one MJE13003 Transistor (Q2)
:: one Brushed DC motor
:: connecting wires
:: Perforated or general board for mounting components
:: solder and soldering iron
The darlington configuration of the two transistors is obtained by connecting the Emitter of Q1 with the Base of Q2 and connecting both Q1 & Q2 collector together. Now the obtained configuration is darlington configuration which behaves as a single transistor whose base is the base of Q1 and the emitter is the emitter of Q2 and since the collector of both transistor are connected therefore it is the joined collector of the single behaving transistor as shown in the circuit diagram above. The most important property of a darlington configuration is the Hfe product property.
The Hfe of the dalington pair of the transistor as a whole is the product of the individual transistor's Hfe. Hence we get a large output for small change in base current of Q1. Also the 2N3904 is capable of handling about 500 mili amps of current also it get very hot when operated at extreme positions hence to eliminate this 13003 (Q2) transistor is used with 2N3904 (Q1) in dalington cofiguration in which the 13003 will sink all the current passing through the motor as it is capable of delivering maximum current of 3 amps. , Normally motor needs less than 1 amp. . If your motor is of higher current rating then you can replace 13003 (Q2) transistor with another suitable transistor which can deliver higher current then 13003 like 13007 ,etc,.
Now the darlington pair is properly biased by using voltage  divider  biasing  technique with the help of a 10k ohm resistor and a 10k ohm potentiometer or preset. The potentiometer or preset is a device whose resistance can be varied in some specified limits by rotating the knob of potentiometer or by rotating the wiper of preset using screwdriver. Below is a potentiometer.

The potentiometer's knob will be used for the controlling speed of motor by rotating it. The middle terminal of the potentiometer or preset is the variable resistance terminal which is connected to the base of the transistor Q1 and other terminals are used for completing the biasing circuit of the darlington pair.The motor is connected at the terminals A and B as shown in the circuit.The emitter of Q2 is grounded through a 10 ohm resistor to regulate the flow of current through the motor. The current flowing through the motor  is the sum of collector current through Q1 and Q2 transistor. But large quantity of current flows through the 13003 transistor. A small change in the value of current through the transistor's base Q1 brings large change in current and hence voltage across motor. So by rotating the knob of the potentiometer ,the resistance below R1 changes and hence the voltage across RV1 lower changes linearly consequently the voltage at the base of transistor Q1 changes which changes the base current of Q2 and hence voltage across Terminals A and B changes. Which changes the speed of the DC motor connected at terminals A and B.
Hence in this way the speed of the Brushed DC motor can be varied by just rotating the Knob of the potentiometer in the Circuit.
For making the physical circuit on pcb just place all the listed components in their proper place and connect as shown in the circuit diagram.For details about making pcb of circuit click here.

Wednesday, 22 October 2014

12 V DC POWER SUPPLY



Today I am going to make here a 220 Volt AC to 12 Volt DC  Power supply.

For that we must be familiar with the conversion of  high voltage AC to low Voltage AC.A transformer is used for the conversion, which is the combination of two coils mutually coupled together using a ferrite core, Which is a soft iron core.One coil is of large numbers of turns with high resistance of small diameter of copper wire, which is called high voltage coil and another coil is of low resistance ,low number of turns but with comparatively large diameter of copper wire,which is called low voltage coil.
TRANSFORMER TEST-
Before using the transformer we must know which coil's terminals should be connected to mains or circuitry.It is important since this knowledge would protect your home wiring as well as protects your transformer  from being burned or damaged.
Now have a multimeter  (analog or digital) with you and set it to ohm measurement,now test each coils terminals,see that what readings you get.
If you are getting a reading in few kilo-ohms then it must be the high voltage coil or primary coil.
If you are getting a reading in only ohms then it must be the low voltage coil or secondary coil.
Also test for the shorting of the coils by checking the resistance of both the coil is infinite or not,If not then the transformer is faulty, just change the transformer.

Also test for the coil and core resistance is infinite or not,If so then be aware that you can get shock if you don't take care of it.It is recommended that you must change the transformer in such condition.
BUILDING THE DEVICE-
Here is the list of components-
:: Four 1N4001 diodes
:: one 9-0-9,500mA transformer
:: one LM7812 IC
:: one 470uF,50v Electrolytic capacitor
:: one 10uF,25v Electrolytic capacitor
:: one 0.1uF ceramic capacitor
:: wires
:: shoulder and shouldering iron
:: A perforated copper board or a copper clad board with 5cm By 5cm                  dimensions.  
:: A 10 cm by 10 cm cardboard
Make a bridge rectifier (see here how to make bridge rectifier) on the perforated board now take the transformer secondary or low voltage coil terminals as the rectifier AC input.The 9-0-9 has three terminals of the low voltage coil,leave the zero potential or common terminal of the coil and take the other two terminals.Always remember that a transformer output gives an AC voltage which has no polarity so don't worry of the connection at the rectifier input,it can be connected at any polarity as the input to rectifier.
Now the output of the bridge rectifier is always fluctuating DC, for knowing the polarity test it with the multimeter.You can also know the polarity by seeing that the same p terminals connected together will have negative output and vice-versa in the bridge rectifier.



Now after knowing the polarity, connect the 470uF capacitor in parallel to the bridge rectifier output.Before connecting also see the polarity of the electrolytic capacitor and connect with the same polarity as the bridge output.The black line near the terminal shows that it is negative terminal.
If the electrolytic Capacitor is connected with wrong polarity then the capacitor may explode.Also connect another 10uF electrolytic capacitor in parallel with the 470uF capacitor with correct polarity.

Now connect the positive terminal of the capacitor to the input or first terminal of the LM7812 IC and other terminal to the ground terminal or second/middle terminal of the IC. Now take the output at third/Output terminal of the IC w.r.t. the ground terminal.For stability Connect 0.1uF capacitor in parallel to the output terminal and ground terminal.Take the output across the 0.1uF capacitor.
Now fit all the circuitry on the cardboard and use it for any electronic application, Which requires 12v dc and 400mA of current.For high current applications just add a heat sink to the LM7812 IC.
You can also mount the components on a copper clad board PCB (See here how to make PCB).

Here are some pics of the Device-












Saturday, 12 July 2014

HOW TO MAKE PCB OF AN ELECTRONIC CIRCUIT USING EXPRESS PCB

Hi friends today i will tell you about pcb making of an electronic circuit. To temporary make the circuit some persons use perforated boards to mount and shoulder the components. But to make permanent circuit we use copper clad board so as to ensure less wear and tear with the pcb. Some of you might have seen the pcb inside various electronics equipment e.g., T.V. , Radio, etc. We will make pcbs similar to that with perfect outline of the tracks as it has been manufactured from a company. Now first of all you must know the circuit diagram of electronic gadget you are going to make. The circuit schematic is drawn on the paper with the pin connections of different terminals of  electronics  components. The circuit diagram  helps   us for accurate making of pcb layout with right pin connection.Now the express pcb software is used for drawing the schematic in express SCH portion of the express pcb software and after making,Its printouts is taken and the circuit schematic is obtained in this way.For making the circuit schematic you must install the express pcb software (Download here free).Now after installation you will find two icons viz. expressSCH and expressPCB.The former is used for drawing the schematic,  Now double click  the the former icon and a window will appear showing various tools and drawing area.You can choose any of the ICs and electronic component from the menu.The component Menu comes when you click on the analog icon on the tool bar. Then you choose the required component or IC. Now after choosing the correct item you can place it on the work area.The component Menu contains various ICs with their part numbers and company name also like Texas instruments     SN75160, Linear Technology LT1070, Atmel Microcontrollers, Microchip PIC microcontrollers series ICs,and many more are there in the component Menu.You can choose your desired ic of which you are going to make the circuit.The ICs contains all the associated Pin with names Labeled. If the component is not listed in the Menu Then You can create your own component using Various tools in the tool bar, these component are at no.9,10,11 Position from the upper most tool.Get the information of making the custom component in the Quick start Guide of the Express SCH. You can connect the various components pins using the Connecting wire Icon from tool bar at left.Now according to the Datasheets and application notes of the components and ICs make the correct connection with wire tool. When the circuit is complete you can print the whole circuit on paper and obtain the schematic, and save the .sch file. Now double click on the express PCB icon and you will find there a toolbar,Menu bar,In The toolbar you will find a component Menu tool in the shape of an IC. You can then select the proper component and place it on the work area.Different connectors and different IC packages are available such as SOIC package,QFN package,DIP Package ,etc.This Creates a versatile ways of designing your pcbs. Now select the Wire tool for connecting different pins of the components, Also you Can link your .sch file in the ExpressPCB for Pin Connecting aid.However it is recommended in large circuit since the chances of wrong pin connection are high as compared to small circuits.It is not necessary to link the .sch file to ExpressPCB also it is not necessary that you draw schematic in ExpressSCH  for small circuit you can take a look at pin connection by hand made schematic. For linking the .sch file go to File option in the Menu bar and select 'Link schematic to PCB' .You can also configure the track width and it curvness.It is recommended to use keyboard keys for proper placement of component and wires for a perfect layout.Also the thermal pad option is available and the top layer and bottom layer option is available.You can make the custom components if it is not available in the component list. For procedure of making the custom component see the 'Quick guide of ExpressPCB' .Now after completing the layout Go to print option in the File option in Menu Bar or use short cut keys ctrl+P. Here  If you have make the pcb layout in both top layer and bottom layer then you can choose either one or both at a time.You must mention or choose the paper size for printing like A4,A3 ,etc.The paper that you use for printing must be a Butter paper or a magazine paper and the printer that you use must be the Laser printer.If you Don't have a laser printer then select in the printer option 'Windows XPS document writer'  and click ok. You will get a .xps file which you can take in pen drive and go to a photostat shop or cyber cafe that have a laser printer and print the layout on the butter paper or magazine paper. Always see the component datasheet for the proper size of the package of ICs or component you are going to use in your circuit.Also Read the Quick Guide of the softwares.Here is the Pcb Layout Of a Transmitter and Receiver Circuit Using HT12D and HT12E and RF Modules in ExpressPCB.


Here is the pcb layout of Transmitter and Receiver Circuit Using HT12D and HT12E and RF Modules which is ready for printing.


The above layout is from .xps file of the circuit.Now after printing the .xps file on Butter or magazine paper.Keep the following list of items ready for pcb making-
:: Copper clad board   (desired size)
:: Ferric chloride         (depending on size of board, dissolve 10gm in water for 50 by 30 copper clad board)
:: Electric Iron
:: Thinner
:: permanent marker  (for error correction) 
Now take the copper clad board of the size a little greater than the pcb layout.Now cut out the extra paper in the margin of the printed paper and then put in over the copper clad board where the copper is present with the printed side touching the copper surface.Before placing the paper rub the copper side of copper board with the help of scotch-brite available in market and clean the board with the help of cloth.Now pre heat the clothing iron for five minutes then place it over the magazine or butter paper below which the copper board is present.And apply lot of pressure and heat for 10 minutes and then take the board carefully since it is hot.You will see that the paper has sticked to the board then wash the paper with lot of water and remove the extra paper.You will see that the toner has been transferred to the board i.e. the whose layout has been transferred to the board.Also verify the design that all tracks are right or not,if you find any incomplete track then correct it by using permanent marker Keep the ferric chloride solution ready and dip the printed board in the solution for fifteen minutes (Eaching Process). Here are some snapshots-

Below is the Dual H-Bridge for Motor direction control used in remote control car.Its layout is not shown here.

Below is the PCB Layout of above circuit in express pcb.

Here is PCB layout from .xps file.


Here is the PCB in Ferric Chloride solution-


When Fifteen minutes has completed take out the pcb from the solution with the help of gloves and wash it with water.Now clean the pcb with thinner you Will notice that the extra copper has been removed and your pcb is ready for drilling.Drill the holes using hand drill or stand still drill at appropriate places where the components are to be placed. Use appropriate size of drill bit normally use 1mm bit.After drilling your pcb is ready to be used for placing components and shouldering.But before making the PCB layout of the circuit test the circuit on a breadboard.Here are the pcbs of the layout shown in this article.
Below is the H-Bridge circuit PCB.

Below is the Transmitter circuit PCB.




Below is the Receiver circuit PCB.

You can use the vast varieties of PCB designer software Only the difference lies is the operation of software but the procedure is same printing,transfering,eaching process etc. are same.Be careful with Ferric Chloride since it is highly corrosive.It is recommended to use gloves for treating with Ferric Chloride.

8051 MICROCONTROLLER TUTORIAL FROM BASICS TO ADVANCED CONCEPTS

Hi friends do you know that today we are  exploiting  the advance technology used in our mobiles phones, smart phones and the technology d...