Ad Code

Responsive Advertisement

Ticker

6/recent/ticker-posts

Blink LED with PIC16F877A

Blink LED with PIC16F877A
  


fig: Light Emitting Diodes (LEDs)

Blink LED with PIC16F877A

In this tutorial, i will take you through the process of blinking an LED with PIC16F877A and i hope you have gone through my previous post on Getting started with MikroC pro for PIC Compiler if not, click   here  

A light-emitting diode (LED) is a semiconductor light source that emits light when current flows through it. LEDs are used in many electronic devices as indicator lamps, in automobiles as rear-window and brake lights, and on billboards and signs as alphanumeric displays or even full-colour posters.


There are two ways of connecting the LED with PIC16F877A which are:

  • Current sinking mode 
  • Current souring mode
In current sinking mode, current flows from the power supply (+5V) through a resistor and the LED itself to the I/O (Input/Output) pin of the microcontroller as shown in the schematic diagram below. In order to turn ON the LED in this mode, a logic Zero (i.e. a logic LOW) should be sent to the I/O pin and in order to turn OFF  the LED, a logic One (i.e. a logic HIGH) should be sent to the PIC MCU.

Fig: Current sinking mode



In current sourcing mode, current flows out of the PIC MCU through a resistor and to the LED itself as shown in the schematic diagram below.  In order to turn ON the LED in this mode, a logic One (i.e. a logic HIGH) should be sent to the I/O pin and in order to turn OFF  the LED, a logic Zero(i.e. a logic LOW) should be sent to the PIC MCU.


Fig: Current sourcing mode

In this tutorial we will consider the Current Sourcing mode but Note that in order to work with the current sinking mode, one has to adjust the Logic sent to the I/O pin in the code as well as the schematic.

Materials Required:

  • PIC16F877A

  • 22pf capacitors

  • 10k resistor

  • 330R resistor

  • LED

  • Crystal Oscillator

NB: The crystal oscillator as seen in the diagram is used to determine the clock speed of the PIC MCU, in this tutorial we are making use of an 8MHZ oscillator .

Connect the above circuit on your bread board and upload the code below into the microcontroller.

CODE:



/*

  Name     : BLINKING LEDWITH PIC16F877A

  Author   : DANIEL OLUWOLE

           : (C) 2020 DANITRONICS.

           : danitronics7@gmail.com, danieloluwole51@yahoo.com

           : Mobile: +234 8188508765.

  

  Notes    this programme switches ON and OFF an LED connected to PORTD.0 every second.

  Compiler : MikroC Pro for PIC

  Target   : PIC16F877A

*/



void main() {                                //program begins here

      TRISD.B0 = 0;                     //set bit 0 of PORTD as output

      do{

              PORTD.B0 = 1;            // turn ON LED on bit 0 of PORTD

              delay_ms(1000);          // wait for 1 second

              PORTD.B0 = 0;            // turn OFF LED on bit 0 of PORTD

              delay_ms(1000);          //wait for 1 second

  }    while(1)  ;                  // loop this forever

}


Our next tutorial focuses on interfacing the PIC16F877A with a Switch.

Read Switch with PIC16F877A

Post a Comment

0 Comments

Ad Code

Responsive Advertisement