{"id":975,"date":"2019-06-05T18:18:38","date_gmt":"2019-06-05T18:18:38","guid":{"rendered":"https:\/\/ibex.tech\/embedded\/?p=975"},"modified":"2024-07-24T15:54:34","modified_gmt":"2024-07-24T14:54:34","slug":"xc8-v2-compiler","status":"publish","type":"post","link":"https:\/\/ibex.tech\/embedded\/microchip\/pic18\/xc8-compiler\/xc8-general\/xc8-v2-compiler","title":{"rendered":"XC8 V2.# Compiler"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Setting a new project<\/h4>\n\n\n\n<p>(After following the&nbsp;<a href=\"https:\/\/ibex.tech\/embedded\/microchip\/pic18\/xc8-compiler\/xc8-general\/new-xc8-project\">steps here<\/a>)<\/p>\n\n\n<p>Project Properties &gt; XC8 global options &gt; XC8 Compiler &gt; Select \u2018Optimizations\u2019<\/p>\n<p style=\"padding-left: 40px;\">Speed (or disable optimizations?) &amp; Debug checkboxes<\/p>\n<p style=\"padding-left: 80px;\">Set as needed (off and on is good for debugging)<\/p>\n<p style=\"padding-left: 40px;\">Address qualifiers \u2013 CAN BE VERY IMPORTANT!!!!<\/p>\n<p style=\"padding-left: 80px;\">If you are using anything that requires locating in specific memory locations set this to \u2018Require\u2019, e.g. variables used in assembler, etc. This is not the default setting as it can cause horribly confusing bugs until you realize it is the cause.<\/p>\n\n\n<h4 class=\"wp-block-heading\">Upgrading A Project From XC8 V1.## to XC8 V2.## and use C99<\/h4>\n\n\n\n<p><a href=\"https:\/\/microchipdeveloper.com\/xc8:moving-to-xc8-2-0\">https:\/\/microchipdeveloper.com\/xc8:moving-to-xc8-2-0<\/a><\/p>\n\n\n\n<p>V2.00 of the XC8 compiler is quite different to V1.## versions, various things are broken \/ change:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Uses C99 instead of C90 (you can still use C90 if you want to &#8211; see  <a href=\"https:\/\/microchipdeveloper.com\/xc8:moving-to-xc8-2-0\">https:\/\/microchipdeveloper.com\/xc8:moving-to-xc8-2-0<\/a> )<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">If you don&#8217;t want to implement this C99 changes<\/h4>\n\n\n\n<p>This guide is based on moving up to C99, but you can avoid having to do some of the changes if you want to use the older C90 standard.<\/p>\n\n\n\n<p>If you want to continue using #asm, old style interrupt definitions and other C90 based C things then you can simply select C90 instead of C99:  Properties &gt; XC8 Global Options &gt; C Standard. <\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Upgrading A Project From XC8 V1.## to  XC8 V2.## and use C99<\/h5>\n\n\n\n<h5 class=\"wp-block-heading\">Change Project Settings<\/h5>\n\n\n\n<p>Project properties &gt; Conf &gt; Select XC8 v2.## compiler<\/p>\n\n\n\n<p>Project properties &gt; XC8 Global Options &gt; C standard &gt; C99<\/p>\n\n\n\n<p>Project properties &gt; XC8 Global Options &gt; XC8 Linker &gt; Link in C Library &gt; C99<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Include Files<\/h5>\n\n\n\n<p>Replace your device specific header file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;p18f23k22.h&gt;<\/code><\/pre>\n\n\n\n<p>With this generic file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;xc.h&gt;<\/code><\/pre>\n\n\n\n<p><em>This header file is typically included into each C source file you write. It is a generic header file that will include other device- and architecture-specific header files when you build your project.<\/em><\/p>\n\n\n\n<h5 class=\"wp-block-heading\">ASM code<\/h5>\n\n\n\n<p>Remove these:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#asm\n#endasm<\/code><\/pre>\n\n\n\n<p>Add this before and after each line of assembly<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>asm(\"        \");<\/code><\/pre>\n\n\n\n<p>An example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\t\tasm(\"GLOBAL _uc_asm_irq_temp\");\n\t\tasm(\"GLOBAL _uc_asm_irq_temp1\");\n\t\t\/\/Reset timer for next rollover\n\t\tasm(\"movff\tTMR0L,_uc_asm_irq_temp\");\t\t\t\/\/read_current_timer_value (read low byte loads high byte)\n\t\tasm(\"movff\tTMR0H,_uc_asm_irq_temp1\");\n\t\tasm(\"movlw\t0x6b\");\n\t\tasm(\"addwf\t_uc_asm_irq_temp,f,c\");\t\t\t\/\/(1 = file register, 0 = access ram)\n\t\tasm(\"movlw\t0xf0\");\n\t\tasm(\"addwfc\t_uc_asm_irq_temp1,f,c\");\t\t\t\/\/(1 = file register, 0 = access ram)\n\t\tasm(\"movff\t_uc_asm_irq_temp1,TMR0H\");\t\t\t\/\/Store new value (high byte first)\n\t\tasm(\"movff\t_uc_asm_irq_temp,TMR0L\");<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Interrupt Functions<\/h5>\n\n\n\n<p>Change the definitions in your .c and .h files from this format:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void interrupt interruptisrh (void);\nvoid interrupt low_priority interruptisrl (void);<\/code><\/pre>\n\n\n\n<p>To this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void __interrupt() interruptisrh (void);\nvoid __interrupt(low_priority) interruptisrl (void);<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">near variables<\/h5>\n\n\n\n<p>For any variables defined as near add a double underscore in front of the near directive, so from this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>near static unsigned char uc_asm_irq_temp;\t\t\/\/ near qualifier specifies access RAM\nnear static unsigned char uc_asm_irq_temp1;<\/code><\/pre>\n\n\n\n<p>To this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>__near static unsigned char uc_asm_irq_temp;\t\t\/\/ near qualifier specifies access RAM\n__near static unsigned char uc_asm_irq_temp1;<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Possible errors<\/h5>\n\n\n<p>error: (2047) 24-bit floating point types are not supported when compiling in C99<\/p>\n<p style=\"padding-left: 40px;\">Project properties &gt; XC8 Global Options &gt; XC8 Linker &gt; Memory Model &gt; Size of float 32bit<\/p>\n\n\n<h4 class=\"wp-block-heading\">MPLAB Code Configurator<\/h4>\n\n\n\n<p>You really have to use the graphical \u201cMPLAB Code Configurator\u201d instead of the old peripheral libraries \u2013 even though they can still be installed we ran into compile issues when we tried to use some.<\/p>\n\n\n\n<p>For how to use <a href=\"\/embedded-programming\/microchip-pic\/mplab-x\/code-configurator\/code-configurator-new-project\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">see here<\/a><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Peripheral Libraries<\/h4>\n\n\n\n<p>Seems you really have to use the graphical \u201cMPLAB Code Configurator\u201d instead of the old peripheral libraries \u2013 even though they can still be installed we ran into compile issues when we tried to use.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Setting a new project (After following the&nbsp;steps here) Project Properties &gt; XC8 global options &gt; XC8 Compiler &gt; Select \u2018Optimizations\u2019 Speed (or disable optimizations?) &amp; Debug checkboxes Set as needed (off and on is good for debugging) Address qualifiers \u2013 CAN BE VERY IMPORTANT!!!! If you are using anything that requires locating in specific memory [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[80],"tags":[],"class_list":["post-975","post","type-post","status-publish","format-standard","hentry","category-xc8-general"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/posts\/975","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=975"}],"version-history":[{"count":18,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/posts\/975\/revisions"}],"predecessor-version":[{"id":1586,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/posts\/975\/revisions\/1586"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/media?parent=975"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/categories?post=975"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/embedded\/wp-json\/wp\/v2\/tags?post=975"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}