variable delay in PIC16F877A

Thread Starter


Joined May 13, 2022
i have a code in (PIC16F877A) i made a delay for one sec and i need to make a traffic light so the delay between each of them is deferent so for example for red i need delay 5 sec but i do not want to call delay five time like this ,call delay,call delay,call delay,call delay, what is the best way to make 5 sec delay in this situation .

Moderators note : changed font size, as large fonts are like screaming.


Joined Feb 24, 2006
Easiest way is to modify the existing function so you can pass it a value and it will implement a delay of that value. What language the code is written in is irrelevant, since you can implement this strategy in any coding paradigm that you happen to have.


Joined Apr 2, 2020
If you are using assembly, the strategy is different than listed above, but "different" is in the eye of the beholder. It's not much different but I'm guessing different enough because you are asking here. As was asked above, which language are you using.


Joined Oct 2, 2009
Function call is
call delay

Parameters can be passed via a register, variable, or on the stack.
For a simple function call, pass the parameter via a CPU register.