; Assembly PIC18 - Versione 0.1 - July 2017 ; Copyright (c) 2016-2017, Vincenzo Villa ; Creative Commons | Attribution-Share Alike 4.0 Unported ; https://www.vincenzov.net/tutorial/PIC18/Assembly/variabili-2.htm ; Using PIC18 MPASM idata ; Undocumented Proof of Concept, please use with care #include "p18f26k20.inc" EXTERN _cinit ; Start of constant data table GLOBAL init_data ; **************************************************************************** comodity_data UDATA_OVR num_entry res 1 ; Number of entries in ROMdata (max 255) idata_counter res 1 ; Table counter ROM_pointer_save res 4 ; Temporaney storage for ROMdata Pointer ; !!************************************************************************** ; !! DO NOT change order or size! ROMdata_addr res 4 ; ROMdata address RAMdata_addr res 4 ; RAMdata address data_size res 4 ; Number of bytes in ROMdata ; !!************************************************************************** i_data CODE init_data ; This code copy initialization data from ROMdata to RAMdata - ; Inizialize the Table Pointer (TBLPTR) register to benif of ROMdata movlw LOW _cinit movwf TBLPTRL movlw HIGH _cinit movwf TBLPTRH movlw UPPER _cinit movwf TBLPTRU ; Read the number of entries in ROMdata (up to 255) BANKSEL num_entry tblrd*+ movff TABLAT, num_entry tblrd*+ ; Skip next byte next_entry ; Read a single entry from ROMdata and store in RAMdata (idata) ; Read ROMdata addr, RAMdata addr and data size (4 byte each, 12 byte) movlw .12 lfsr FSR0, ROMdata_addr repeat tblrd*+ movff TABLAT, POSTINC0 decf WREG bnz repeat ; Save pointer movff TBLPTRL, ROM_pointer_save movff TBLPTRH, ROM_pointer_save + 1 movff TBLPTRU, ROM_pointer_save + 2 ; Point to begin of ROMdata value movff ROMdata_addr, TBLPTRL movff ROMdata_addr + 1, TBLPTRH movff ROMdata_addr + 2, TBLPTRU ; Point to begin of RAMdata movff RAMdata_addr, FSR0L ; RAMdata pointer movff RAMdata_addr + 1, FSR0H movf data_size,W ; Data size, up to 256 byte ; Copy from ROMdata to RAMdata repeat_2 tblrd*+ movff TABLAT, POSTINC0 decf WREG bnz repeat_2 ; Recover pointer fon next entry movff ROM_pointer_save, TBLPTRL movff ROM_pointer_save + 1, TBLPTRH movff ROM_pointer_save + 2, TBLPTRU decf num_entry bnz next_entry return END