How to write a macro sub routine?

How to write a macro sub routine?
none 0.0 0

I wrote a function to convert BCD to ASCII in library but It had some error when Compile. Please show me how to fix it?

//
sub unsigned char bcdToAscii(unsigned int source, unsigned char *dest)
dest ++
*dest = ( source & 0x000f ) + 0x30
dest --
*dest = ( ( source >> 4 ) & 0x000f ) + 0x30		
return *dest
end sub
//

Hi @zippo,

Thank you for contributing to our forum!

We do not support pointers such as by using *varName in a macro. Also, shortcut functions like ++ must also be replaced with the equivalent varName = varName + 1 .

To convert binary or numeric values to ASCII characters I would recommend using a process similar to this:
Note: The type short may represent integers, binary, or bcd numbers.

macro_command main()
	short source = 16961 					// 16-bit source var
	char dst[2] 							// 8-bit array of 2
	
	// 16961 		|		 0100 0010 0100 0001 
	// "AB"			|			 B 		   A
	//                         High       Low
	
	LOBYTE(source, dst[0])
	HIBYTE(source, dst[1])
	
	SetData(dst[0], "Local HMI", LW, 0, 2)
	
end macro_command

Note: You can use a loop to parse multiple instances of short and output them to a char array.