• PicŪ Basic


  • Pack small variables EEPROM

    I use a macro to pack small variables into EEDATA

    It has been great for me, saving lots of EData & Cdata space.

    This example "packs" the following into 4 bytes (of EEPROM):
    - variable index within RAM array (handles BYE & Word variables)
    - whether Byte or Word
    - displayed format: signed, leading & trailing digits
    - divisor (eg Amp is stored as mA)
    - unit Estr string address
    - decimal place may be UNIT (string) character (eg 5V6)
    - row & column (or ignore this codingl)

    Eg.
    Macro=
    ;define Macros to eliminate "gosub" text etcs. Include variable name into macro, so do NOT need FSR.
    $define XmSp(X, m, S, p) $eval (((X & 0x01) << 7) + ((m & 0x03) << 5) + ((S & 0x01) << 4) + (p & 0x07)) 'Macro to COMBINE for Byte_1 28-Aug-2011
    $define
    XmSBp(X, m, S, B, p) $eval (((X & 0x01) << 7) + ((m & 0x03) << 5) + ((S & 0x01) << 4) + ((B & 0x01) << 3) + (p & 0x07)) 'Macro to COMBINE for Byte_1 (var=BYTE)

    $define rcUd(r, c, U, d) $eval ((((r - 1) & 0x01) << 7) + (((c - 1) & 0x0F) << 3) + ((U & 0x01) << 2) + (d & 0x03)) 'Macro to COMBINE for Byte_2

    Usage example:

    'EStr data for Unit character/s
    UE2_Ah EData &quot;Ah&quot;,0 'AmpHour
    UE2_V EData &quot;V&quot;,0 'Volt
    UE2_A EData &quot;A&quot;,0 'Amp


    'lookup table for variable value (as index to input_mV array), displayed format and Unit (Estr) (suits XWIU style)

    ;F_example edata XmSp(1,m,S,p), rcUd(r,c,U,d), index, uea ;Flags: Sign, Unit_as_DP; m=divisor, p=digit, d=decimal, row, column, index [0..n WORD], uea=unit_Estr_addr

    F_output_mV EData XmSp(1,3,0,2), rcUd(2, 5,0,1), 1, UE2_V ;calculated output voltage mV (0 .. +31767) &quot;pp.dV&quot;
    F_PSP_mA EData XmSp(1,3,0,2), rcUd(1,12,0,0), 2, UE2_A ;mains PSP Output current mA (0 .. +63535) &quot;ppA&quot;

    Hope these ideas may help save space.

    I have not shown my universal print routines and their macros here.
    Alan.

    Ranox on forum
  • Recent Activity

    teo-16018

    Microsoft security essentials blues

    Thread Starter: shantanu@india

    Hi, A strange thing happened just now.My Windows 7 Micrsoft Sercurity Essentials suddenly gave a warning that prplus.exe(Compiler) is a potential...

    teo Today, 19:23 Go to last post
    David Barker-251

    UMC bootloader 18F46K22

    Thread Starter: shunt010

    Hi all. I am trying to build a UMC bootloader file for the 18F46K22, and it doesn't appear to work. It returns (in the error log) Error ...

    David Barker Today, 11:20 Go to last post
    barak-1433

    SPI mssp

    Thread Starter: picprotonguy

    Just ordered Digital to Analog IC MCP4822 with SPI interface and immediately opened proton manual. I'm very disappointed, it looks like Proton...

    barak Today, 16:06 Go to last post