8051 – GPIO Tutorial

Hi All…. In this tutorial we are going to see 8051 GPIO Tutorial. Before that if you are not installing Keil please install that. If you don’t know please go through the Here. Please see Here if you don’t know how to create the project. See the introduction of 8051 Here.

Let’s start!!!!!

8051 GPIO Tutorial

Introduction

Normally 8051 has four GPIO ports.

  1. Port 0 (P0)
  2. Port 1 (P1)
  3. Port 2 (P2)
  4. Port 3 (P3)

I have already discussed about the Ports in introduction. So now we can directly go into the programming.

WRITING ON A PORT PIN

Writing the data on a particular port is sending the data from the controller to any peripheral device which is connected with the controller. For example here we are using the LED to indicate the data coming out from the parallel port.

READING FROM A PORT

Reading operation is getting the data from any peripheral device. Here we are using a simple push button (switch) to give the input to the port pins.

LED Interfacing

A light emitting diode (LED) is essentially a PN junction opto-semiconductor that emits a monochromatic (single color) light when operated in a forward biased direction. LEDs convert electrical energy into light energy. They are frequently used as “pilot” lights in electronic appliances to indicate whether the circuit is closed or not.

Pin Diagram

Here LEDs are connected into Port 2 (P2). If you are going to connect LEDs into Port 0 (P0) you should connect the pull up resistor.

CODE

 

OUTPUT

 

Switch Interfacing

Pin Diagram

Here we are connecting switch into Port 1 . 0 (P1.0). Then LEDs are connected into P2. Whenever i press switch these LEDs should glow.

CODE

 

OUTPUT

 

Hope you enjoyed in this tutorial. But this is the basic. You can do it whatever you want. I will give you some exercises. Do practice it.

Tasks

  1. Blink alternate LEDs at P3 using software delay
  2. Blink P0 LEDs in cyclic fashion using software delay
  3. Count the number of times a switch at P1.1 is pressed and display the count in P2If you have any doubt please comment below. In our next tutorial we will see LCD interfacing.

Download our new Android app. You can learn all Embedded Tutorials from your Android Phone easily.

Click Here to Download App!