Thursday, May 7, 2015

How LEDs are turned On Off by a Microcontroller


The turning on and off LEDs or switch as used in control application is a major part of the microcontroller application. Another application is also displaying character on 7 segment display. The assembly code instruction to send 5 volt or 0 volt to the port 1.

To turn On/Off Leds we send single bit to port pins 0 to 7 of port 1. And to turn on 7 segment display we send a byte or turn on number of port pins simultaneously. The instruction to turn on/of single pin of a port is the setb and clr instruction for 8051 microcontroller. The instruction to send a byte to a port to turn on/off several pins of the port is the mov instruction.

Here we illustration how this works.

Consider first the process of turning on or off a single led. The following shows an illustration of 8051 microcontroller port 1 pins-





There are 8 port 1 pins labelled P1.0, P1.1, P1.2....P1.7. When using instruction like setb or mov instruction the microcontroller sends logic 1(5V) or logic 0(0V) to these port pins.

If we want to connect a LED to one of this port then we have two options. The first is to connect the LED between the port pin and the power supply and the second is connect the LED between the port pin and the ground.

The first method is shown below,


In this above schematic, when the 0V is sent or set to the port P1.2 then the LED would turn on because the the voltage from the +5V power supply would flow through the 330 ohm resistor into the port pin P1.2.This is illustrated below by running the simulation.

The instruction that is used to do this in this setting is- SETB P1.2

If logic 1 or +5V is sent to the port P1.2 then because of the voltage equality between the power supply and the port pin the LED is turned off. This is illustrated below.


The instruction to do this is CLR P1.2

And finally if we wanted to turn on/off the led regularly then we would use the SETB P1.2 and CLR P1.2 instructions. Similarly we could have used any of the ports or we could have used multiple port pins simultaneously.

Another method is to use the connect the LED to the ground as shown below,


If we sent logic 0 or 0V to the pin P2.1 then because there is no voltage difference between the ground and the port pin the LED would not turn on. But if we sent logic 1 or +5V to the port pin then because of the voltage difference of +5V between the port pin and the ground the LED would turn ON as illustrated below-


The instruction are the same as before.

The display of alphanumeric character on a 7 segment display is the same. Consider that the 7 segment display is connected to the port pins as shown-


In the above figure the 7 segment shows number 7 by sending 00000111 to the port 1. This is dine by the instruction MOV P1,#07H.

See the next blog post of how to write assembly program to turn on/off led in port 1

Related Posts by Categories

0 comments:

Post a Comment