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 as RETLW NN, where NN = 8-bit random code. In MPLAB® IPE, you would select RETLW under Access 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 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

© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.