lloydi12345
Member
Hi, first of all it's my first time to use TMR1. I used TMR0 but as an external input interrupt so I really have no idea how to use TMR registers for timers or counters. I would like to make a 1 sec delay and portb will show it. Can you teach me about the calculations? I've read the datasheet and a lot of information from other websites but I can't understand them all. So far I managed to blink LEDs but I wanted to know how to exactly calculate time based from my internal clock. As far as I know, I need to place counters for me to increase the time but don't know how to start since I can't understand fully the calculations needed. Here's what I've started. Please help me to continue this.
Thank you for your time reading this thread.
Code:
void interrupt(void){
if (PIR1.TMR1IF){ //Let me use this even if no other interrupts are enabled
PORTB = ~PORTB; //To show the output
TMR1L = 100; //TMR1 start time
TMR1H = 90;
PIR1.TMR1IF = 0; //reset timer1 flag
}
}
void main() {
portb = 0x00;
trisb = 0x00;
T1CON.TMR1CS = 0; // Fosc / 4
T1CON.T1CKPS1 = 1; // Setting prescale value to 1:8
T1CON.T1CKPS0 = 1; // "
TMR1L = 100; //TMR1 start time
[COLOR="Red"] TMR1H = 90; <<--------- If I change this one to 88 why is it not blinking anymore
[/COLOR]
PIE1.TMR1IE = 1;
INTCON.PEIE = 1;
INTCON.GIE = 1;
T1CON.TMR1ON = 1; //turn on timer1
while(1){
}
}
Thank you for your time reading this thread.
Last edited: