### Implementing Short Delays

/* Program SHORT_TM.C
**
** When interfacing with the Dallas 1-W family, delays of 60 us and
** 500 us are required. Clearly, the TurboC delay function cannot be
** used.
**
** The following routine uses a delay of the form;
**
** for (n=100; n>0; n--) ;
**
** Note that P2.0 is toggled with a delay of the form shown. The period
** was measured as 1.51 kHz or 662 usecs. As there are two such delays,
** 331 usecs or 3 us per. The conclusion is that a rule of thumb is that
** to obtain a short delay of nominally 60 us, a delay of the form;
**
** for (n=20; n>0; n--) ;
**
** may be used.
**
** copyright, Peter H. Anderson, Baltimore, MD, Sept, '00
*/
#include <stdio.h>
#include <dos.h>
#define SEG 0xf000
#define P2_OFFSET 0xff10
#define P2 0
#define PM2 1
#define PMC2 2
void main(void)
{
int n;
unsigned char far *p2;
p2 = MK_FP(SEG, P2_OFFSET);
*(p2+PMC2) = 0x00; /* not special purpose */
*(p2+PM2) = 0xfe; /* least sig bit is an output */
while(1)
{
*p2 = 0x01; /* flash the LED on least sig bit of p2 */
for (n=100; n>0; n--) ;
*p2 = 0x00;
for (n=100; n>0; n--) ;
}
}