Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
04/04/10 14:08
Read: times


 
#174826 - P89V51RD2 Timing
Hi, I am having lots of trouble with using Timer 0 on the P89V51RD2 to interrupt every 1 second. I want to use it in Mode 2 (set it and forget it). I am driving it at 18.432 MHz

Here is the code, note that ?? = the number I can't calculate


void timer0 (void) interrupt 1 using 1 {
    if (++cycle == 10000) {
       secs++;
       printf("time = %in",secs);
    }

}

void main()
{
    TH0 = (unsigned char) ??;
    TL0 = (unsigned char) ??;
    TMOD = TMOD | 0x02;
    TR0 = 1;
    ET0 = 1;
}


 


I would also like to have a wait function using Timer 1 so that I can introduce small delays into the code independent of the overall 1 second Timer 0. Something like this:


void Wait(unsigned char t) 
{
    unsigned char c;
    for (c=0;c<t;c++) 
    {
         TH1 = ??;
         TL1 = ??;
         TR1=1;
         TF1=0;
         while (TF1==0);
         TR1 = 0;
     }
}


 


Could someone please guide me through the calculations of the TH0 and TL0 in both cases? What mode should I use for the wait function (e.g. to wait for periods less than a second e.g. 50ms)

Many many thanks!


List of 2 messages in thread
TopicAuthorDate
P89V51RD2 Timing            01/01/70 00:00      
   Duplicate thread            01/01/70 00:00      

Back to Subject List