Shop OBEX P1 Docs P2 Docs Learn Events
sx/b DATA question — Parallax Forums

sx/b DATA question

stefstef Posts: 173
edited 2007-07-26 16:14 in General Discussion
Hi

I'm working on a little project. I neet to store a lot off data at compile time to send out later on the serial colnnection.
I want to use the DATA statemend but I had a little question on it.

Can you store multiple byte values, separated by a "," on one line?

ex
Preset1:
DATA %10100000, %00000000, %00000000, %00000111, %00000000, %00010100, %00111000
DATA %10100001, %00000000, %00000000, %00000111, %00000000, %00010000, %00111001

see example.

And how do you recall them with read + indx??

Thanks in advance.

stef


·

Comments

  • OzStampOzStamp Posts: 377
    edited 2007-07-26 12:33
    Hi Stef

    Yes a comma is all that is needed.
    You may want to revert to coding in Hex notation so you can fit more on 1 line

    See the SX B compiler online help file,
    The example for the keypad encoder down the bottom shows you how
    to retrieve the values from the data look up tables.

    Cheers

    Ronald Nollet
  • T&E EngineerT&E Engineer Posts: 1,396
    edited 2007-07-26 16:14
    You may also want to look at doing a WORD Read. JonnyMac wrote a nice function to do this.
    For example:········
    
    
    data1   VAR Word
    data2   VAR Word           
    data3   VAR Word  
     
    tmpW1  VAR Word
    tmpW2  VAR Word
    tmpB1  VAR Byte
    J  VAR Byte
    .
    .
    WREAD  FUNC 2, 3  ' read word from WDATA
    .
    .
     
    FOR J = 0 TO 15
     data2 = WREAD dat2b, J
     data3 = WREAD dat3b, J
     'IF data2 = %0000000000001111 THEN data2 = 0
     'IF data3 = %1111111111110000 THEN data3 = 1
    NEXT
    .
    .
    
    ' Use: result = WREAD table, element
    ' -- "table" is a WDATA table
    ' -- "element" is the nth word in the WDATA table
    FUNC WREAD
      tmpW1 = __WPARAM12    ' get table address
      tmpB1 = __PARAM3    ' get element
      tmpB1 = tmpB1 << 1    ' x2; convert to LSB offset 
      tmpW1 = tmpW1 + tmpB1    ' add offset to address
      READ tmpW1, tmpW2_LSB, tmpW2_MSB
      RETURN tmpW2
      ENDFUNC
    .
    .
    dat2b:
     WDATA %0000000000000001
     WDATA %0000000000000011
     WDATA %0000000000000111
     WDATA %0000000000001111
     WDATA %0000000000011111
     WDATA %0000000000111111
     WDATA %0000000001111111
     WDATA %0000000011111111
     WDATA %0000000111111111
     WDATA %0000001111111111
     WDATA %0000011111111111
     WDATA %0000111111111111
     WDATA %0001111111111111
     WDATA %0011111111111111
     WDATA %0111111111111111
     WDATA %1111111111111111
     
    dat3b:
     WDATA %1000000000000000 
     WDATA %1100000000000000
     WDATA %1110000000000000
     WDATA %1111000000000000
     WDATA %1111100000000000
     WDATA %1111110000000000
     WDATA %1111111000000000
     WDATA %1111111100000000
     WDATA %1111111110000000
     WDATA %1111111111000000
     WDATA %1111111111100000
     WDATA %1111111111110000
     WDATA %1111111111111000
     WDATA %1111111111111100
     WDATA %1111111111111110
     WDATA %1111111111111111
    
    



    Also look at the attached file - example from JonnyMac.



    Post Edited (T&E Engineer) : 7/26/2007 5:09:23 PM GMT
Sign In or Register to comment.