Announcements
IMPORTANT: Cypress Developer Community is transitioning on October 20th. To learn more and be prepared for this change, check out our latest announcement.
cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1 MCU

Anonymous
Not applicable

How do I convert the hex to a decimal base 0 to 9.

   

 

   

 

   

 

   

void Display_Result(void)
{
  
      LCD_Char_Position(0,6);
      LCD_Char_PrintInt8(HYT221_Read_Buff[0] & 0x3f);         //Mask HYT humidity the highest two status bits
      LCD_Char_PrintInt8(HYT221_Read_Buff[1]);
      LCD_Char_PrintNumber(unit8,HYT221_Read_Buff);  
      temp = astio(temp, HYT221_Read_Buff[1], 16);
      LCD_Char_PrintString("      ");    
      LCD_Char_Position(1,6);
      LCD_Char_PrintInt8(HYT221_Read_Buff[2]);
      LCD_Char_PrintInt8(HYT221_Read_Buff[3] & 0xfc);       //Mask HYT temperature the lowest two status bits
      LCD_Char_PrintString("      ");      
}

0 Likes
6 Replies
Anonymous
Not applicable

My original email was wrong. below is the corrected version

   

 

   

void Display_Result(void)
{
  
      LCD_Char_Position(0,6);
      LCD_Char_PrintInt8(HYT221_Read_Buff[0] & 0x3f);         //Mask HYT humidity the highest two status bits
      LCD_Char_PrintInt8(HYT221_Read_Buff[1]);
      LCD_Char_PrintString("      ");    
      LCD_Char_Position(1,6);
      LCD_Char_PrintInt8(HYT221_Read_Buff[2]);
      LCD_Char_PrintInt8(HYT221_Read_Buff[3] & 0xfc);       //Mask HYT temperature the lowest two status bits
      LCD_Char_PrintString("      ");      
}

0 Likes
Anonymous
Not applicable

How about LCD_Char_PrintNumber()?

0 Likes
Anonymous
Not applicable

I believe I tried it. I received an email that I needed to use UNIT16. THere is the long and hard way. But I was hoping Kiel software had a function to convert the the number. I have a hex value ex: 3fad. This needs to be converted to a decimal value.

   

 

   

Thanks for the reply.

   

 

   

Philip

0 Likes
Bob_Marlowe
Expert II

when you #include <stdio.h> you may use sprintf() to convert any number to a string which you may print on LCD.

   

Parameters for sprintf() are here http://publications.gbdirect.co.uk/c_book/chapter9/formatted_io.html 

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Thanks for the feedback,

   

 

   

 

   

My code Is as follows. I get the the hex vale in 4 digits. With the sprintf(0 can I get the complete decimal value? 

   

 

   

 

   

void Display_Result(void)
{

   

 LCD_Char_Position(0,6);
    LCD_Char_PrintInt8(HYT221_Read_Buff[0] & 0x3f);  //Mask HYT humidity the highest two status bits
 LCD_Char_PrintInt8(HYT221_Read_Buff[1]);
 LCD_Char_PrintString("      "); 
  

   

///////////////////////////////////////////////////////////
 // sprintf()  insert conversion here ?
 /////////////////////////////////////////////////////////
    LCD_Char_Position(1,6);
   
  
   
    LCD_Char_PrintInt8(HYT221_Read_Buff[2]);
 LCD_Char_PrintInt8(HYT221_Read_Buff[3] & 0xfc);  //Mask HYT temperature the lowest two status bits
    LCD_Char_PrintString("      ");  
}

0 Likes
Anonymous
Not applicable

Bob,

   

 

   

     Thanks for the help. My Cypress compiler at work will compile my software fine. But the same software on my home PC will not compile. I am uninstall Creator 2.1 and 2.2 CP5 from my work PC now. Then I will do a clean install? That did not occur to me to check the copilers.

   

Thanks Bob,

   

Phi

0 Likes