2 Attachment(s)
Problem with TIMER0 Interrupt
Hi,
I execute the following lines of code and
expect me that the program will deliver a 1Hz
pulse train on PIN RA2. the problem is that
I only get 6 pulses from RA2 (LED). I Send you
an image of the simulation. Can you see anything
wrong?
Thank you!Attachment 16283
Code:
#include <pic.h>
#include <htc.h>
void Initialization ();
__CONFIG(FOSC_LP & WDTE_ON & PWRTE_OFF & CP_OFF);
#define _XTAL_FREQ 32768
#define LED RA2
int S = 0;
void main()
{
Initialization ();
while (1)
{
if (S)
{
S=0;
LED = 1;
__delay_us (1);
LED = 0;
}
}
}
void Initialization(void)
{
TRISA = 0b00000000;
TRISB = 0b00000001;
OPTION_REG = 0b00000100;
INTCON = 0b10100000;
TMR0 = 0;
LED = 0;
}
void interrupt tc_int(void)
{
if (T0IF)
{
T0IE = 0;
S = S+1;
T0IF = 0;
T0IE = 1;
TMR0 = 0;
}
}