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.
Why delays exist
Section titled “Why delays exist”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.
Two methods
Section titled “Two methods”| Method | How | Advantage | Limitation |
|---|---|---|---|
| Software | DECFSZ + BRA loops | Simple; partial exam focus | CPU stays busy in the loop |
| Hardware (Timer) | Timer + optional ISR | CPU can do other work | More setup (Timer 0) |
Partial II emphasizes software delays and Delay = CM × Σ CI.
What the CPU does during a software delay
Section titled “What the CPU does during a software delay”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.
Basic flow
Section titled “Basic flow” Start | v Counter = N | v +--> DECFSZ | | | zero? -- yes --> Done | | | no -> BRA back +------+RAM variables
Section titled “RAM variables”CONTADOR RES 1 ; one byte: 0..255Subroutine + CALL pattern
Section titled “Subroutine + CALL pattern” CALL RETARDO_CORTORETARDO_CORTO MOVLW .200 MOVWF CONTADORBUCLE DECFSZ CONTADOR,F BRA BUCLE RETURNEach CALL adds 2 cycles when counting Σ CI.
Section path
Section titled “Section path”| Step | Page | Goal |
|---|---|---|
| 1 | This page | Concepts + intro quiz |
| 2 | Machine cycles | CM, Table 4.1 |
| 3 | Delay loops | Nested loops |
| 4 | Calculation | 3 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?
Introduction quiz
Section titled “Introduction quiz”Check your understanding before formulas and machine cycles.
Introduction — Software delays
Based on: Clase Tema 4 y 5.pdf
0 of 0 answered
Sign in with CALETAS to sync this result across devices.
Sign in with CALETAS