timer1 overflow interrupt by using 20Mhz cystal Pic16f877a

Status
Not open for further replies.

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?
 

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.
 

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.
 
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…