C8051F120 timer Problem

Hi frnds,

I am using Silabs C8051F120, I wanted to have timer delay of 1-msec (One milli second), Since both timers 0 & 1 are used for som application.

I had left with Timers 2,3,4 , so i used timer 2 for calculating delay of 1 msec, which can be called specified number of times * 1 Msec., I am polling for Timer 2 overflow flag TF2.., but som how the code is not working..,

I have used Timer 2 , 16 bit timer with compare capture mode., If there is any solution to this problem , plz let me know..

code:


//-----------------------------------------------------------------------------
// Timer2_ms
//-----------------------------------------------------------------------------
//
// Configure Timer-2 to delay <ms> milliseconds before returning.
//
                void Timer2_ms (unsigned char ms)
                {
                   unsigned char xdata i;             // millisecond counter

                   char SFRPAGE_SAVE = SFRPAGE;     // Save Current SFR page

                   SFRPAGE = 0x00;
                   SFRPAGE = TIMER01_PAGE;

                   TMR2CN = 0x00;
                   TMR2CF = 0x00;
                   RCAP2L = 0xCA;
                   RCAP2H = 0xEF;
                   TMR2L  = 0xCA;
                   TMR2H  = 0xEF;

                           for (i = 0; i < ms; i++)
                           {                                                   // count microseconds
                              TR2    =0;                   // STOP Timer0
                              TR2    =1;                   // START Timer0
                              while(TF2 == 0);             // wait for overflow
                              TR2    =0;                   // Stop Timer 0
                                  TF2    =0;                               // clear overflow indicator

                           }
                           SFRPAGE = SFRPAGE_SAVE;          // Restore SFR page

           }

// Calling Function:

                     SFRPAGE = TIMER01_PAGE;
                   Timer2_ms (10);



With Regards,

Rajesh

More questions in this forum