Reconstituting 12-bit values from 8-bit eeprom
Andy McLeod
Posts: 40
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.
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
if H=high byte and L=Low byte and W=word
w=(H*256)+L
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Think outside the BOX!
·
·· 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
·
·· 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