How to Write to the Ports - PIC Tutorial 2


Within the last instructional, we I confirmed you the way to establish the IO port pins on the PIC to be possibly input or output.

PIC Tutorial - 1.....................................PIC Tutorial - 3
Through this course, Let me assist you to send data to the ports. In the subsequent tutorial, we are going to complete by flashing an LED on and off that consist of a complete program detailing and a straightforward circuit diagram so that you could see the PIC performing precisely what we anticipate it to. Don’t attempt to put together and program your PIC with the results below, since they are illustrations only. Initially, we will establish Port A bit 2 as an output:



This could be recognizable from the previous instructional. The sole distinction could be We have fixed every bit of the pins on A as output, by delivering 0h to the tri-state register. So what now he must do is switch an LED on. We accomplish this by scheduling one of the pins (the one with the LED linked to it) high. To put it differently, we apply a ‘1’ to the pin. This is exactly exactly how it’s carried out (observe the comments for a clarification for every line):



Therefore, what now we have accomplished is switch the LED on then off one time. What we desire is for the LED to switch on subsequently off continually. We achieve this by obtaining the program to return to the start. We accomplish this by initially establishing a tag at the outset of our program, thereafter informing the program to proceed back there. We specify a tag quite straightforwardly. We key in a term, say START, next type the code:

As is demonstrated, we initially mentioned the expression ‘Start’ immediately at the outset of the program. Next, at the very finish of the program we plainly mentioned ‘goto Start’. The ‘goto’ instruction performs just what it declares. This program would consistently switch the LED on and off whenever we power up the circuit, tending to switch OFF once we remove electricity. May be we ought to check our program yet again:







Surely we have omitted the comments off, however we can still observe the instructions and the numbers. This can be a slightly puzzling later in case you try troubleshooting the program and while writing the code you've memorize al of the addresses. Although the comments may be be placed still it could become a bit cluttered. This will require naming the numbers and might be accomplished by an additional instruction: 'equ' The 'equ' instruction suggests that some stuff might be equal to another stuff. It may not be an instruction for PIC, rather for the assembler. This instruction facilitates assigning name to a register address location, or a constant to a programming term. We will establish a few constants for our program and also witness how much straightforward it is reading the program.





Since now we have fixed the constant values we may proceed by setting them up into our program. The constant values needs to be designated prior to using them. therefore make sure to always position them at the beginning of the program. We will rewrite the program excluding the comments once again, in order to compare the earlier labeling with the latest one.



May be you are able to notice that the constants are enabling slightly easier understanding of the program, however we are still without the comments, no worries though, since we are not yet finished.

0 Response to "How to Write to the Ports - PIC Tutorial 2"

Posting Komentar