| ??? 08/07/06 11:40 Read: times |
#121787 - The best way: Responding to: ???'s previous message |
Use a free running timer to generate delays:
#include <reg51.h>
// T0 must be running in mode 1
unsigned int read_t0_on_the_fly( void )
{
unsigned char tl, th;
th = TH0;
tl = TL0;
if( (tl & 0x80) == 0 )
th = TH0;
return tl | th << 8;
}
void delay_us( unsigned int t ) // 20 ... 60000us at 12MHz
{
unsigned int d = read_t0_on_the_fly();
while( read_t0_on_the_fly() - d < t );
}
Peter |



