' String to Hex routine Sub PADSTRHEX(VAL As uLong, S As String) zPadStrHex(val,s,0,"0") End Sub Sub PADSTRHEX(VAL As uLong, S As String,length As uByte) zPadStrHex(val,s,length,"0") End Sub Sub PADSTRHEX(VAL As uLong, S As String,length As uByte,padchar As uByte) zPadStrHex(val,s,length,padchar) End Sub Sub zPADSTRHEX(VAL As uLong, S As String,length As uByte,padchar As uByte) ' length is the desired length of the resulting string, padded on the left with padchar ' If zero, then no padding will be performed, and leading zeros will be removed ' padchar is the character to use for padding. FSR2=ADDR(S) Call B2HEX(VAL.Byte3) Call B2HEX(VAL.Byte2) Call B2HEX(VAL.Byte1) Call B2HEX(VAL.Byte0) POSTINC2=0 ' Find 1st non-zero char fsr2 = addr(s) fsr1 = fsr2 - 1 While preinc1 = "0" End While ' If FSR1 points to NULL then back up one If INDF1=0 Then WREG = POSTDEC1 ' FSR1 -> 1st non-zero character ' If we are to pad to a specific length, set FSR1 -> 1st char to copy ' Otherwise we just copy starting with th 1st non-zero char If length <> 0 Then ' length = (length+1) And 0xFE fsr1 = fsr2 + (8 - length) Else ' We want to put out an even number of chars. ' If the low-order bits of FSR0 and FSR0 are the same, then the resulting ' length will be even. If odd, we must back up FSR1 by 1 If fsr2.0 <> fsr1.0 Then WREG = POSTDEC1 End If End If ' Copy string pointed to by FSR1 to start of S, ending it with the 0x00 While indf1<>0 postinc2 = postinc1 End While indf2 = 0 'null-terminate If length <> 0 And padchar <> "0" Then ' Now replace leading zeros with PADCHAR, unless, of course, PADCHAR is "0" fsr2 = addr(s) While indf2="0" postinc2 = PADCHAR End While If INDF2=0 Then WREG = POSTDEC2 INDF2="0" End If End If End Sub