Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
11/20/02 10:51
Read: times


 
#32818 - RE: convert a large hex number to ascii
Here under is what I've wrote to convert a up to long to an ascii value with dot.
I've the double spacing problem also, but the following text is correct
Regards
Stephane


/*-------------------------------------------------------------------------------
Convert a digital value into an ASCII string
	UART_DisplayValue (U32 u32Value, U8 u8NumberOfIntegerDigits, U8 u8NumberOfDecimalDigits)
		u32Value = 32 bits Value to display
		u8NumberOfIntegerDigits = Number of interger digits.
					  If this number is higher than the number of integer
					  digits, it will display the non significant '0'
		u8NumberOfDecimalDigits = Number of decimal digits			
-------------------------------------------------------------------------------*/
void UART_DisplayValue (U32 u32Value, U8 u8NumberOfIntegerDigits, U8 u8NumberOfDecimalDigits)
{
	U8 u8Size; 			/* Size of the table */
	U8 au8ValueToDisplay[10];	/* String where is converted the value */
	S8 s8CharNumber;		/* Character number in the string */
	
	/* Check if the dot has to be displayed and change the Size value */	
	if (u8NumberOfDecimalDigits == 0)
		{
		u8Size = u8NumberOfIntegerDigits + u8NumberOfDecimalDigits;
		}
	else
		{
		u8Size = u8NumberOfIntegerDigits + u8NumberOfDecimalDigits + 1;
		}
	/* Last value of the table = 0 */	
	au8ValueToDisplay[u8Size] = 0;

	/* Convert the value to an ASCII string */			
	for(s8CharNumber=u8Size - 1;s8CharNumber>=0;s8CharNumber--)
	{
		if ((s8CharNumber == u8Size - 1 - u8NumberOfDecimalDigits) && u8NumberOfDecimalDigits !=0)
			{
			au8ValueToDisplay[s8CharNumber] = '.';
			}
		else
			{
			au8ValueToDisplay[s8CharNumber] = u32Value % 10 + '0';
			u32Value /= 10;
			}
	}
	
	/* Display the string */
	UART_Printf(au8ValueToDisplay);
	
}			


List of 9 messages in thread
TopicAuthorDate
convert a large hex number to ascii            01/01/70 00:00      
RE: convert a large hex number to ascii            01/01/70 00:00      
RE: convert a large hex number to ascii            01/01/70 00:00      
RE: convert a large hex number to ascii            01/01/70 00:00      
RE: convert a large hex number to ascii            01/01/70 00:00      
RE: convert a large hex number to ascii            01/01/70 00:00      
RE: convert a large hex number to ascii            01/01/70 00:00      
RE: convert a large hex number to asc            01/01/70 00:00      
RE: convert a large hex number to ascii            01/01/70 00:00      

Back to Subject List