8051 Microcontroller tutorials in c programming examples

8051 Microcontroller tutorials:  In this article we completely learn about 8051 microcontroller tutorials and interfacing with different component using 8051 microcontroller. So we discussed here some introduction and some important feature of 8051 microcontroller. In this article, we are going to introduce you a complete list of 8051 microcontroller tutorials. After reading these 8051 Microcontroller tutorials you will able to design your own project using 8051.

  1. Introduction

This is a introduction of series of 8051 microcontroller tutorials. 8051 microcontroller was first designed by Intel since 1980. It is a 8bit microcontroller. It have on chip one serial and four peripheral ports, 4K bytes of ROM, 128 bytes of RAM, counters, timers.

Features of 8051 Microcontroller

It provides us many functions on single chip.

Two timers/counters each of 16 bit.

It has 4 separate registers sets.

Serial port.

Internal and External input sources.

  1. Optocoupler Interfacing with AVR PIC and 8051 microcontroller.

In this second 8051 microcontroller tutorials we learn about the Optocoupler working of the Optocoupler and how to interface with AVR PIC and 8051 microcontroller.

What is Optocoupler?

It’s also known as Optoisolator. It is a electrical component that interconnect with two separate electric circuits, like that is used to transmit input signal by light sensitive.

Working of Optocoupler

It consist of a LED when the input voltage of LED is forward biased the LED emits light, this signal turn ON the photo transistor.

PC817 Optocoupler Interfacing with PIC

It’s a photo transistor which provides I/O voltage isolation upto 5KV. It can be used input output isolation of controllers.

It is a very easy to connect, port which you desire of PIC connect through resistor of pin no 1 of optocoupler and pin 2 ground. And output of its transistor connects as you require.

And also similarly

PC817 Optocoupler Interfacing with AVR and also with 8051 microcontroller.

  1. EEPROM interfacing with microcontroller.

In this topic we learn about the EEPROM and how to interface with 8051 microcontroller.

What is EEPROM?

EEPROM stands for Electrically Erasable Programmable Read Only Memory. It’s a ROM but data can be erased electrically. In which data is created by electrical pulses and grid. We can change and also erase a data according to requirement. Flash memory is a later form of EEPROM.

Electrically Interface of EEPROM

It categories two main devices

  • Serial Bus
  • Parallel Bus

EEPROM interfacing with microcontroller

The interfacing of EEPROM with microcontroller mostly done by master slave protocol known as 12C. Two signals of 12C, SCL and SDA. The operating of this interface is to send a signal like a READ/WRITE. The signal control by data or address bus. In 8051 two numbers of EEPROM lines are regulated by I2C supported drivers. The SCL and SDA are connected to the I2C based serial EEPROM. By using SDA and SCL I2C lines, the read and write operations of EEPROM are done in 8051.

4.    Difference between C language and Embedded C

C Language

C is a general purpose language, developed in 1972 by Denins R. Ritcjie. It’s imperative computer programming language. The C language is developed for creating system application that direct interacts to the computer hardware devices. The C language used the keywords like do while/while/for loop, if/else, switch, etc.

Embedded C Language

Embedded C is a very similar to C if you know C you won’t have a problem to learning the Embedded C. The embedded C is a collection of one or more functions. Through embedded C a high level optimization can be done. It is used in microprocessor or microcontrollers applications.

Major Difference between C and Embedded C

C LanguageEmbedded C
Independent of hardware architectureDependent on hardware architecture
Used for Desktop application, OS and PCUsed for limited resources like RAM, ROM and peripheral on embedded controller

5.   Types of Memory in Microcontrollers

In this topic we learn about the memory spaces and their use in microcontroller.

Types of memory in microcontroller

Three types of memory use in microcontroller;

  1. Program Memory
  2. Data Memory
  3. Date EEPROM

1.     Program Memory

Program Memory is a read only memory (ROM). Program memory where we store the applications. Some chips permit to part of the program memory to be modified in segments. In program memory we can’t store the variables. In a microcontroller normally store the constants i.e, instruction, initialized variables which we don’t change. It further divided into four different categories;

        i.            ROM (Read Only Memory)

      ii.            EPROM (Erasable Programmed Read Only Memory)

    iii.            OTP (On Time Programmable)

    iv.            FLASH EEPROM (Electrical Erasable Programmed Read Only Memory)

