Lowbyte, Highbyte question


Closed Thread
Results 1 to 7 of 7
  1. #1
    FrankM's Avatar
    FrankM Guest

    Default Lowbyte, Highbyte question

    Hi,

    I need to save a word-variable in an EEPROM.
    So I thought I could save the highbyte and lowbyte of the variable in the EEPROM and set them in my PBP programm together.

    My question is:
    How can I calculate the lowbyte and highbyte of a number?
    I know that I can read an write the highbyte oder lowbyte in PBP but I need to know how to calculate theses values without PBP.

    Thanks
    Frank

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    If I understand you correctly, you want to know how to manually calculate the content of a word and save it in EEPROM for later loading...

    A word is formed up of two bytes. The Lowbyte contains the lower 8-bits and the Highbyte contains the Upper 8-bits.

    How do you calculate it?

    Example 1.

    Value 5000 Decimal is $1388 hex (use your Windows Calculator in Scientific Mode as an easy HEX/Decimal/Binary convertor). The Highbyte is the upper (higher) 8 bits (the $13 of $1388), and the Lowbyte is the lower 8 bits (the $88 of $1388).

    Example 2.

    Value 45000 Decimal is $AFC8. Highbyte is $AF. Lowbyte is $C8.

    Example 3.

    Value 45 Decimal is $002D. Highbyte is Zero ($00), Lowbyte is $2D.

    Note. If using windows calculator, it will surpress leading zero's. Don't forget to ADD them back in. You NEED 4 characters for a word, and two characters for a Byte.

    How do I Save these (manually into EEPROM)?

    Use the DATA Statement. Say I wanted to preset the value 5000 (Decimal) into EEPROM... I could easily do this...

    Data @0,19,136

    Huh? I can hear you say... that doesn't look like 5000... nope but it's the same (in decimal) as this...

    Data @0,$13,$88

    ... and you will (should) have recognised $1388 from Example 1 above.

    Finally, how do I load that into a variable...

    MyWord var Word
    ..
    Read 0,MyWord.Highbyte
    Read 1,MyWord.Lowbyte
    ...
    LCDOut $FE,1,#MyWord," Hex=",HEX4 MyWord

    The LCD will display... "5000 Hex=1388".

    Because the EEPROM is byte sized, it doesn't actually matter if you have it in Highbyte then Lowbyte order, or the other way around... just remember which way you're doing it. This is just as valid...

    Data @0,$88,$13
    ..

    Read 0,MyWord.Lowbyte
    Read 1,MyWord.Highbyte
    ...
    LCDOut $FE,1,#MyWord," Hex=",HEX4 MyWord

    The LCD will still display... "5000 Hex=1388".

    Melanie

  3. #3
    TONIGALEA's Avatar
    TONIGALEA Guest


    Did you find this post helpful? Yes | No

    Smile

    That should get you going but just remember that the DATA command don't work with 18F series

    Toni

  4. #4
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    I thought it was corrected with 2.45 and the latest MPASM.

  5. #5
    TONIGALEA's Avatar
    TONIGALEA Guest


    Did you find this post helpful? Yes | No

    Red face

    Nop

  6. #6
    FrankM's Avatar
    FrankM Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks for these detailed examples.

    Now, I know how it works

    Frank

  7. #7


    Did you find this post helpful? Yes | No

    Question

    Toni,

    It seems to be working just fine for me after upgrading to 2.45 and the latest MPASM.

Similar Threads

  1. Array Question....please help
    By jmoskalski in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 31st October 2009, 01:29
  2. Remote PIC input question
    By Adrian in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 1st September 2007, 15:44
  3. FREQOUT - PWM question
    By Etcho in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 25th February 2007, 23:51
  4. Question for a math guru
    By Christopher4187 in forum General
    Replies: 3
    Last Post: - 22nd November 2006, 09:45
  5. Please answer my first question
    By John_001 in forum Off Topic
    Replies: 1
    Last Post: - 15th September 2006, 06:49

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts