shreyas_patel21
Full Member level 3
how to generate 1 us time delay using timer module of pic
i have the code for it
here it is
void delay(unsigned int us)
{
unsigned int x;
T1CON=0x0000;
for(x=0;x<us;x++)
{
TMR1=0x0000;
T1CON=0x8010; //timer 1 enable with prescale of 1:8
while(TMR1<0x02);
T1CON = 0x0000;
}
}
can anyone explain me why 0x02 is chosen for 1 us in TMR1.?
i have the code for it
here it is
void delay(unsigned int us)
{
unsigned int x;
T1CON=0x0000;
for(x=0;x<us;x++)
{
TMR1=0x0000;
T1CON=0x8010; //timer 1 enable with prescale of 1:8
while(TMR1<0x02);
T1CON = 0x0000;
}
}
can anyone explain me why 0x02 is chosen for 1 us in TMR1.?