Shop OBEX P1 Docs P2 Docs Learn Events
Reconstituting 12-bit values from 8-bit eeprom — Parallax Forums

Reconstituting 12-bit values from 8-bit eeprom

Andy McLeodAndy McLeod Posts: 40
edited 2006-11-06 18:15 in BASIC Stamp
Witness this loop:

FOR address = 0 TO 384 STEP 2
STORE bank
GOSUB convert ' Get data from ADC.
WRITE address, AD.LOWBYTE
WRITE address + 1, AD.HIGHBYTE
SEROUT 7,n9600,[noparse][[/noparse]I,L2_C6,DEC AD,CR]
DEBUG DEC AD, " ", DEC AD.HIGHBYTE, " ", DEC AD.LOWBYTE, " ", DEC bank, " ", DEC address, CR
PAUSE 50 ' Wait a twentieth second.
NEXT
END

This works great to write decimal 12-bit ADC values to the eeprom of the BS2pe (and a serial LCD) in lowbyte and highbyte form, splitting the 12-bit value between 2 single byte registers. I am, however, having difficulty reconstituting the 2 1-byte binary(?) values back into their single decimal form. Does anyone have code or inspiration for this operation?

Thank you.

Comments

  • metron9metron9 Posts: 1,100
    edited 2006-11-06 17:43
    Just read back in the high byte and low byte, multiply the high byte by 256 and add the low byte and store in a word.

    if H=high byte and L=Low byte and W=word

    w=(H*256)+L

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think outside the BOX!
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-11-06 17:49
    Andy,
    ·
    ·· For the most part you just do it in reverse…when you READ the values back into the variable using the LOWBYTE/HIGHBYTE modifiers it will put the full value back into the variable.· And again you’ll need to step in increments of two.· You should even be able to use the same variable names.· I hope this helps.· Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-11-06 17:53
    Metron,
    ·
    ·· There is no need to do all the math.· Simply placing the appropriate LOWBYTE/HIGHBYTE values into a Word variable will be quicker.· Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • Andy McLeodAndy McLeod Posts: 40
    edited 2006-11-06 18:15
    Bingo, thank you much!
Sign In or Register to comment.