PIC16F877A LED INTERFACE

In this tutorial we are going to interface LED to PIC16F877A



Software : MPLAB IDE

Compiler: Hi Tech C

Simulation : Proteus

REGISTERS 

    TRIS - Tri State Register

                    This register is used to set the direction of the I/O pin.

                    1- is used to set the pin as input

                    0 - is used to set the pin as output

    Example: 

                                              TRISB = 0B00000000

            Here the PORT B 8 pins are assigned as output.

                   TRISC = 0B00000001

            Here the PORTC RC0 is set as input and remaining pins are set as output.

    PORT Register

    PORT register is used to assign the value to particular pin or entire port.

    Example: 

                                              PORTB = 0B00000000

            Here the PORT B 8 pins are low or logical zero.

                   PORTC = 0B00000001

            Here the PORTC RC0 is high or five volt and other pins are low or zero volt.

             Single pin in an PORT can also be assigned by setting the particular pin

    Example:

                    RC0=0;

        Here the RC0 is assigned as low or zero volt

                    RC0=1;

        Here the RC0 is assigned as high or five volt.


CODE FOR LED INTERFACE

/************************************************************/

#include<pic.h>
void delay()
{
    int i,j;
    for(i=0;i<100;i++)
    {
        for(j=0;j<100;j++);
    }
}
int main()
{
    TRISB =0B00000000;
    PORTB =0B00000000;
    while(1)
        {
            PORTB=0B11111111;
            delay();
            PORTB=0B00000000;
            delay();
        }
}
/****************************************************************/


  • In this LED coding PORTB is set as OUTPUT by assigning TRISB as 0 (zero).
  • PORTB is toggled high (1) and low (0) for certain time delay using delay function.
  • The while(1) is the endless loop function.
  • This process is repeated until power is turned OFF.

        






Comments

Post a Comment