The following example shows the principles of obtaining the code for Custom DPA Handler to be stored at external EEPROM and to be later loaded into MCU flash memory and executed.
Below is the piece of output .lst file of the compiled FRC-Minimalistic Custom DPA Handler example. The code is located from the mandatory starting address 0x3A20 and in this example ends at address 0x3A30.
; bit CustomDpaHandler()
; {
; // Handler presence mark
; clrwdt();
3A20 0064 CLRWDT
;
; // Return 1 if IQRF button is pressed
; if (GetDpaEvent() == DpaEvent_FrcValue && _PCMD == FRC_USER_BIT_FROM && buttonPressed)
3A21 0870 MOVF userReg0,W
3A22 3A0A XORLW 0x0A
3A23 1D03 BTFSS 0x03,Zero_
3A24 320A BRA m001
3A25 0025 MOVLB 0x05
3A26 082F MOVF PCMD,W
3A27 3A40 XORLW 0x40
3A28 1D03 BTFSS 0x03,Zero_
3A29 3205 BRA m001
3A2A 0020 MOVLB 0x00
3A2B 1A0D BTFSC PORTB,4
3A2C 3202 BRA m001
; responseFRCvalue.1 = 1;
3A2D 002B MOVLB 0x0B
3A2E 14B8 BSF responseFRCvalue,1
;
; return FALSE;
3A2F 1003 m001 BCF 0x03,Carry
3A30 0008 RETURN
; }
The portion of the corresponding .hex file stores the code bytes from the double address 0x7440 = 2 × 0x3A20 to 0x7460 = 2 × 0x3A30. The first two digits at the line specify the byte count, two zeros after the address specify the record type.
:020000040000FA
...
:08741000AC310024BA31080080
:10744000640070080A3A031D0A3225002F08403AEA
:10745000031D053220000D1A02322B00B814031050
:02746000080022
:027AFE0008007E
...
The exact code size is 2 × (0x3A30 - 0x3A20 + 1) = 34 bytes. The length of the code stored at external EEPROM must be multiple of 64 so, in our example, the stored size is 64 = 0x40 bytes. If the unused 30 bytes (64 - 34) bytes of the 64-byte block are filled in with zeros then the Fletcher-16 checksum equals 0xEA3A.