Understanding Delay Loops: PIC Tutorial 3

There may be a minor downside of our flashing LED program. Every instruction needs 1
clock sequence to finish. In case we are utilizing a 4MHz crystal, then every instruction calls for
1/4MHz, or 1uS to finish.


PIC Tutorial – 2............................................ PIC Tutorial - 4

Since we have been employing just five instructions, the LED would activate then off in 5uS. This could be much too rapid for folks to notice, in addition, it will seem that the LED is fully on. What we should instead accomplish is produce a inhibition between switching the LED on and turning the LED off. The theory of the inhibition is that we count down from a earlier quantity, so when it gets to zero, we quit counting. The zero value signifies the conclusion of the delay, and we keep working our process throughout the program. Therefore, the firstly we must do is to determine a constant to make use of as our counter. Let us term this constant COUNT. After that, we must determine how significant a number to begin counting from. Surely, the biggest figure we could include is 255, or FFh in hex., as I talked about in the earlier tutorial, the equ instruction assigns a expression to a register situation. This implies that no matter what quantity we allocate our COUNT, it would match the items of a register. In case we try to designate the value FFh, we are going to get a mistake once we get to compile the program. The reason being the location FFh is , therefore we can’t gain access to it. Therefore, how must we designate a genuine number? Certainly, it will require a small amount of lateral pondering. If perhaps we designate our COUNT to the address 08h, for instance, this would indicate a basic objective register destination. By default, the untouched areas are set to FFh. Consequently, if COUNT leads to 08h, you will encounter the value of FFh while we first power up. Nevertheless, I you, how can we fix COUNT to another number?, all we apply is ‘move’ a valuation to this destination first. As an illustration, suppose we wished for COUNT to possess a value of 85h, we can’t mention COUNT equ 85h since that is the position of out Tri-State register for Port A. Precisely what we accomplish is the following: movlw 85h;First put the value of 85h in the W register movwf 08h;Now move it to our 08h register. Subsequently, in case we express COUNT equ 08h, COUNT would match the value 85h. Delicate, isn’t it! Therefore, initially we determine our constant: COUNT equ 08h Following we must reduce this COUNT by one until it becomes zero. It simply so occurs that there exists one instruction designed to accomplish this for us, by making use of a ‘goto’ and a tag. The instruction we are going to apply is: DECFSZ COUNT,1 This instruction states ‘Decrement the register (here it's COUNT) by the number that tracks the comma. If we attain zero, hop two spots ahead.’ Lets find it in action first, before we place it into our course.


What we have performed is initially establish our constant COUNT to 255. The subsequent segment positions a tag, called LABEL close to our decfsz instruction. The decfsz COUNT,1 reduces the value of COUNT by one, and retains the end result straight into COUNT. Moreover it verifies to check if COUNT possesses a value of 0. If it doesn’t, it in that case triggers the program to shift to the subsequent line. Now we have a ‘goto’ declaration which delivers us back to our decfsz instruction. In case the value of COUNT performs equal , then the decfsz instruction results in our program to leap 2 spots ahead, and is sent to where We have claimed ‘Carry on here’. Therefore, since you can observe, we have brought about the program to sit in one spot for a predestined time before proceeding. This could be named a delay loop. In case we require a more substantial delay, we could pursue one loop by the next. The extra loops, the extended the delay. Let us at least two, assuming we want to observe the LED flash.. We will place these delay loops into our program, and accomplish by rendering it a genuine program by introducing comments:








It is possible to compile this program after which program the PIC. Obviously, be sure that you attempt
the circuit out to check if it does indeed function. The following is a circuit diagram that you should construct as soon as you have programmed the PIC.




Well done, you could have actually composed your first PIC program, as well as constructed a circuit to blink
an LED on and off. Until now, in case you have ensued these courses, you might have learned an overall of
seven instruction out of 35, but without doubt so far you might be controlling the I/O ports!
Would you attempt to change the delay loops to render the LED flash quicker – what appears the
minimal value of COUNT to essentially see the LED flash? Or maybe, you will want to include a 3rd or
supplementary delay loops after the initial one to stabilize the LED down. a
unique constant for each delay loop. You could potentially then actually fiddle with your delay loops to
render the LED flash at a specific speed, for instance after a second.
Within the next instructional let us see how we are able to utilize something known as a subroutine to maintain
the program compact and basic

0 Response to "Understanding Delay Loops: PIC Tutorial 3"

Posting Komentar