1

One of my engineers came to me with a question that I can't answer. This is for a project using a PIC16F controller, all written in assembler.

He is defining a constant that he wants his program to use in two different ways: as an integer for use within the program and the same integer expressed as an ASCII string for use within his serial communication routines.

The standard way that I have done this in the past is to simply have the PIC convert that constant to an ASCII string at run time. However, since it is a constant, it should be possible to have the compiler do the conversion.

I've thought about it and the answer doesn't immediately come to mind.

He is defining the constant as follows:

  #DEFINE gFORCE_MIN 250

He is defining the ASCII equivalent as follows:

  #DEFINE gFORCE_MIN_STR "250"

The idea is that he modifies only one constant and the assembler automatically converts that constant into the double-quotes delimited ASCII value.

His last attempt returns the following after assembly:

  DT "gFORCE value ","gFORCE_MIN"  returns:  gFORCE value gFORCE_MIN 

He is currently using MPLAB 8.92.

Chris Stratton
  • 33,282
  • 3
  • 43
  • 89
Dwayne Reid
  • 23,390
  • 2
  • 35
  • 67
  • 4
    The search terms you're looking for are "stringify" and "token pasting". See [this](https://stackoverflow.com/questions/240353/convert-a-preprocessor-token-to-a-string) over at Stack Overflow. – brhans Oct 03 '18 at 00:53
  • If you do a lot of this it might help to install the basic UTF-8 chart which includes char numbers 1 - 255. Those over 127 are considered 8 bit Unicode. The char 250 is ú. –  Oct 03 '18 at 02:19
  • @brhans Different language. – pipe Oct 04 '18 at 13:47
  • 1
    @Sparky256 - it's not a character code, it's a number that needs to be represented as a string. – Chris Stratton Oct 04 '18 at 15:25

0 Answers0