In this tutorial we will learn how to blink the LED's with PIC16F877 Starter Board.
Starter PIC board has two on board LED's connected to PORTD.0 and PORTD.1.

Steps

  1. Configure the PORTS as outputs using TRIS registers.
  2. Turn ON all the LEDs and wait for some time.
  3. Turn OFF all the LEDs and wait for some time..

Code

#include <pic16f877a.h>
void DELAY_ms(unsigned int ms_Count)
{
unsigned int i,j;
for(i=0;i<ms_Count;i++)
{
for(j=0;j<1000;j++);
}
}
int main()
{
/* Configure all the ports as Output */
TRISA = 0x00;
TRISB = 0x00;
TRISC = 0x00;
TRISD = 0x00;
while(1)
{
PORTA = 0xff; /* Turn ON all the leds connected to Ports */
PORTB = 0xff;
PORTC = 0xff;
PORTD = 0xff;
DELAY_ms(100);
PORTA = 0x00; /* Turn OFF all the leds connected to Ports */
PORTB = 0x00;
PORTC = 0x00;
PORTD = 0x00;
DELAY_ms(100);
}
return (0);
}

Demo

Pic16f877aLedBlinking.gif