Understanding Data Tables: PIC Tutorial 9

There exists a great option in the training set that permits
you to make use of a data table.
A data table is just a list of data quotes, in which all is looked over based
on a few considerations.

PIC Tutorial - 8....................................PIC Tutorial - 10

For instance, you could have a circuit that utilizes a PIC which counts the quantity of instances an input pin becomes high in 1 second. After that you can exhibit the number on a 7 segment display. As soon as the timing has launched, the PIC starts counting the quantity of occasions the pin goes high. After 1 second it visits the table and glances up the data it must display the number on the display that symbolizes the amount of situations the pin got high. This can be beneficial, since we don’t determine what the figure could be until the PIC has accomplished its estimate. By utilizing a table, we are able to allow the PIC determine which figure to portray. At this point, before I continue to show you how the data table functions, I might have to tell you that the PIC maintains path of whereabouts in the program it is whilst the program is operating. It facilitates for those who have performed certain programming in BASIC. Otherwise, don’t be anxious, you might want to continue to learn about the theory. Envision there is a BASIC program similar to the one presented below:

10               LET K=0
11               K=K+1
12               IF K>10 THEN GOTO 20 ELSE GOTO 11
20                     PRINT K
21                     END

The program begins at line 10. As soon as K is scheduled to 0, it next advances to line 11. After we have included 1 to K we after that proceed to line 12. At this point we might be curious if K is higher than 10. In case it is, next we head to line 20, or else we return to line 11. Line 20 documents the K, and line 21 concludes the program. BASIC employs line statistics to assist the programmer keep a record of where issues are, as labels are not authorized. The PIC employs labels to escape between destinations – or can it really? We utilize the labels to ensure that we be aware of where issues are, as well as to ensure we are able to inform the PIC in a simple way where to search. Precisely what occurs is the PIC takes advantage of an inner line counter called a Program Counter. The Program Counter (abbreviated to PC) trail of the memory destination of where the present instruction is. Whenever we inform the PIC to visit a selected label, it understands the memory spot and therefore augments the PC until it sees that memory destination. This is precisely the same method as we check out the BASIC program above. Below is a segment of code, with the memory spaces, or the items of the PC, beside every instruction:

PC Instruction

0000             movlw 03
0001             movwf 0C
0002  Loop    decfsc 0C
0003              goto Loop
0004  end

In the demonstration above, We have fixed the PC to 0000. On this we have the instruction movlw 03. When the PIC has implemented this data, it increments the PC in order that the subsequent instruction is scanned. At this point the PIC views movwf 0C. The PC is incremented yet again. Now the PIC studies decfsc 0C. In case the details of 0C are not 0, in that case the PC is incremented by 1, as well as the following instruction, goto Loop, informs the PC to return to position 0003, which there is the said Loop. In case the details of 0C is 0, then the PC is advised to increment by 2, put simply omit the subsequent instruction. This places the PC at position 0004, wherein the program finishes. The destinations are fixed by the assembler, and we don’t generally ought to be concerned what the PC is accomplishing. Until, we find the need to bring it under control just like while we do when utilizing data tables. The most convenient way to describe how a data table functions, is to begin with an illustration.

PC equ  02
movlw  03
call        table
table      addwf PC
retlw      01
retlw      02
retlw      03
retlw      04
retlw      05
retlw      06
retlw      07
The initial instruction is allocating the label PC with the address of the Program Counter (02h). We will be soon after putting the value of 03h into the w register. We after that communicate to table. The foremost line in the subroutine table augments the details of the W register (03h) to the program counter. This triggers the program counter to raise by 3, or to put it a different way, stimulates the program counter to proceed down 3 lines. While the counter arrives 3 lines down it the PIC recognizes the instruction retlw. This command sends the value following it into the W register, after which comes back from the subroutine. RETLW basically signifies Return, Literal to W. See I placed a comma after the word Return. Since we are in a subroutine, we require a Return instruction to surface of it. Therefore the RET in the instruction. After the RETLW instruction is a number, and this is exactly what is put into the W register. In this instance it is the figure 3. We could designate any quantity to the W register, so long as this figure is combined with the Program Counter in the table subroutine, we are going to discover a retlw instruction. In the above illustration this implies we are able to possess any number from 1 to 7. In case we proceed past the subroutine, we might be able to finish up performing an additional section of the program. For this reason, it is usually a smart move to place the data table exactly towards the end of the PIC program, therefore if we do overshoot in that case we are going to arrive at the conclusion of the program anyhow.

Leave a Comment