Shop OBEX P1 Docs P2 Docs Learn Events
Confusion about passing an array address — Parallax Forums

Confusion about passing an array address

John CoutureJohn Couture Posts: 370
edited 2008-08-04 19:52 in General Discussion
I must have the syntax incorrect, thus the reason for the question.

In this program I store a 64 bit serial number in a byte array called "DS18B20".· The problem is when I try to print each of the bytes out.· Using Method #1 I call a subroutine called TX_NUM and hand it the DS18B20 address.· It goes off and prints out a goofy number.

In the second method, I don't use the TX_NUM subroutine but rather print each of the eight bytes of the array using a simple for/next loop.· This works great.

Both routines use TX_HEX so that isn't the problem.· It must be something to do with how I am handing the address to the subroutine.· I was trying to pattern it after Jon Williams TX_STR routine but I am obviously doing something wrong.

In analyzing the generated assembler code, the first method does a
MOV __PARAM1,#DS18B20
MOV __PARAMCNT, #1
CALL @__TX_NUM

The second method passes the array differently as in:
MOV W,#DS18B20
ADD W,temp3
MOV FSR,W
MOV __PARAM1,IND
BANK $00
CALL @__TX_HEX

The first method seems to be saying that there is only 1 parameter (a byte) when there should be 2 parameters (a word)?

Am I even close?




' variable declaration

temp2···· var byte
temp3···· var byte
tempW1··· var word
DS18B20···var byte(8)· ' Thermometer Serial Number
'·subroutine declaration

TX_NUM SUB 1,2

'·main program

' Method #1
outputs goofy number
·· TX_NUM DS18B20·· ' Thermometer Serial Number

' Method #2
outputs·correct number
·· for temp3 = 0 to 7
····· TX_HEX DS18B20(temp3)
·· next
'

' Subroutines
'

SUB TX_NUM
· tempW1 = __WPARAM12···· ' get string address
· FOR temp3 = 0 to 7
··· READINC tempW1, temp2··' read a character
··· TX_HEX temp2·············· ·' send the byte
· NEXT
ENDSUB

SUB TX_HEX
' used by both so not important
ENDSUB

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
John J. Couture

San Diego Miramar College

Comments

  • JonnyMacJonnyMac Posts: 9,215
    edited 2008-08-03 21:35
    The problem is TX_NUM routine: it's waiting on a two-byte address and wanting to read from program space while your data is actually in RAM, uses a one-byte address, and cannot be read by READ or READINC. You need to read it using the internal __RAM() array, like this:

    SUB TX_NUM
      tmpB1 = __PARAM1                      ' collect address pointer
    
      FOR tmpB2 = 0 to 7                    ' loop through eight bytes
        TX_HEX __RAM(tmpB1)                 ' print the byte
        INC tmpB1                           ' update the pointer
      NEXT
      ENDSUB
    


    In your first example you're passing the RAM address, in essence a pointer to the array. You can use this as an index within the __RAM array to read the value.

    Post Edited (JonnyMac) : 8/3/2008 9:40:21 PM GMT
  • John CoutureJohn Couture Posts: 370
    edited 2008-08-04 19:52
    WoW! Is that kool!

    Thanks Jon!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John J. Couture

    San Diego Miramar College
Sign In or Register to comment.