Delay Loops


Posted on Feb 5, 2014

There is one slight drawback to our flashing LED program. Each instruction takes one clock cycle to complete. If we are using a 4MHz crystal, then each instruction will take 1/4MHz, or 1uS to complete. As we are using only 5 instructions, the LED will turn on then off in 5uS. This is far too fast for us to see, and it will appear that the LED is perma


Delay Loops
Click here to download the full size of the above Circuit.

nently on. What we need to do is cause a delay between turning the LED on and turning the LED off. The principle of the delay is that we count down from a previously set number, and when it reaches zero, we stop counting. The zero value indicates the end of the delay, and we continue on our way through the program. So, the first thing we need to do is to define a constant to use as our counter. We will call this constant COUNT. Next, we need to decide how big a number to start counting from. Well, the largest number we can have is 255, or FFh in hex. Now, as we mentioned in the last tutorial, the equ instruction assigns a word to a register location. This means that whatever number we assign our COUNT, it will equal the contents of a register. If we try and assign the value FFh, we will get an error when we come to compile the program. This is because location FFh is reserved, and so we can`t access it. So, how do we assign an actual number Well, it takes a little bit of lateral thinking. If we assign our COUNT to the address 08h, for example, this will point to a general purpose register location. By default, the unused locations are set to FFh. Therefore, if COUNT points to 08h, it will have the value of FFh when we first switch on. But, We hear you cry, how do we set COUNT to a different number Well, all we do is move` a value to this location first. For example, if we wanted COUNT to have a value of 85h, we can`t say...




Leave Comment

characters left:

New Circuits

.

 


Popular Circuits

Speed Controler for R/C Models
Timer LM555 Circuits
Simple Li-Ion Battery Charger
PIC18 programmer
Transmission indicator
80W-3-30mhz-amplifier
Ups 5Volt Circuit
ancient baudot teletype interface
the modern firepower pinball project
mini logger circuit
10A H-Bridge Motor Controller Circuit
Photoelectric controller circuit immunity



Top