PIC16F877A Timer1 RB0 LED Blink

By Kunal Kapoor

LED blink using PIC16F877A is the simplest project that one can undertake. LED blink is like the” Hello World” equivalent to embedded programming.

Using the simplest approach we will be executing LED blink using a single pin interface.

Timer 1 is 16 bit timer in PIC16F877A microcontroller.

Read About Timer1 in other posts. 


Circuit Diagram:

IDE used : MPLAB from Microchip

Code:

Project snippet:


main.h :

#include
#define XTAL_FREQ 16000000

__CONFIG(0x2f0a);

void main(void);


main.c :

#include"main.h"
void main(void)
{
T1SYNC=1;
T1CKPS1=0;
T1CKPS0=0;
T1OSCEN=0;
TMR1CS=0;
TMR1ON=1;

TRISB =0x00;
TRISC=0;

RB1=0;
unsigned int count=0,time,i;
i=61;
while(1)
{	count=0;
	PORTB=0xff;	
	PORTC=0xff;
		
while(count<i)
	{	
		TMR1ON=1;
		while(TMR1IF!=1);
		TMR1IF=0;
		count++;
		TMR1ON=0;
	}
	PORTB=0x00;
	PORTC=0x00;

	count=0;
	while(count<i)
	{
		TMR1ON=1;
		while(TMR1IF!=1);
		TMR1IF=0;
		count++;
		TMR1ON=0;
	}
}	
}



Download the code from here



Related Tutorials