{"id":129,"date":"2012-05-24T09:01:09","date_gmt":"2012-05-24T09:01:09","guid":{"rendered":"http:\/\/www.electronic-products-development.com\/?p=129"},"modified":"2022-02-18T15:37:50","modified_gmt":"2022-02-18T15:37:50","slug":"locating-things-in-pogram-memory","status":"publish","type":"post","link":"https:\/\/ibex.tech\/embedded\/microchip\/pic18\/c18-compiler\/memory-c18-compiler\/locating-things-in-pogram-memory","title":{"rendered":"Locating things in Pogram memory"},"content":{"rendered":"<pre>\r\n<code>\r\n\/\/----- CONSTANTS LOCATED IN PROGRAM MEMORY -----\r\n#pragma romdata firm_upgrade_code_markers_romdata_section=0x0009fc\r\n      const rom WORD firmware_upgrade_marker_1 = OUR_PRODUCT_ID;\r\n      const rom WORD firmware_upgrade_marker_2 = OUR_FIRMWARE_REVISION;\r\n#pragma code normal_section=0x000a00\r\nextern void _startup (void);        \/\/ See c018i.c in your C18 compiler dir\r\n#pragma code _RESET_INTERRUPT_VECTOR = 0x000a00\r\nvoid _reset (void)\r\n{\r\n      _asm goto _startup _endasm\r\n}\r\n#pragma code\r\n\r\n<\/code><\/pre>\n<p>\n&nbsp;\n<\/p>\n<h4>\nUsing Program Memory For A Large Lookup Table<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n\r\n\/\/Lookup value from our program memory lookup table\r\n\/\/dest is the index into the lookup table we want the word value for\r\n\tstatic DWORD_VAL address;\r\n\taddress.val = 0x1fd00;\t\t\t\t\t\/\/&lt;&lt;&lt;&lt;&lt;THE START ADDRESS IN PROG MEMORY\r\n\taddress.val += dest;\r\n\taddress.val += dest;\r\n\r\n\tTBLPTRU = address.v[2];\r\n\tTBLPTRH = address.v[1];\r\n\tTBLPTRL = address.v[0];\r\n\r\n\t_asm\r\n\t\/\/tblrd*+\r\n\tTBLRDPOSTINC\r\n\t\/\/dw\t0xffff\t\t\t\t\/\/(Silicon Bug Fix)\r\n\t_endasm\r\n\tw_temp = TABLAT;\r\n\r\n\t_asm\r\n\t\/\/tblrd*+\r\n\tTBLRDPOSTINC\r\n\t\/\/dw\t0xffff\t\t\t\t\/\/(Silicon Bug Fix)\r\n\t_endasm\r\n\tw_temp |= (WORD)TABLAT &lt;&lt; 8;\r\n\r\n\r\n\/\/----- LOOKUP TABLE LOCATED IN PROGRAM MEMORY -----\r\n\/\/Have this at the end of a .c file if compiler gets upset\r\n#pragma romdata firm_upgrade_code_markers_romdata_section=0x1fd00\t\t\/\/&lt;&lt;&lt;&lt;&lt;THE START ADDRESS IN PROG MEMORY (REMEMBER THAT PIC18 INSTRUCTION ADDRESS ARE +2, USE LAST BLOCKS BEFORE CONFIG MEMORY)\r\nconst rom WORD led_lookup_table[]={\r\n0\t,\r\n1\t,\r\n2\t,\r\n3\t,\r\n4\t,\r\n5\t,\r\n6\t,\r\n7\t,\r\n8\t,\r\n9\t,\r\n10\t,\r\n11\t,\r\n12\t,\r\n13\t,\r\n14\t,\r\n15\t,\r\n16\t,\r\n17\t,\r\n18\t,\r\n19\t,\r\n20\t,\r\n21\t,\r\n22\t,\r\n23\t,\r\n24\t,\r\n25\t,\r\n26\t,\r\n27\t,\r\n28\t,\r\n29\t,\r\n30\t,\r\n31\t,\r\n32\t,\r\n33\t,\r\n34\t,\r\n35\t,\r\n36\t,\r\n37\t,\r\n38\t,\r\n39\t,\r\n40\t,\r\n41\t,\r\n42\t,\r\n43\t,\r\n44\t,\r\n45\t,\r\n46\t,\r\n47\t,\r\n48\t,\r\n49\t,\r\n50\t,\r\n51\t,\r\n52\t,\r\n53\t,\r\n54\t,\r\n55\t,\r\n56\t,\r\n57\t,\r\n58\t,\r\n59\t,\r\n60\t,\r\n61\t,\r\n62\t,\r\n63\t,\r\n64\t,\r\n65\t,\r\n66\t,\r\n67\t,\r\n68\t,\r\n69\t,\r\n70\t,\r\n71\t,\r\n72\t,\r\n73\t,\r\n74\t,\r\n75\t,\r\n76\t,\r\n77\t,\r\n78\t,\r\n79\t,\r\n80\t,\r\n81\t,\r\n82\t,\r\n83\t,\r\n84\t,\r\n85\t,\r\n86\t,\r\n88\t,\r\n90\t,\r\n92\t,\r\n94\t,\r\n97\t,\r\n99\t,\r\n101\t,\r\n103\t,\r\n106\t,\r\n108\t,\r\n111\t,\r\n113\t,\r\n116\t,\r\n118\t,\r\n121\t,\r\n123\t,\r\n126\t,\r\n129\t,\r\n132\t,\r\n134\t,\r\n137\t,\r\n140\t,\r\n143\t,\r\n145\t,\r\n148\t,\r\n151\t,\r\n154\t,\r\n157\t,\r\n160\t,\r\n163\t,\r\n166\t,\r\n170\t,\r\n173\t,\r\n176\t,\r\n179\t,\r\n183\t,\r\n186\t,\r\n189\t,\r\n193\t,\r\n196\t,\r\n200\t,\r\n203\t,\r\n207\t,\r\n210\t,\r\n214\t,\r\n217\t,\r\n221\t,\r\n225\t,\r\n229\t,\r\n232\t,\r\n236\t,\r\n240\t,\r\n244\t,\r\n248\t,\r\n252\t,\r\n256\t,\r\n260\t,\r\n264\t,\r\n269\t,\r\n273\t,\r\n277\t,\r\n281\t,\r\n286\t,\r\n290\t,\r\n295\t,\r\n299\t,\r\n304\t,\r\n308\t,\r\n313\t,\r\n318\t,\r\n322\t,\r\n327\t,\r\n332\t,\r\n337\t,\r\n342\t,\r\n347\t,\r\n352\t,\r\n357\t,\r\n362\t,\r\n367\t,\r\n373\t,\r\n378\t,\r\n383\t,\r\n389\t,\r\n394\t,\r\n400\t,\r\n405\t,\r\n411\t,\r\n416\t,\r\n422\t,\r\n428\t,\r\n434\t,\r\n439\t,\r\n445\t,\r\n451\t,\r\n457\t,\r\n463\t,\r\n469\t,\r\n476\t,\r\n482\t,\r\n488\t,\r\n494\t,\r\n501\t,\r\n507\t,\r\n514\t,\r\n520\t,\r\n527\t,\r\n533\t,\r\n540\t,\r\n547\t,\r\n553\t,\r\n560\t,\r\n567\t,\r\n574\t,\r\n581\t,\r\n588\t,\r\n595\t,\r\n602\t,\r\n609\t,\r\n616\t,\r\n624\t,\r\n631\t,\r\n638\t,\r\n646\t,\r\n653\t,\r\n661\t,\r\n668\t,\r\n676\t,\r\n683\t,\r\n691\t,\r\n699\t,\r\n707\t,\r\n714\t,\r\n722\t,\r\n730\t,\r\n738\t,\r\n746\t,\r\n754\t,\r\n763\t,\r\n771\t,\r\n779\t,\r\n787\t,\r\n796\t,\r\n804\t,\r\n813\t,\r\n821\t,\r\n830\t,\r\n838\t,\r\n847\t,\r\n856\t,\r\n864\t,\r\n873\t,\r\n882\t,\r\n891\t,\r\n900\t,\r\n909\t,\r\n918\t,\r\n927\t,\r\n936\t,\r\n945\t,\r\n955\t,\r\n964\t,\r\n973\t,\r\n983\t,\r\n992\t,\r\n1002\t,\r\n1011\t,\r\n1021\t,\r\n1023\r\n};\r\n#pragma code\r\n<\/code><\/pre>\n<p>\n&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/\/&#8212;&#8211; CONSTANTS LOCATED IN PROGRAM MEMORY &#8212;&#8211; #pragma romdata firm_upgrade_code_markers_romdata_section=0x0009fc const rom WORD firmware_upgrade_marker_1 = OUR_PRODUCT_ID; const rom WORD firmware_upgrade_marker_2 = OUR_FIRMWARE_REVISION; #pragma code normal_section=0x000a00 extern void _startup (void); \/\/ See c018i.c in your C18 compiler dir #pragma code _RESET_INTERRUPT_VECTOR = 0x000a00 void _reset (void) { _asm goto _startup _endasm } #pragma code &nbsp; Using [&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-129","post","type-post","status-publish","format-standard","hentry","category-memory-c18-compiler"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/posts\/129","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=129"}],"version-history":[{"count":4,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/posts\/129\/revisions"}],"predecessor-version":[{"id":450,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/posts\/129\/revisions\/450"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/media?parent=129"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/categories?post=129"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/tags?post=129"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}