Apr 11, 2014 #1 S Sheritronics Newbie level 6 Joined Feb 1, 2014 Messages 12 Helped 0 Reputation 0 Reaction score 0 Trophy points 1 Activity points 80 Need help! i have to generate 1sec overflow interrupt with timer1 in pic16f877a any special logic?
Apr 12, 2014 #2 C cl10greg Full Member level 3 Joined Mar 29, 2012 Messages 177 Helped 36 Reputation 72 Reaction score 36 Trophy points 1,308 Activity points 2,491 Set your timer prescalar so that it overflows at 1 second (based on whatever clock you are using). Enable interrupts Call interrupt, do action, clear flag.
Set your timer prescalar so that it overflows at 1 second (based on whatever clock you are using). Enable interrupts Call interrupt, do action, clear flag.
Apr 12, 2014 #3 H hemnath Advanced Member level 3 Joined Jun 24, 2012 Messages 702 Helped 61 Reputation 120 Reaction score 57 Trophy points 1,308 Location Chennai Activity points 6,588 Crystal Frequency: 20Mhz Fosc = 20Mhz/4 => 5Mhz Tosc = 1/5Mhz => 0.2us For 1 millisecond, So 1000us/0.2us => 5000 => 0x1388(in HEX) TMR1 = 0xFFFF - 0x1388 => 0xEC77 in interrupt routine you can do something like this, Code C - [expand]1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 if(TMR1IF == 1) // if overflows { variable++; // increments every 1ms if(variable == 1000) // when it reaches 1000ms i.e., 1 sec delay { seconds_variable++; // increment another variable variable = 0; // reset to 0 } } TMR1H = 0xEC; TMR1L = 0x77; TMR1IE = 1; TMR1IF = 0; Hope it helps.
Crystal Frequency: 20Mhz Fosc = 20Mhz/4 => 5Mhz Tosc = 1/5Mhz => 0.2us For 1 millisecond, So 1000us/0.2us => 5000 => 0x1388(in HEX) TMR1 = 0xFFFF - 0x1388 => 0xEC77 in interrupt routine you can do something like this, Code C - [expand]1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 if(TMR1IF == 1) // if overflows { variable++; // increments every 1ms if(variable == 1000) // when it reaches 1000ms i.e., 1 sec delay { seconds_variable++; // increment another variable variable = 0; // reset to 0 } } TMR1H = 0xEC; TMR1L = 0x77; TMR1IE = 1; TMR1IF = 0; Hope it helps.