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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
05/29/05 06:20
Read: times


 
#94077 - Delay
Responding to: ???'s previous message
These SW delays will not be accurate and vary depending on how the compiler handles a construct. Accurate way is to use interrupt (of course the interrupt latency has to be accounted).
Following is an example.

void delay(unsigned int time_1ms)
{
if (time_1ms)
{
DELAY_count = time_1ms; // Set global delaytime
delay_on = 1 ;

while ( DELAY_count > 0 ) { ; } // Wait delaytime
delay_on = 0 ;
return;
}
}

void timer1_init(void)
{
TMOD &= 0x0f; /* set timer mode */
TMOD |= 0x10;
TL1 = _1msec; /* _1msec is a constant no of */
TH1 = _1msec >> 8 ; /* cycles ex. 12 MHz = 64536 */
TF1 = 0 ;
TR1 = 1 ;/* turn on timer */
ET1 = 1; /* set timer interrupt flag */
PT1 = 1;
EA = 1; /* enable the interrupts */
}

void int_t1( void ) interrupt 3
{
ET1 = 0; // Disable Timer0-interrupt
TF1 = 0 ;
TL1 = _1msec;
TH1 = _1msec >> 8 ;
ET1 = 1 ;
EA = 1; /* enable the interrupts */
if (delay_on)
{
if ( DELAY_count > 0 )
DELAY_count--; // Timebase ticks for delay-routine
}
}

hope this helps.


List of 22 messages in thread
TopicAuthorDate
Keil: getting input            01/01/70 00:00      
   If it works in ASM it Works in C            01/01/70 00:00      
      Why C?!            01/01/70 00:00      
         Irrelevant            01/01/70 00:00      
         Of Course            01/01/70 00:00      
   key scan            01/01/70 00:00      
      Delay..            01/01/70 00:00      
         Delay            01/01/70 00:00      
         Software Delay Loops            01/01/70 00:00      
            Software Delay Loops            01/01/70 00:00      
   Learning 'C'            01/01/70 00:00      
   to be precise..            01/01/70 00:00      
      Debounce            01/01/70 00:00      
         completely missed it..            01/01/70 00:00      
      to be precise...            01/01/70 00:00      
         Sorry Leo !            01/01/70 00:00      
         Inferences            01/01/70 00:00      
            Right answer, wrong reason            01/01/70 00:00      
               and therefore            01/01/70 00:00      
            Congratulations            01/01/70 00:00      
               to: Raghu Sir            01/01/70 00:00      
      BIts!            01/01/70 00:00      

Back to Subject List