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:

Related Circuits

  • New Circuits

    .

     


    Popular Circuits

    Self oscillating flyback converter
    555 Astable oscillator
    Strobe Light circuit
    Car Anti-Theft Wireless Alarm
    PLL1706DBQ 3.3-V DUAL PLL MULTICLOCK GENERATOR
    TDA2555 Dual Tv Sound Demodulator Circuits - Nxp Semiconductors
    89 S10 Starter wiring Snafu
    Synchronous Dual Mode Phase Modulated Full Bridge Controllers
    One-way operation of the brake circuit reverse



    Top