MPLAB® IPE Usage of RETLW in SQTP(SM) File for Midrange and Baseline Devices

Last modified by Microchip on 2023/11/09 09:10

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 as RETLW NN, where NN = 8-bit random code. In MPLAB® Integrated Programming Environment (IPE), you would select Serialized Quick Turn Programming (SQTP℠) > Acces Method > RETLW.

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 the RETLW 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):
:16000000 01 08 02 08 03 08 04 08 05 08 06 08 07 08 08 08 86

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