<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic display decimal to LCD in S12 / MagniV Microcontrollers</title>
    <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/display-decimal-to-LCD/m-p/166121#M5385</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm trying to convert a HEX number to a deciaml number so that I can display it onto the LCD. I can display everything I want on the the display but my number is in HEX. My hex number is coming from a routine that converts the value stored in ATD0DR0H. The value stored there is (I think) binary, so what every is easier binary to deciamal or Hex to decimal, I need to convert to deciamal. I'm using CodeWarrior I have attached the code that&amp;nbsp;I have so far. Thanks to anyone that helps me&lt;/P&gt;&lt;P&gt;Heath&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 11 Sep 2011 01:58:26 GMT</pubDate>
    <dc:creator>broady20</dc:creator>
    <dc:date>2011-09-11T01:58:26Z</dc:date>
    <item>
      <title>display decimal to LCD</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/display-decimal-to-LCD/m-p/166121#M5385</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm trying to convert a HEX number to a deciaml number so that I can display it onto the LCD. I can display everything I want on the the display but my number is in HEX. My hex number is coming from a routine that converts the value stored in ATD0DR0H. The value stored there is (I think) binary, so what every is easier binary to deciamal or Hex to decimal, I need to convert to deciamal. I'm using CodeWarrior I have attached the code that&amp;nbsp;I have so far. Thanks to anyone that helps me&lt;/P&gt;&lt;P&gt;Heath&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 11 Sep 2011 01:58:26 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/display-decimal-to-LCD/m-p/166121#M5385</guid>
      <dc:creator>broady20</dc:creator>
      <dc:date>2011-09-11T01:58:26Z</dc:date>
    </item>
    <item>
      <title>Re: display decimal to LCD</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/display-decimal-to-LCD/m-p/166122#M5386</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello, and welcome to the forum.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It is more straight forward to convert a binary value to decimal numeric&amp;nbsp;ASCII characters, assuming the LCD is compatible with these.&amp;nbsp; For simplicity, the following code snippet assumes a 16-bit unsigned binary value, and generates up to five digits, right aligned.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;void disp_decimal( word val){   char buf[6];  // Temporary buffer for numeric data   int i;   // Fill buffer with spaces   for (i = 0; i &amp;lt; 5; i++)      buf[i] = ' ';   buf[5] = 0;   // Null termination for data   // Convert binary value to decimal ASCII   for (i = 4; i &amp;gt;= 0; i--) {      buf[i] = (val % 10) + '0';      val /= 10;      if (val == 0)  break;   }   lcd_puts_String( buf);  // Send string data to LCD}   &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:13:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/display-decimal-to-LCD/m-p/166122#M5386</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2020-10-29T09:13:07Z</dc:date>
    </item>
    <item>
      <title>Re: display decimal to LCD</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/display-decimal-to-LCD/m-p/166123#M5387</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi BigMac,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Great code.&lt;/P&gt;&lt;P&gt;Based on your idea we made a modification for microcontrollers without hardware divider:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;void disp_decimal(INT16U val, CHAR8 *buff){   INT16U backup;   INT8U i;      // Fill buffer with spaces   for (i = 0; i &amp;lt; 5; i++)    {      *(buff + i) = ' ';   }      // Null termination for data   *(buff + i) = 0;   // Convert binary value to decimal ASCII   for (i = 4; i &amp;gt;= 0; i--)    {      backup = val;      val /= 10;      *(buff + i) = (backup - (val*10)) + '0';            if (val == 0)  break;   }}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We made same modifications on the buffer creation too. You can use like this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;char buff[6];&lt;/P&gt;&lt;P&gt;disp_decimal(12345, buff);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And use the generated string for everything.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Gustavo&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:13:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/display-decimal-to-LCD/m-p/166123#M5387</guid>
      <dc:creator>gustavod</dc:creator>
      <dc:date>2020-10-29T09:13:09Z</dc:date>
    </item>
    <item>
      <title>Re: display decimal to LCD</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/display-decimal-to-LCD/m-p/166124#M5388</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Gustavo,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes, there are many variations on this theme.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Irrespective of whether a hardware divider is available, your approach to deriving the remainder of each division is very likely to be more efficient.&amp;nbsp; This is because you have a single explicit division only.&amp;nbsp; With my previous aproach, there is likely to be two divisions - an implicit one for the '%' operator implementation,&amp;nbsp;plus the explicit one.&amp;nbsp; But this will depend on the&amp;nbsp;compiler optimisation process.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I notice that the local variable is declared as type INT8U, presumably unsigned.&amp;nbsp; I might have expected this would need to be a signed type for the second decrementing loop to exit, when there is a 5-digit result.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If using a buffer that is external to the conversion function, it may provide more flexibility and efficiency&amp;nbsp;if the buffer initialisation also occurs outside the&amp;nbsp;function.&amp;nbsp; This is especially so if the function is called to "fill in the blanks" of a larger string.&amp;nbsp; For example -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;void disp_temp( int temp){  char buffer[] = "Temperature:    0 C";  // Initialise local variable  conv_decimal( temp, &amp;amp;buffer[11]);  LCD_puts( buffer);}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;The following is a proposed adaption to allow the handling of a signed value.&amp;nbsp; In this case, the local variable 'i' can be unsigned, since the loop exit does not require a negative value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;void conv_decimal(INT16 val, CHAR8 *buff){   INT16U backup;   INT8U i;   CHAR8 s = ' ';      // Fill buffer with spaces   for (i = 0; i &amp;lt; 6; i++) {      *(buff + i) = ' ';   }      // Null termination for data   *(buff + i) = 0;   if (val &amp;lt; 0) {      val = -val;      s = '-';   }   // Convert binary value to decimal ASCII   for (i = 5; i &amp;gt; 0; i--) {      backup = val;      val /= 10;      *(buff + i) = (backup - (val*10)) + '0';            if (val == 0)  break;   }   *(buff + i) = s;  // Sign character}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:13:11 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/display-decimal-to-LCD/m-p/166124#M5388</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2020-10-29T09:13:11Z</dc:date>
    </item>
    <item>
      <title>Re: display decimal to LCD</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/display-decimal-to-LCD/m-p/166125#M5389</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Mac,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Great&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN&gt;idea of ​​supporting&lt;/SPAN&gt;﻿&amp;nbsp;sign values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Gustavo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Sep 2011 19:31:16 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/display-decimal-to-LCD/m-p/166125#M5389</guid>
      <dc:creator>gustavod</dc:creator>
      <dc:date>2011-09-13T19:31:16Z</dc:date>
    </item>
    <item>
      <title>Re: display decimal to LCD</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/display-decimal-to-LCD/m-p/166126#M5390</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just noticed an inconsistency in the placment of the sign character, depending on whether the for-loop completes, or there is an early break.&amp;nbsp; The index variable 'i' needs to be decremented prior to either event.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;   // Convert binary value to decimal ASCII   for (i = 5; i; ) {      backup = val;      val /= 10;      *(buff + i) = (backup - (val*10)) + '0';      i--;      if (val == 0)  break;   }   *(buff + i) = s;  // Sign character&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards.&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:13:13 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/display-decimal-to-LCD/m-p/166126#M5390</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2020-10-29T09:13:13Z</dc:date>
    </item>
    <item>
      <title>Re: display decimal to LCD</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/display-decimal-to-LCD/m-p/166127#M5391</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the advice Mac.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Gustavo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Sep 2011 23:17:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/display-decimal-to-LCD/m-p/166127#M5391</guid>
      <dc:creator>gustavod</dc:creator>
      <dc:date>2011-09-13T23:17:41Z</dc:date>
    </item>
  </channel>
</rss>

