Reputation: 11
i wrote a code in mikroc for pic16f877A in which i have used a timer0 and timer1. i debug my code and found that timer0 is not working but i am not able to understand the reason behind it. I even checked datasheet for the OPTION_REG but couldn't figure out the problem plz help. i am new to pic programming. I just uploaded the function in which timer0 and timer1 is setup. UART is used to check whether each line is getting executed and i found after printing the value of TMR1H it stops .
int feedback()
{
sh = 0;
UART1_WRITE_TEXT("inside feedback");
UART1_Write(13); // newline
TMR0=193;
Uart1_Intout_ReturnInt(TMR0);
UART1_Write(13); // newline
INTCON=0xA0;
Uart1_Intout_ReturnInt(INTCON);
UART1_Write(13); // newline
TMR1L=0;
Uart1_Intout_ReturnInt(TMR1L);
UART1_Write(13); // newline
TMR1H=0;
Uart1_Intout_ReturnInt(TMR1H);
UART1_Write(13); // newline
OPTION_REG.PSA=0;
OPTION_REG.PS2=0;
OPTION_REG.PS1=1;
OPTION_REG.PS0=0;
OPTION_REG.T0SE=0;
OPTION_REG.T0CS=0;
UART1_WRITE_TEXT("timer0 start");
UART1_Write(13); // newline
T1CON=0x07;
UART1_WRITE_TEXT("timer1 start");
UART1_Write(13); // newline
sh=1;
Uart1_Intout_ReturnInt(sh);
UART1_Write(13); // newline
while(sh==1){
Uart1_Intout_ReturnInt(sh);
UART1_Write(13); // newline
UART1_WRITE_TEXT("inside while loop");
}
UART1_WRITE_TEXT("outside while loop");
TMR1H=TMR1H*1000;
sh=TMR1H+TMR1L;
actualOut=(60*2*sh)/8;
Uart1_Intout_ReturnInt(actualOut);
UART1_Write(13); // newline
return actualOut;
}
void interrupt(){
T1CON=0x00;
sh=0;
}
Upvotes: 1
Views: 901
Reputation: 700
You're enabling the TMR0 interrupt in the line INTCON=0xA0;
but I don't see an interrupt service routine for it. The interrupt is probably triggering after the lines that do work and then is remains asserted because the TMR0IF interrupt flag (INTCON bit 2) is not being cleared.
Upvotes: 1