imranahmed
Advanced Member level 3
- Joined
- Dec 4, 2011
- Messages
- 822
- Helped
- 3
- Reputation
- 6
- Reaction score
- 3
- Trophy points
- 1,298
- Location
- Karachi,Pakistan
- Activity points
- 6,533
Use your old INTCONbits.INTF == 1 and use TRISB = 0xFF; PORTB = 0x00; in main() function.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 //Timer1 //Prescaler 1:4; TMR1 Preload = 15533; Actual Interrupt Time : 100 ms //Place/Copy this part in declaration section void InitTimer1(){ T1CON = 0x21; TMR1IF_bit = 0; TMR1H = 0x3C; TMR1L = 0xAD; TMR1IE_bit = 1; INTCON = 0xC0; } void Interrupt(){ if (TMR1IF_bit){ TMR1IF_bit = 0; TMR1H = 0x3C; TMR1L = 0xAD; //Enter your code here } }
how to implement ot how to increase prescaler value for timer1.
Can I use timer0 interrupt it has prescaler rate 1:256?
use clrwdt instruction in the main loopHow to prevent WDT reset on program execution.?
it is the same probleme as with Timer1 .. because timer0 size is 8 bits !
so better capacity of counting with Timer1 : 8 x 65536 =524280 maximum
instead of 256x256=65536 with timer0.
volatile int Sec ; // compteur de secondes
volatile int count;
volatile int Flag;
void InitTimer1(){
T1CON = 0x21;
TMR1IF_bit = 0;
TMR1H = 0x0B; // 3035 => 65535-3035=62500 62500x8x0.5=250000µS=>250mS
TMR1L = 0xDB;
TMR1IE_bit = 1;
INTCON = 0xC0;
}
if (PIR1bits.TMR1IF==1)
{
PIR1bits.TMR1IF=0;
count++;
TMR1H = 0x0B; // you have to load the timer value 18660 in the interrupt routine also
TMR1L = 0xDB;
if (count>4)
{
Flag=1; // one second elapsed used for TMR0 counting
count=0;
Sec ++; // increment secondes
}
}
void main()
{
Sec=0;
count=0;
Flag=0;
InitTimer1(); // IT every 250mS
......
while(1)
{
...
//here test Flag value to detect one second elapsed
//and RAZ the Flag !!
if( Flag==1)
{
// do it every second
Flag=0;
....
....
}
....
}
The code I gave is for 8 MHz Clock frequency.
This is for 100ms timer1 interrupt. Use a counter and increment it in step of one on every interrupt (of 100ms). For counter value = 10 you will have 100ms or 1sec timer.
//Timer1
//Prescaler 1:4; TMR1 Preload = 15533; Actual Interrupt Time : 100 ms
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?