2.     Data Memory

Data memory is random access memory (RAM). It consist a general purpose register. The Date Memory is divide into 4 banks each banks having length 128 bytes means 128 free locations. Status register is used to access to each bank. It is a special function register which is used to control the aspect of microcontroller. Some specials function registers like, like Timers, Serial port, peripheral control etc.

3.      Data EEPROM Memory

EEPROM stands for Electrically Erasable Programmable Read Only Memory. It’s a ROM but data can be erased electrically. In which data is created by electrical pulses and grid. We can change and also erase a data according to requirement. Flash memory is a later form of EEPROM.

  1. How to write a first program in Keil for 8051

In this topic we deal with the programming of 8051 microcontroller. And also learned how to write a program in Keil.

For AT89C51 programming we used a Keil µVision software. Programming can be C, C++ or in any another language.

Steps to use the Keil

First of all download the Keil µVision 5 setup and install the following instructions. After the installation now open the Keil µVision, and follow these steps;

  1. For any new project, click on Project>> New µVision Project.
  2. A new window will display on screen which will prompt for project name and directory.Give a name to your project.
  3. When you click on save button, a new window will appear naming “Select Device for Target ‘Target 1’”. Now we have to select specific microcontroller. Here, we have to use 8051, which belong to Atmel family, so double click on Atmel. All Atmel microcontrollers will get available. SelectAT89C51 and then click on OK.
  4. When you click on OK, another window will appear which will ask for “Copy Standard 8051 Startup Code to Project Folder and Add File to Project?” Click on YES to proceed further.
  5. If we see on left side of screen i-e, in ‘Project workspace’ you can see ‘STARTUP.A51’ file. It is the file which contains the assembly language commands of 8051 microcontroller. Leave it just as it is, because we have to first set option values for target1.
  6. To configure option valueof our microcontroller project. Select the Target 1, click on Project>>Option for target ‘target 1’”.
  7. Select Target tab to configure microcontroller. Change the crystal value from 24 MHz to 12 MHz and go to output tab.
  8. In Output tab, check the “create HEX file” option and then click OK.
  9. Now click on File << New. Or simply create new file. Blank text file will open and we have to write our code in it. After writing the code, save this file and the most important thing is to give extension of .c or .asm (according to the language used for program) in file name.
  10. Right click the target and select manage components. From the Project component tab >> select STARTUP.A51 >> click add files.
  11. Add saved file and close the components window by clicking OK.
  12. Now we are again on the code. Just click on the “Rebuild all target files” from tool bars. We can also choose Project << Rebuild all target files. By clicking this button our program will start compilation and give the compilation results at bottom output window. If our code is correct then there will be no errors.

Now the hex file is created in the specified folder with “.hex” extension. We can burn it in microcontroller through Fly pro software and burner circuit.

  1. How to use input output ports 8051 microcontroller LED blinking

In this topic we learned how to use the input output ports of 8051. 8051 consist 40pins contains four I/O ports. 8 pins are used for specific purposes and 32 pins are used as input/output  to connect with the peripheral devices. Each port is 8bit which configured as I/O port.

Ports Description of input output ports 8051 microcontroller

Port 0

P0 includes 32-39 pins. It’s  I/O port which some alternative functions.

Port 1

P1 includes 1-8 pins. It is general purpose I/O port. Only 8bit R/W. P1 contains built-in pull-up resistor and is compatible with TTL circuits.

Port 2

P2 includes 21-28 pins. It’s also 8bit R/W general purpose I/O. High byte of address bus for external memory.

Port 3

P3 includes 10-17 pins. It’s an I/O port with different functions.

Working of input output ports

In the LED blinking example we use a push button as a input and led as a output. If push the 1st button the 1st led glow and then after the 1 second  led off. When push the 2nd button the 2nd led glow after the 1 second the led off, similarly we can turn ON the led.

  1. 8051 timer how to generate delay using 8051 timers

In this topic we learned how to generate delay using 8051 timers. 8051 consist two 16bits timers, every one programmed individually 8051 have three general function;

  • Calculating the amount of time between events.
  • Counting events.
  • Generating baud rate for serial port.

Timers of 8051

  • Timer0 Register
  • Timer1 Register

These timers control individually.

  1. Interrupts 8051 microcontroller
  • How to use external interrupt

In this topic we deal with 8051 interrupts. And also how to use an external interrupts. Interrupts used to communicate between microcontroller and external device.

Types of interrupts

Interrupts is a request or delay to microcontroller to stop the current program temporary and make to solve the interrupt first, in microcontroller six types of interrupt recognize;

  • Reset interrupts
  • Timer0 overflow interrupt TF0
  • Timer1 overflow interrupt TF1
  • External hardware interrupts INT0
  • External hardware interrupts INT1
  • Serial communication interrupt (RX/TX)
  1. Interfacing ADC 0804 with 8051 microcontroller

This topic is about interfacing analog to digital convertor (ADC) to 8051 microcontroller. ADC 0804 is used here before going through the interfacing; we must nearly understand how the ADC 0804 works.

ADC 0804

ADC0804 is a 8bit analog to digital convertor. The ADC has different analog digital inputs; 0-5V input voltage range, no zero adjustment, built in clock generator, reference voltage can be externally adjusted to convert small analog voltage to 8bit resolution.

  1. Interfacing of LCD with 8051 microcontroller

In this topic we learned how to interface LCD with microcontroller. LCD is used for displaying a different character, numbers or some message etc.

16×2 LCD

Here we use a simple 16*2 LCD for interfacing. We can also use 8*1, 16*4 etc. So 16*2 LCD display the 32 characters at a time. There a 16 pins in LCD module.

LCD interfacing with 8051 microcontroller

The LCD can be operating in 4bit or 8bit mode. First of all initialized the LCD. Then Reset and Enable pins of LCD are connected with port 1 of microcontroller. Data pins connected with port 2. And R/W pin connect to the ground, Vcc pin connected through the battery.

  1. KEYPAD Interfacing with 8051 microcontroller

In this tutorial we learned about how to interface the keypad using 8051 microcontroller. And also we learned about the programming part of the keypad.

Keypad Structure

In a keypad push button as a switches that arranged in row and columns. In 4*4 keypad 16 switches use to connect the microcontroller.

Keypad interfacing using 8051 microcontroller

For best communicate and result displaying to connect the LCD with port 2 of microcontroller. Keypad is connected to port 3 of microcontroller to scan the input. RS and Enable pin connect the port 1.

  1. DC Motor Interfacing with 8051 microcontroller

In this topic we learned about the DC motor and how to interface with microcontroller. Directly connect the DC motor to microcontroller is not a good because the motor need more current else the microcontroller provide current. So to solve this problem we use a motor driver to interface with microcontroller.

Motor Driver  

To solve the problem a motor driver IC is connected between DC motor and microcontroller. We use IC like L293D or L298.

  1. Stepper Motor Interfacing with 8051 microcontroller

In this topic we learned about the Stepper motor and how to interface with microcontroller

What is Stepper Motor?

Stepper motors are type of DC motors A Stepper Motor is a brushless, synchronous DC Motor. It has many applications in the field of robotics and mechatronics. The total rotation of the motor is divided into steps. The angle of a single step is known as the stepper angle of the motor.

Interfacing with 8051 microcontroller

It’s also used a motor driver IC due to current limitation of microcontroller we can used L293D or ULN2003.

  1. Servo motor Interfacing with 8051 microcontroller

This topic about the Servo motor, in this topic we learned how to interface and control servo motor using 8051 microcontroller.

What is Servo Motor?

A servo motor is a mechanism that allows to control the angular position. It consist the motor coupled sensor that is used to control the rotary motion of the motor. Servo motor works on PWM (Pulse width modulation) principal means its angle of rotation is controlled by the duration of applied pulse to its Control PIN.

Interfacing with 8051 microcontroller

Servo motor has three terminal one terminal connect to ground, second for supply and third connected through the microcontroller for the motor signal.

  1. Serial communication 8051 microcontroller

In this topic we deal with Serial communication using 8051 microcontroller. Serial is not much fast as parallel communication but it can deal with transmission of data over longer distances.

Interfacing with 8051 microcontroller

8051 microcontroller has a built-in serial port called UART. We can easily read and write values to the serial port.

so this is all about complete list of 8051 Microcontroller tutorials for beginners, I hope this list helps to understand its c programming using keil compiler. I will keep updating this list with more tutorials.

Add Comment

Subscribe to our blog to get updates in your email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1,357 other subscribers