Hi,

Delays can be implemented by software or by software & timer
depending on the PIC you are using (timer & interrupts available).

If there is interrupt capability (PIC16CXX and not PIC16C5XX),
you can enable TIMER0 interrupt and the interval which the timer interrupts at
will become time quantum for delays. In ISR you can implement a counter (RTClock)
which will increment. And delays will be measured in this counter units.
If you want smaller units, ISR can write to TIMER0 a value that is closer to 0xff.

Instead of TIMER0 you may use TIMER1 and CCP1 in 1010 compare mode that
generates interrupt. CCPR1H:CCPR1L will contain interval measured in 1/(CLOCKIN/4).
ISR should set TMR1L and TMR1H to an appropriate value closer to 0.

A routine performing delay can be defined as
void Delay (char ticks);
and it will count _ticks_ changes of above RTClock
before return to the caller.

If there is no interrupts it is still possible to call (very) often a procedure that will check if
timer0 overflow is occured and if it is to increment RTClock. Here is good idea to have
a guard value, smaller than 0xff and check if timer0 has got above it. It is important
to call this procedure at intervals smaller than the time that TIMER0 needs to pass from
this guard value to 0xff and 0x00.

The delay procedure will have loop with
call to timer0 check routine and
check for RTClock change
and this will repeat until _ticks_changes happen.

these variant are not for very short delays.


Hope this helps.

Ivan Cenov
okto7@botev.ttm.bg