• PicŪ Basic


  • macroFORMAT formats and displays values up to 31 bytes wide as a string

    With macroFORMAT you can now format and display any value up to 31 bytes wide as a string.
    This is especially usefully in debugging and displaying routines in Alberto's NBitMATH.

    Formating includes a thousands separator, decimal places and negative offset.
    Thousands separator will add an apostrophe per thousands.
    A 1 in the macro thousands parameter will add apostrophes and a 0 will not.

    Decimal places will place a decimal point as user sets in the macro parameter.
    User is to multiply the calculation value by 10 per decimal point.
    This is extremely useful when using division.

    Negative offset will display as a negative any value less than the user set value in the negative macro parameter.
    User is to add to the calculation the maximum negative value required.
    For instance if the macro resulting value is 990 and the negative parameter is 1000 macroFORMAT will display a -10.
    If the macro resulting value is 0 and the negative parameter is 1000 macroFORMAT will display a -1000.


    'An example macroFORMAT display of an integer with thousands separator, 3 decimal places and a negative offset of 1000:
    dMY_VAL_PTR = 2147483648 'Enter integer to display
    yMY_VAL_LEN = 0 'Set to 0 to display an integer
    macroFORMAT yMY_VAL_LEN, dMY_VAL_PTR, 1, 3, 1000
    HSerOut[sFORMATED,13] 'will display "+2'146'483.648"

    'An example macroFORMAT display of a variable with thousands separator, 3 decimal places and a negative offset of 1000:
    dMY_VAL = 990000
    dMY_VAL_PTR = VarPtr(dMY_VAL) 'Enter variable to display.
    yMY_VAL_LEN = SizeOf(dMY_VAL) 'Enter variable to display.
    macroFORMAT yMY_VAL_LEN, dMY_VAL_PTR, 1, 3, 1000
    HSerOut[sFORMATED,13] 'will display "-10.000"

    'An example macroFORMAT display of an NBitMath register with thousands separator, 4 decimal places and a negative offset of 0:
    'Requires Alberto Freixanet's P-NBitMath.inc
    'Download macroFORMAT Demo.bas for complete example
    MOVE_CVA 4294967295, REG_B 'LOAD REG_B
    MOVE_CVA 4294967200, REG_C 'LOAD REG_C
    MATH_MUL REG_B, REG_C, REG_A 'equivalent of REG_B * REG_C = REG_A
    dMY_VAL_PTR = VarPtr(REG_A) 'Enter register to display.
    yMY_VAL_LEN = SizeOf(REG_A) 'Enter register to display.
    macroFORMAT yMY_VAL_LEN, dMY_VAL_PTR, 1, 4, 0
    HSerOut[sFORMATED,13] 'will display "1'844'674'365'709'772.400'0"
    'macroFORMAT can display full width of NBitMath register at any point in a calculation.

    Download the latest version of macroFORMAT or additionally see NBitMath to calculate in values up to 31 bytes wide.

    macroFORMAT formats and displays values up to 31 bytes wide as a string forum.

    Thanks to JohnB for help with macro's.

    Norm
  • Recent Activity

    xldaedalus-432

    Mysterious PORTB problem

    Thread Starter: xldaedalus

    I'm using Proton+ to develop firmware for a product with switches. The MCU is an 18F26K22. Most of the switches reside on PORTB. I am NOT using a...

    xldaedalus Today, 03:21 Go to last post
    towlerg-21522

    PIC18F1330 PLL problem

    Thread Starter: rcurl

    I'm just starting out on a new project that uses a PIC18F1330. I haven't used this specific chip before, so I began by trying to blink an LED just...

    towlerg Today, 02:15 Go to last post
    towlerg-21522

    Lin bus and auto baud detection

    Thread Starter: Tim

    Lin bus looks to be a great system for an application i'm working on. One of the main things is the slave can be really simple without needing a...

    towlerg Yesterday, 15:13 Go to last post