ipunished
Junior Member level 3
- Joined
- Mar 15, 2011
- Messages
- 31
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Location
- United Kingdom
- Activity points
- 1,504
Im trying to write code so that when timer0 reaches zero it check port b if any button is pressed, it should do this every 5 ms.. but im having confusions in this
I was reading up on timers and found this code in a book:
I believe this just raised more questions, and id appreciate it if someone could explain a few things to me.
first off why are the seconds defined when they are not even used?
also where in the code do we tell the microcontroller where to count from, i mean under what conditions will the T0IF flag get enabled?
also how does the compiler know to go to interrupt() when it gets interrupted as we did not tell it to do so in our main.
furthermore how can I modify this program to work for me.
Thank you
I was reading up on timers and found this code in a book:
Code:
#include<system.h>
void config(void);
void interrupt(void);
unsigned char seconds;
void main()
{
config();
while(1);
}
void config(void)
{
trisa=0xff;
trisb=0x00;
portb=0;
//now setting up timer0
clear_bit(option_reg,T0CS);
clear_bit(option_reg,PSA);
set_bit(option_reg,PS0);
clear_bit(option_reg,PS1);
set_bit(option_reg,PS2);
//enabling interrupts
set_bit(intcon,T0IE);
set_bit(intcon,GIE);
}
void interrupt(void)
{
portb++;
clear_bit(intcon,T0IF);
}
I believe this just raised more questions, and id appreciate it if someone could explain a few things to me.
first off why are the seconds defined when they are not even used?
also where in the code do we tell the microcontroller where to count from, i mean under what conditions will the T0IF flag get enabled?
also how does the compiler know to go to interrupt() when it gets interrupted as we did not tell it to do so in our main.
furthermore how can I modify this program to work for me.
Thank you