{"id":362,"date":"2014-01-07T10:32:16","date_gmt":"2014-01-07T10:32:16","guid":{"rendered":"https:\/\/ibex.tech\/embedded\/?p=362"},"modified":"2022-02-18T15:37:49","modified_gmt":"2022-02-18T15:37:49","slug":"memory-2","status":"publish","type":"post","link":"https:\/\/ibex.tech\/embedded\/microchip\/pic18\/c18-compiler\/memory-c18-compiler\/memory-2","title":{"rendered":"Memory"},"content":{"rendered":"<h4>\nCreating Large Memory Arrays<br \/>\n<\/h4>\n<p>\nThe C18 compiler does not support data buffers over 256 bytes without a modification to the linker script&nbsp;to define a larger bank of microcontroller ram.\n<\/p>\n<p>\nCopy the default linker script for your PIC18 device from:\n<\/p>\n<p style=\"margin-left: 40px;\">\nC:\\Program Files (x86)\\Microchip\\MPASM Suite\\LKR\n<\/p>\n<p>\ninto your projects directory. &nbsp;Add the file to your MPLAB project so that it is used in place of the default file.\n<\/p>\n<p>\nFind the section listing each of the databanks for your device, e.g.\n<\/p>\n<pre>\r\n<code>\r\nDATABANK   NAME=gpr0       START=0x60              END=0xFF\r\nDATABANK   NAME=gpr1       START=0x100             END=0x1FF\r\nDATABANK   NAME=gpr2       START=0x200             END=0x2FF\r\nDATABANK   NAME=gpr3       START=0x300             END=0x3FF\r\nDATABANK   NAME=gpr4       START=0x400             END=0x4FF\r\nDATABANK   NAME=gpr5       START=0x500             END=0x5FF\r\nDATABANK   NAME=gpr6       START=0x600             END=0x6FF\r\nDATABANK   NAME=gpr7       START=0x700             END=0x7FF\r\nDATABANK   NAME=gpr8       START=0x800             END=0x8FF\r\nDATABANK   NAME=gpr9       START=0x900             END=0x9FF\r\nDATABANK   NAME=gpr10      START=0xA00             END=0xAFF\r\nDATABANK   NAME=gpr11      START=0xB00             END=0xBFF\r\nDATABANK   NAME=gpr12      START=0xC00             END=0xCFF\r\n#IFDEF _DEBUGDATASTART\r\n  DATABANK   NAME=gpr13      START=0xD00             END=_DATAEND\r\n  DATABANK   NAME=dbgspr     START=_DEBUGDATASTART   END=_DEND           PROTECTED\r\n#ELSE \/\/no debug\r\n  DATABANK   NAME=gpr13      START=0xD00             END=0xDFF\r\n#FI\r\nDATABANK   NAME=gpr14      START=0xE00             END=0xE40\r\n<\/code><\/pre>\n<p>\nThe number will relate to the number of gpr banks your PIC18 device has.\n<\/p>\n<p>\nNow select as many consecutive&nbsp;databanks as you will need to be able to hold your array from somewhere in the middle of the available banks. If you need a multiple of 256bytes then you will use the&nbsp;complete banks, or otherwise you will use just part of the final bank. You want to delete those databanks (and just&nbsp;edit the START address for the final bank if not using a 256byte multiple) and then add your own new databank which will hold your array:\n<\/p>\n<pre>\r\n<code>\r\nDATABANK NAME=my_ram_section START=0x#00 END=0x#FF\r\n<\/code><\/pre>\n<p>\nWhere &lsquo;0x#00&rsquo; is the start address of the first removed bank and &lsquo;0x#FF &lsquo; is the end address of the last removed bank. &nbsp;E.g. for a 512 byte databank in this example:\n<\/p>\n<pre>\r\n<code>\r\nDATABANK   NAME=gpr0       START=0x60              END=0xFF\r\nDATABANK   NAME=gpr1       START=0x100             END=0x1FF\r\nDATABANK   NAME=gpr2       START=0x200             END=0x2FF\r\nDATABANK   NAME=gpr3       START=0x300             END=0x3FF\r\nDATABANK   NAME=gpr4       START=0x400             END=0x4FF\r\nDATABANK   NAME=gpr5       START=0x500             END=0x5FF\r\nDATABANK   NAME=gpr6       START=0x600             END=0x6FF\r\n\r\nDATABANK NAME=dmx_512_byte_ram_section START=0x700 END=0x8FF\r\n\r\nDATABANK   NAME=gpr9       START=0x900             END=0x9FF\r\nDATABANK   NAME=gpr10      START=0xA00             END=0xAFF\r\nDATABANK   NAME=gpr11      START=0xB00             END=0xBFF\r\nDATABANK   NAME=gpr12      START=0xC00             END=0xCFF\r\n#IFDEF _DEBUGDATASTART\r\n  DATABANK   NAME=gpr13      START=0xD00             END=_DATAEND\r\n  DATABANK   NAME=dbgspr     START=_DEBUGDATASTART   END=_DEND           PROTECTED\r\n#ELSE \/\/no debug\r\n  DATABANK   NAME=gpr13      START=0xD00             END=0xDFF\r\n#FI\r\n<\/code><\/pre>\n<p>\nSave the linker script. &nbsp;This defines the new block of memory and you can now use the name you assigned to declare your array:\n<\/p>\n<pre>\r\n<code>\r\n#pragma udata dmx_512_byte_ram_section\t\t\t\t\/\/This is the PIC C18 compiler command to use the specially defined section in the linker script (uses a modified linker script for this)\r\nBYTE dmx_tx_buffer[512];\t\t\t\/\/(C18 large array requirement to use a special big section of ram defined in the linker script)\r\n#pragma udata\r\n<\/code><\/pre>\n<h5>\nAccessing The Array<br \/>\n<\/h5>\n<p>\nIts OK to use pointers like this:\n<\/p>\n<pre>\r\n<code>\r\n\tBYTE *buffer_pointer;\r\n\tbuffer_pointer = &amp;my_array[0] + some_value;\r\n\t*buffer_pointer = 0x01;\r\n<\/code><\/pre>\n<p>\n&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Creating Large Memory Arrays The C18 compiler does not support data buffers over 256 bytes without a modification to the linker script&nbsp;to define a larger bank of microcontroller ram. Copy the default linker script for your PIC18 device from: C:\\Program Files (x86)\\Microchip\\MPASM Suite\\LKR into your projects directory. &nbsp;Add the file to your MPLAB project so [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[52],"tags":[],"class_list":["post-362","post","type-post","status-publish","format-standard","hentry","category-memory-c18-compiler"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/posts\/362","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/comments?post=362"}],"version-history":[{"count":4,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/posts\/362\/revisions"}],"predecessor-version":[{"id":417,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/posts\/362\/revisions\/417"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/media?parent=362"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/categories?post=362"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/tags?post=362"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}