We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Can someone help with a code snipet for a fixed delay subroutine using DR1 in memory 20h using a 4Mz crystal
Machine instructions are excellent for fixed delays. Especially short delays where the requirement is "must wait at least x ns/us" - such as when pacing some I/O with a slower external device.
When the delay gets long, it's often not so fun with a busy-loop since the processor can't do anything else. Letting a timer do the delay (maybe not the full delay span but at least suitably long sub-delays of maybe 1ms or 10ms) means the "main loop" can continue to update blinking LED concurrently with looking for key presses etc.
If doing longer busy-loops, it's way better to not count machine cycles but looking at a timer or similar - then it doesn't matter if the processor has 20% CPU load in ISR during the delay. The delay loop will "auto-compensate" for machine cycles spent in the ISR. Often other peripherial hardware can also be used to measure time - such as an unused SPI/UART/xx where the baudrate gives a fixed time until the data has been clocked out and the "I'm hungry" bit gets set again.
Madame Westermark,
You are one very smart lady.