Shop OBEX P1 Docs P2 Docs Learn Events
Use of the @@ operator — Parallax Forums

Use of the @@ operator

Thomas StickneyThomas Stickney Posts: 23
edited 2010-07-23 21:02 in Propeller 1
I am having a problem using the @@ operator. The simple code shown below has 13 text strings padded with periods.
Each string is 20 chars long. When the code is run the display shows garbled text·· If I reduce the length of each string
to 17 or fewer chars, the code works fine.

The expressions using @@ are shown with a '<
.

What is the right way to do this so long·strings can be printed?

Thanks in advance!

CON
_CLKMODE······· = XTAL1 + PLL16X
_XINFREQ······· = 5_000_000
rx__pin···· = 31·················· 'pin to receive a serial data signal (from prop plug)
tx__pin···· = 30·················· 'pin to send a serial data signal (to prop plug)
TAB········ = 9··················· 'used with Parallax
LF········· = 10·················· 'Serial Terminal
CR········· = 13·················· '
CLS········ = 16·················· '
VAR
BYTE str_select
OBJ
· DBG·········· : "FullDuplexSerial"
PUB·· Print_Months_Of_Year
· DBG.START (rx__pin, tx__pin, 0, 57600)
·
· WAITCNT(10 * CLKFREQ + CNT)
· DBG.TX (CLS)
· DBG.TX (CR)
· repeat str_select from 0 to 12
··· DBG.DEC (str_select)
··· DBG.TX (TAB)
··· DBG.DEC (STRSIZE(@@months_table[noparse][[/noparse]str_select << 1]))· '<----
··· DBG.TX (TAB)
··· DBG.STR (@@months_table[noparse][[/noparse]str_select << 1])··'<----
··· DBG.STR (STRING(LF, CR))
· DBG.STR (STRING("End", LF, CR))

DAT

months_table
······· WORD· @nomnth
······· WORD· @mnth1
······· WORD· @mnth2
······· WORD· @mnth3
······· WORD· @mnth4
······· WORD· @mnth5
······· WORD· @mnth6
······· WORD· @mnth7
······· WORD· @mnth8
······· WORD· @mnth9
······· WORD· @mnth10
······· WORD· @mnth11
······· WORD· @mnth12
·······
nomnth· BYTE· "
...........",0
mnth1·· BYTE· "January.............",0
mnth2·· BYTE· "Febuary.............",0
mnth3·· BYTE· "March...............",0
mnth4·· BYTE· "April...............",0
mnth5·· BYTE· "May.................",0
mnth6·· BYTE· "June................",0
mnth7·· BYTE· "July................",0
mnth8·· BYTE· "August..............",0
mnth9·· BYTE· "September...........",0
mnth10· BYTE· "October.............",0
mnth11· BYTE· "November............",0
mnth12· BYTE· "December............",0

Comments

  • Dave HeinDave Hein Posts: 6,347
    edited 2010-07-23 20:05
    Use @@word[noparse][[/noparse]@months_table][noparse][[/noparse]str_select] and it will work correctly.· In your code, you are accessing the months_table as a byte array, which is why you have to shift the index up by 1 bit.· You get in trouble when the address is greater than 255.

    I think you could access the months_table directly as a word array if you defined it·as follows:

      months_table word @nomnth, @mnth1, @mnth2, @mnth3, @mnth4, @mnth5
      word @mnth6, @mnth7, @mnth8, @mnth9, @mnth10, @mnth11, @mnth12
    


    Dave

    Post Edited (Dave Hein) : 7/23/2010 8:19:59 PM GMT
  • Thomas StickneyThomas Stickney Posts: 23
    edited 2010-07-23 20:43
    Thanks alot!!!, It Works!!!
  • MagIO2MagIO2 Posts: 2,243
    edited 2010-07-23 20:43
    If your strings all have the same size, why do you need the table then??? You can calculate the address by:

    @nmonth + 20*str_select

    or better ... define a constant which holds the stringlength and use that ... makes it a bit more flexible.
    Calculating saves 13 words of valuable RAM in this case ;o)
    ....
    Or use the table and create the dots via program, which·saves even more memory.



    Post Edited (MagIO2) : 7/23/2010 8:49:17 PM GMT
  • Thomas StickneyThomas Stickney Posts: 23
    edited 2010-07-23 21:02
    I wanted visible charaters to pad the strings to the same length to make testing the code easier
Sign In or Register to comment.