data with wordvar?


Closed Thread
Results 1 to 11 of 11

Hybrid View

  1. #1
    Join Date
    Jul 2006
    Posts
    60

    Default data with wordvar?

    Hello

    Can the DATA command handle word variable?
    like this

    Data @1, $1DF4, $FAFD, $AB13, $3FC3

    For i = 1 to 4
    read i,wordvar
    'do anything
    next i

    Is this correct?

    Thanks
    Best Regards
    Pedro

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Pedro Santos View Post
    Hello

    Can the DATA command handle word variable?
    like this

    Data @1, $1DF4, $FAFD, $AB13, $3FC3

    For i = 1 to 4
    read i,wordvar
    'do anything
    next i

    Is this correct?

    Thanks
    Best Regards
    Pedro
    Data @0, $1DF4, $FAFD, $AB13, $3FC3

    For i = 0 to 3
    read i , wordvar.lowbyte
    read i , workvar.highbyte
    'do anything
    next i

    1st time thru wordvar = $1DF4
    2nd time thru wordvar = $FAFD
    3rd time thru wordvar = $AB13
    4th time thru wordvar = $3FC3

    It's all right there in your handy PicBasicPro manual that you got when you bought PicBasicPro, page 53 and page 123.
    Mine's green, what color is yours?

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Mine's green, what color is yours?
    Mine's Olive.

    And yup, right there on page 53 is all about the DATA statement.

    And in it, it says ...
    "Only the least significant byte of numeric values are stored unless the WORD modifier is used"

    Therefore:

    Data @1, WORD $1DF4, WORD $FAFD, WORD $AB13, WORD $3FC3

    Regards,
    DT

  4. #4
    Join Date
    Jul 2006
    Posts
    60


    Did you find this post helpful? Yes | No

    Default

    Hello Darrel

    data @1, word $E276, word $E183, word $8001, word $EF90

    and how can i read the variavle?

    so?

    for i = 1 to 4
    read i, wordvar
    ''do anything
    next i

    is that correct?

    Thanks

    Regards

    Pedro

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Pedro Santos View Post
    Hello Darrel

    data @1, word $E276, word $E183, word $8001, word $EF90

    and how can i read the variavle?

    so?

    for i = 1 to 4
    read i, wordvar
    ''do anything
    next i

    is that correct?

    Thanks

    Regards

    Pedro
    Did you even see post #2 above?

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Well, like everthing else, there's probably 100 different ways to go about it. And the best way depends on how your program needs to use it.

    But the biggest thing to remember is that you can only READ 1 byte at a time. So, to read a WORD value must be done in 2 operations.
    Code:
    READ  1, wordvar.LowByte
    READ  2, wordvar.HighByte
    If you wanted to read the data into an array of WORDS, you could do this...
    Code:
    ArraySize   CON 4
    WordArray   VAR WORD[ArraySize]
    Ptr         VAR BYTE
    DataStart   VAR BYTE
    
    DataStart = 1
    For Ptr = 0 to (ArraySize * 2) -1
        READ  DataStart + Ptr, WordArray.LowByte(Ptr)
    Next Ptr
    If you just want to read individual words, then you'll need to know where they are located in EEPROM. You could just count bytes in the data and use the starting address as the location for the READ. But as the program changes, the data might change too, and all those locations you counted fly out the window.

    So the easiest way to deal with individual Locations is to give them names in the DATA statement. Then when things change, the pointers to the data change too.
    Code:
    Calibration  DATA @1, WORD $1DF4
    Offset       DATA WORD $FAFD
    Something    DATA WORD $AB13
    Another      DATA WORD $3FC3
    
    READ  Something, wordvar.LowByte
    READ  Something + 1, wordvar.HighByte
    
    ; returns $AB13
    
    READ  Calibration, wordvar.LowByte
    READ  Calibration + 1, wordvar.HighByte
    
    ; returns $1DF4
    Well, that's 3 possibles, at least 97 more available.

    HTH,
    DT

  7. #7
    Join Date
    Jul 2006
    Posts
    60


    Did you find this post helpful? Yes | No

    Default

    Thank's Darrel for your help

    Regards

    Pedro

  8. #8
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Lightbulb

    Oh Yeah, forgot to mention that you might find this usefull as well.

    EEPROM Variables (EE_Vars.pbp)
    http://www.picbasic.co.uk/forum/showthread.php?t=2444
    <br>
    DT

Similar Threads

  1. Using Nokia LCD
    By BobP in forum mel PIC BASIC Pro
    Replies: 300
    Last Post: - 3rd May 2018, 04:47
  2. Nokia 3310 display text
    By chai98a in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 26th August 2007, 03:39
  3. Big characters on HD44780 4x20
    By erpalma in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 7th January 2007, 02:21
  4. LCD + bar graph
    By DynamoBen in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 5th October 2005, 14:50
  5. Sinus calculating !
    By Don Mario in forum mel PIC BASIC Pro
    Replies: 29
    Last Post: - 28th November 2004, 23:56

Members who have read this thread : 0

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