Understanding Usage of RETLW in SQTP File for Midrange and Baseline Devices

For midrange and baseline families of devices, the serial number must reside in contiguous locations, with up to 256 locations used. These locations must be coded in the finished product asRETLWNN, whereNN = 8-bit random code. In MPLAB® IPE, you would selectRETLW underAccess Method on the SQTP tab.

The first example presented is an implementation of a table in the program memory of baseline devices. Baseline devices use Harvard architecture, in which the program memory is separate from data memory. All instructions operate on data that is fetched from the register file or data memory. Since there are no instructions to read from or write to the program memory, simply storing data Words in program memory is of no use. There is, however, a simple and elegant way to implement constant tables in the program memory by using theRETLW instruction. This instruction returns from a subroutine, as well as loads an 8-bit constant into the W register. The following example shows how to get a byte of “serial information” from the table stored at location 0h.

In the SQTP file, the record would be (RETLW =08h):
:160000000108020803080408050806080708080886

Programmed into the device with the application:

ORG 0 ;store serial numbers
RETLW 01h
RETLW 02h
RETLW 03h
RETLW 04h
RETLW 05h
RETLW 06h
RETLW 07h
RETLW 08h ;end of serial numbers


main_prog ORG XYZ ;This is main program


MOVLW byte_num ;byte_num = 0 for 1st byte
CALL get_1byte;


get_1byte MOVWF PC ;write W to program counter
;W = offset = 0 for 1st byte
;end of get_1byte subroutine


END

The second example shows how a serial number may reside at a location other than 0h (0000).

main_prog ORG XYZ ;This is main program


MOVLW byte_num ;byte_num = 0 for 1st byte
CALL get_1byte;


get_1byte ADDWFPC ;W = offset
RETLW 01h ;
RETLW 02h ;
RETLW 03h ;
RETLW 04h ;
RETLW 05h ;
RETLW 06h ;
RETLW 07h ;
RETLW 08h ;end of serial numbers


END