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

    STRESS METER
    Frequency Locked Loop for HF
    1 GHz Frequency Counter
    Power-line frequency meter
    Automatic Tr Switch Circuit
    Misc. Circuits
    Standalone Circuit Converts Square Waves To Sine Waves
    AVR 1.1V Internal ADC Reference Over-Voltage
    microcontroller driving a relay with transistor and Opto-isolator
    bridge
    TDA2030 200 watt amp low cost audio power amplifier
    2 line intercom plus a telephone changeover switch
    receiver circuits
    pyro rf transmitter 27mhz
    LIGHT SENSITIVE AUDIO OSCILLATOR



    Top