Skip to content

Software delays

Blinking an LED every 1 second, holding a display digit for 10 seconds (partial exam pump problem), or debouncing a button all require delays. This section covers software delays: the MCU runs a loop until counter(s) in RAM reach zero.

This page is the entry point. After reading it and passing the quiz below, you should know what a software delay is, when to use it, and how it connects to the rest of the section and Partial II.

Without an explicit wait:

  • An LED toggled too fast looks always on.
  • A display digit is unreadable.
  • A button bounces and registers multiple false presses.

A delay slows the program for a known (or calculated) time.

MethodHowAdvantageLimitation
SoftwareDECFSZ + BRA loopsSimple; partial exam focusCPU stays busy in the loop
Hardware (Timer)Timer + optional ISRCPU can do other workMore setup (Timer 0)

Partial II emphasizes software delays and Delay = CM × Σ CI.

The MCU repeats decrement-and-branch until the counter hits zero. It does not run the rest of your main code during that wait (unless interrupts intervene).

  • Not multitasking in the same thread.
  • Fine for LED blink, digit hold, short debounce.
  • Long waits (10 s pump problem) need nested loops or repeated CALLs — see Loops.
Start
|
v
Counter = N
|
v
+--> DECFSZ
| |
| zero? -- yes --> Done
| |
| no -> BRA back
+------+
CONTADOR RES 1 ; one byte: 0..255
CALL RETARDO_CORTO
RETARDO_CORTO
MOVLW .200
MOVWF CONTADOR
BUCLE
DECFSZ CONTADOR,F
BRA BUCLE
RETURN

Each CALL adds 2 cycles when counting Σ CI.

StepPageGoal
1This pageConcepts + intro quiz
2Machine cyclesCM, Table 4.1
3Delay loopsNested loops
4Calculation3 ms exam — full quiz

Ejercicio · Parcial

Think

Why can’t a long software delay alone let you poll a sensor every 1 ms and refresh an LCD continuously without interrupts?

Check your understanding before formulas and machine cycles.

Interactive exam

Introduction — Software delays

Based on: Clase Tema 4 y 5.pdf

0 of 0 answered

A software delay on the PIC is typically implemented with...
The two main ways to generate a delay in the course are...
While a software delay runs, the PIC CPU...
The course general software delay formula is...
If you call a delay subroutine with CALL, you must add to the count...

Machine and instruction cycles.