Confusion about passing an array address
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
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
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
Thanks Jon!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
John J. Couture
San Diego Miramar College