[Ajuda] Utilizar Timer PIC16F877A

Olá galera não estou conseguir ajudar o timer do PIC16F877A, estou utilizando cristal de 4MHz e necessito que a cada 1 segundo seja incrementado a variável "segundo".
Segue o código até o momento, encontrei alguns exemplos de implementação do timer, mas acabou não dando certo.
Segue o código até o momento, encontrei alguns exemplos de implementação do timer, mas acabou não dando certo.
- Código: Selecionar todos
#define A_incre portd.f0
#define B_decre portd.f1
#define C_start portd.f2
char segundo, unidade_segundo, dezena_segundo, minuto;
//========================ATUALIZAÇÃO DISPLAY 7 SEGMENTOS=======================
void imprime_display (char posicao, char valor)
{
portb=valor;
if (posicao==1) //UNIDADE SEGUNDO (CI4511 U3) PINO26
{
portc.f7=0;
delay_ms(1);
portc.f7=1;
}
else if (posicao==2) //DEZENA SEGUNDO (CI4511 U2) PINO25
{
portc.f6=0;
delay_ms(1);
portc.f6=1;
}
else if (posicao==3) //MINUTO (CI4511 U1) PINO24
{
portc.f5=0;
delay_ms(1);
portc.f5=1;
}
}
//=======================FIM ATUALIZAÇÃO DISPLAY================================
//=========================ATUALIZAÇÃO DISPLAY TIMER============================
void imprime_timer (char posicao, char valor)
{
portb=valor;
if (posicao==1) //UNIDADE SEGUNDO (CI4511 U3) PINO26
{
portc.f7=0;
delay_ms(1);
portc.f7=1;
}
else if (posicao==2) //DEZENA SEGUNDO (CI4511 U2) PINO25
{
portc.f6=0;
delay_ms(1);
portc.f6=1;
}
else if (posicao==3) //MINUTO (CI4511 U1) PINO24
{
portc.f5=0;
delay_ms(1);
portc.f5=1;
}
}
//=======================FIM ATUALIZAÇÃO DISPLAY TIMER==========================
//================================TIMER 1=======================================
void interrupt()
{
if (PIR1.TMR1IF)
{
segundo--;
if (segundo==255)
{
minuto--;
segundo=59;
}
dezena_segundo = segundo/10;
unidade_segundo = segundo - segundo/10*10;
imprime_timer (3,minuto);
imprime_timer (2,dezena_segundo);
imprime_timer (1,unidade_segundo);
PIR1.TMR1IF = 0; //reset timer1 flag
TMR1L = 0xEC ;
TMR1H = 0x78;
}
}
//=============================FIM TIMER 1======================================
void main()
{
trisa=0;
trisb=0;
trisc=0;
trisd=0b11111111;
porta=0;
portb=0;
portc=0;
portd=0;
minuto=0;
segundo=0;
while (1)
{
//============================BOTAO "A" INCREMENTO=============================
while (A_incre==0)
{
if (minuto==9 && segundo==59)
{
}
else
{
delay_ms (100);
segundo++;
if (segundo==60 && minuto<9)
{
minuto++;
segundo=0;
imprime_display (3,minuto);
}
dezena_segundo = segundo/10;
unidade_segundo = segundo - segundo/10*10;
imprime_display (3,minuto);
imprime_display (2,dezena_segundo);
imprime_display (1,unidade_segundo);
}
}
//============================FIM INCREMENTO===================================
//==========================BOTAO "B" DECREMENTO===============================
while (B_decre==0)
{
if (minuto==0 && dezena_segundo==0 && unidade_segundo==0)
{
break;
}
else
{
delay_ms(100);
segundo--;
if (segundo==255 && minuto>0)
{
minuto--;
segundo=59;
imprime_display (3,minuto);
}
dezena_segundo = segundo/10;
unidade_segundo = segundo - segundo/10*10;
imprime_display (3,minuto);
imprime_display (2,dezena_segundo);
imprime_display (1,unidade_segundo);
}
}
//============================FIM DECREMENTO===================================
//========================BOTAO "START" CRONOMETRO=============================
if (C_start==0)
{
T1CON.TMR1CS = 0; // Fosc / 4
T1CON.T1CKPS1 = 1; // Setting prescale value to 1:8
T1CON.T1CKPS0 = 1; // "
T1CON.TMR1ON = 1; //turn on timer1
TMR1L = 0xEC ;
TMR1H = 0x78;
PIE1.TMR1IE = 1;
PIR1.TMR1IF = 0;
INTCON.PEIE = 1;
INTCON.GIE = 1; // Enable interrupt on overflow
}
//============================FIM CRONOMETRO===================================
}//fim while (1)
}//fim void main