PIC16 Delay Code Generator

Generate nested-loop PIC16 assembly delay routines from crystal frequency and desired delay.

Parameters

Oscillator frequency 1 MHz
Instruction-cycle time 1 µs
Requested delay 1000 ms
Generated delay 1000 µs

Generated PIC16 Assembly


    

Timing Equation

For the 4 MHz example, your equation is:

3 × A1 × A2 × A3 + 4 × A2 × A3 + 4 × A3 + 5

The generator scales the required instruction cycles according to the selected crystal frequency. It searches the three 8-bit loop counters (1–255) for a combination that produces the closest possible delay.

PIC16 classic mid-range devices normally execute one instruction cycle every 4 oscillator periods. The generated routine assumes the same instruction timing used by your example.