Hi All,
I am facing issue in toggling led for 1 second using timer0,
led is connected to RB7 of PIC18f.
Though i can insert delay_ms(1000); and toggle led i wish to do it using timer and interrupt.
Here is my code :
#code
#code
Any thing wrong in the code....?
Please suggest
I am facing issue in toggling led for 1 second using timer0,
led is connected to RB7 of PIC18f.
Though i can insert delay_ms(1000); and toggle led i wish to do it using timer and interrupt.
Here is my code :
#code
Code:
void main()
{
ADCON1 = 0x0F; // Disable Analog functions
ANSELA=0;
ANSELB=0;
TRISB = 0x00;
PORTA = 0x00;
T0PS2_bit = 1; // 256 prescalar
T0PS1_bit = 1;
T0PS0_bit = 1;
PSA_bit = 0; // source from FCPU 5MHz
T0CS_bit = 1; // Counter mode and
T08BIT_bit = 1; // 8 bit mode
TMR0IE_bit=1; //Enable TIMER0 Interrupt
PEIE_bit=1; //Enable Peripheral Interrupt
GIE_bit=1; //Enable INTs globally
TMR0ON_bit=1; //Now start the timer!
TMR0ON_bit = 1; // Timer0 is on
TRISB = 0b01111111; // 7 bit is output and rest are input
while(1); // Infinite Loop
}
void InitTimer0()
{
T0CON = 0x86;
TMR0H = 0x67;
TMR0L = 0x69;
GIE_bit = 1;
TMR0IE_bit = 1;
}
void Interrupt(){
if (TMR0IF_bit){
TMR0IF_bit = 0;
TMR0H = 0x67;
TMR0L = 0x69;
//Enter your code here
counter++; //Increment Over Flow Counter
if(counter == 76 )
{
//Toggle RB7 (LED)
if(RB7==0)
PORTB.F7 = 1;
else
PORTB.F7=1;
counter=0; //Reset Counter
}
//Clear Flag
TMR0IF_bit=0;
}
}
Any thing wrong in the code....?
Please suggest