Chapter 35 ½ PIC1650: Chip Architecture
and Operation 609
VI. Program Examples
Use of Indirect Addressing
This example illustrates the use of the File Select Register (F4) and
the indirect addressing mode using F0. This program clears files F5 to
F31.
Label | Op code | Operand | Comment |
MOVLW | 5 | Move literal 5 to W REG. | |
MOVWF | 4 | Move W to F4. (F4 = 5). | |
Loop | CLRF | 0 | Clear the contents of the file pointed to by F4. |
INCFSZ | 4, F | Increment F4. The PC will skip after F31 is cleared. | |
GOTO | Loop | Repeat the steps beginning at Loop to clear the next file. | |
END | Files PS and F31 are cleared. |
BCD Number Display
This example converts a BCD number held in the four least significant bits of F20 (the 4 MSB's are assumed zero) to a 7-segment code. The 7-segment code is output via I/O port F5,
Label
|
Op code | Operand | Comment |
MOVLW | TBLSTR | Starting address of table. | |
ADDWF | 20, W | Add BCD number as offset to Table start. | |
CALL | CONVRT | Call the conversion subroutine. | |
MOVWF END | 5 | Output the 7-segment code to I/O
P5. The 7-segment
will now show the BCD number and this output will remain stable until F5 is set to a new value. |
|
CONVRT: | MOVWF | 2 | Move the computed address into the PC. Because the ninth bit of the PC is set to zero by a MOVWF 2, the TBLSTR routine must be located in the low 256-word ROM memory area. |
TBLSTR: | RETLW RETLW RETLW RETLW
RETLW RETLW RETLW RETLW RETLW RETLW |
B'00000001 B'01001111 B'00010010
B'00000110
B'01001100 B'00100100 B'01100000 B'00001111 B'00000000 B'00001100 |
Complement of 0 in 7-segment code.
Complement of 1 in 7-segment code. Complement of 2 in 7-segment code. Complement of 3 in 7-segment code. Complement of 4 in 7-segment code.
|
which is directly tied through current-limiting resistors to a 7-segment LED display. This program illustrates the use of the computed GOTO instruction. Figure 5 shows the external component connections.
The RETLW instruction loads the W register with the specified literal
value and returns to the instruction following the CALL instruction (MOVWF
5). The complement of the 7-segment code is used because the LED display
unit is common-anode; a segment is activated when the output is set low.
References
PIC [1979a]; PIC [1979b].