LED Interfacing with PIC18

Updated on 2017/11/20 12:44

LED Interfacing with PIC18

LED Interfacing with PIC18

Introduction of LED

A light-emitting diode (LED) is a two-lead semiconductor light source. It is a p–n junction diode that emits light when activated.[ When a suitable voltage is applied to the leads, electrons are able to recombine with electron holes within the device, releasing energy in the form of photons. This effect is called electroluminescence, and the color of the light (corresponding to the energy of the photon) is determined by the energy band gap of the semiconductor.

When operated in a forward biased direction Light Emitting Diodes are semiconductor devices that convert electrical energy into light energy.

led1

Light Emitting Diode Colours

So how does a light emitting diode get its color? Unlike normal signal diodes which are made for detection or power rectification, and which are made from either Germanium or Silicon semiconductor materials, Light Emitting Diodes are made from exotic semiconductor compounds

Different LED compounds emit light in specific regions of the visible light spectrum and therefore produce different intensity levels.

The LED is to be connected in a forward bias condition across a power supply it should be current limited using a series resistor to protect it from excessive current flow. Never connect an LED directly to a battery or power supply as it will be destroyed almost instantly because too much current will pass through and burn it out.

LED Series Resistor Circuit

Edit

The series resistor value RS is calculated by simply using Ohm´s Law, by knowing the required forward current IF of the LED, the supply voltage VS across the combination and the expected forward voltage drop of the LED, VF at the required current level, the current limiting resistor is calculated as:

res

An amber coloured LED with a forward volt drop of 2 volts is to be connected to a 5.0v stabilised DC power supply. Using the circuit above calculate the value of the series resistor required to limit the forward current to less than 10mA. Also calculate the current flowing through the diode if a 100Ω series resistor is used instead of the calculated first.

series resistor required at 10mA:

sam

An LED can be interfaced with PIC18FXXX Microcontroller for various purpose. The Port Pins are configured in the output direction. So, once the Logic "1" is the at O/P pin, then an LED will be turned "ON". And when Logic "0" is given the LED will be turned "OFF".

Simply: Logic "1" -> 5V DC to output pin

             Logic "0" -> 0 V to output pin.

So, as discussed in earlier, the LED with common cathode mode can be connected with PIC18FXX along with a resistor.

Thus, using the current limiting resistor, the LED will blink according to the written program.

Interfacing Diagram

led-interfacing-with-pic18.png

Embedded C Program

#include<p18f4520.h>
void DELAY();
#pragma config OSC=HS
#pragma config PWRT=OFF
#pragma config WDT=OFF
#pragma config DEBUG=OFF, LVP=OFF
void main()
{
TRISDbits.RD0 = 0x00;          //set RD0 pin direction as an output
while(1)                      //forever loop
{
PORTDbits.RD0=0X01;   //set RD0 pin as HIGH
DELAY();              //call delay
PORTDbits.RD0=0X00;   //CLEAR RD0 piN
DELAY();              //call delay
}
}

void DELAY()
{
unsigned int i;
for(i=0;i<10000;i++);
}

Video Simulation on Proteus


References

  • WikiNote Foundation
  • Created and Edited by Prof. Sujit Wagh, SKNCOE, Pune
Tags:
Created by Sujit Wagh on 2017/09/15 13:46