Timer2 of PIC16F877

Thread Starter

ecaits

Joined Jan 6, 2014
56
Dear Friends,

I am working on TImer 2 of PIC16F877.

Code is given below.

Rich (BB code):
void main()
{
	TRISB0 = 0;
	RB0 = 0;
	inittimer2();

	while(1)
	{
	}
}

void inittimer2(void)
{	
	TMR2 = 0x00;
	T2CON = 0x75;  // Prescaler 4, Postscaler 
	TMR2IF = 0;
	TMR2IE = 1;
	PR2 = 0xFF;
	
}

void interrupt ISR(void)
{
	if(TMR2IF)
	{
		RB0=~RB0;
		TMR2IF=0;
	}
}
But this code is not working.
Can anybody suggest what may be the problem???
 
Last edited by a moderator:

tshuck

Joined Oct 18, 2012
3,534
I don't see GIE nor PEIE (see INTCON register, page 24 of the datasheet) being set - these are required to use interrupts and use peripheral interrupts.

Please put your code between some code tags ([ code]//code goes here[/code ] - without the spaces), as this allows the code to be formatted nicer by the forum software.
 
Top