hi
I need some help regarding Internal Oscillator
i m posting my code below
void timer_int(void)
{
T0CON = 0b11011111; //Prescaler not assigned
TMR0L=253;
OSCTUNE = 0;
OSCCON= 0b01111110; //Internal 8MHz Oscilator as primary Oscillator
INTCONbits.TMR0IE=1;
RCONbits.IPEN = 1; //enable priority levels
INTCONbits.GIEH = 1; //enable interrupts
}
#pragma code
#pragma interrupt InterruptHandlerHigh
void InterruptHandlerHigh( )
{
if (INTCONbits.TMR0IF)
{
LED_Flag++;
INTCONbits.TMR0IF=0;
}
}
void main(void)
{
LATB = 0x00;
TRISB = 0x00;
timer_int();
while (1)
{
if( LED_Flag==6) //LED Will Glow after every 1 Sec delay
{
LED1=!LED1;
LED_Flag=0;
}
}
//**********************************************************************
//#define CLOCK_FREQUENCY 8000000 //8MHz
//Note: 1 INST Cycle = ((1/ CLOCK_SPEED) * 4) = (1/8000000)*4 = 0.5Us
//
//TMR0 will overflow after (0x00-0xFF),so 1 INST cycle= 0.5*2 = 1 usec
//
//timer0 1 overflow will generate 1us delay ,so TMR0L=253;
//**********************************************************************
According to above calculation i should get delay of 6 us everytime when LED_FLag=6...but i m not getting the delay of 6 us,instead i m getting 1ms delay....can you please let me know where the problem is???
thanks in advance!!!!