access to byte array passed to subroutine
Peter Verkaik
Posts: 3,956
I try to read bytes from an array passed to a subroutine
for further processing.
SUB mtI2CwritePage
· mtVARaddress_LSB = __PARAM1
· mtVARaddress_MSB = __PARAM2
· mtVARrdata = __PARAM3
· mtI2C_START
· mtI2C_SEND mtVARi2cid
· mtI2C_SEND mtVARaddress_LSB
· mtI2C_SEND mtVARaddress_MSB
· for mtVARwdata=0 to __PARAM4
··· __PARAM2 = mtVARrdata[noparse][[/noparse]mtVARwdata]·· 'this gives error
··· mtI2C_SEND __PARAM2
· next
· mtI2C_STOP
· return
the sub is called with mtI2CwritePage address,array,count· 'address is word, array is byte, count is byte
array is the address of a byte array.
How to make the subroutine know that array (__PARAM3) is the address of a byte array?
regards peter
for further processing.
SUB mtI2CwritePage
· mtVARaddress_LSB = __PARAM1
· mtVARaddress_MSB = __PARAM2
· mtVARrdata = __PARAM3
· mtI2C_START
· mtI2C_SEND mtVARi2cid
· mtI2C_SEND mtVARaddress_LSB
· mtI2C_SEND mtVARaddress_MSB
· for mtVARwdata=0 to __PARAM4
··· __PARAM2 = mtVARrdata[noparse][[/noparse]mtVARwdata]·· 'this gives error
··· mtI2C_SEND __PARAM2
· next
· mtI2C_STOP
· return
the sub is called with mtI2CwritePage address,array,count· 'address is word, array is byte, count is byte
array is the address of a byte array.
How to make the subroutine know that array (__PARAM3) is the address of a byte array?
regards peter
Comments
Arrays are passed by address (byte). So you use the virtual array "__RAM" to access the data in the array.
P.S. You should store your __PARAMx values as soon as possible. Many commands use the as temporary storage (overwriting their value). This can cause problems that are very hard to find.
Bean
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap used 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
SX-Video Display Modules www.sxvm.com
Stuff I'm selling on ebay http://search.ebay.com/_W0QQsassZhittconsultingQQhtZ-1
"People who are willing to trade their freedom for·security deserve neither and will lose both." Benjamin Franklin
Post Edited (Bean (Hitt Consulting)) : 12/9/2006 12:19:07 PM GMT
The following compiles,
SUB mtI2CwritePage
· mtVARaddress_LSB = __PARAM1
· mtVARaddress_MSB = __PARAM2
· mtVARrdata = __PARAM3
· mtI2C_START
· mtI2C_SEND mtVARi2cid
· mtI2C_SEND mtVARaddress_LSB
· mtI2C_SEND mtVARaddress_MSB
· for mtVARwdata=0 to __PARAM4
··· __PARAM3 = mtVARrdata+mtVARwdata
··· mtI2C_SEND __RAM(__PARAM3)
· next
· mtI2C_STOP
· return
Is this the easiest way when using sx48?
regards peter
Your too fast [noparse];)[/noparse] See my edited post above.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap used 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
SX-Video Display Modules www.sxvm.com
Stuff I'm selling on ebay http://search.ebay.com/_W0QQsassZhittconsultingQQhtZ-1
"People who are willing to trade their freedom for·security deserve neither and will lose both." Benjamin Franklin
·
Your example showed the for/next must start with 1.
I had 0 and noticed in the list view it then loops one too many.
I try to use as few temporary variables as possible.
It is quite safe to use the higher __PARAMx directly
as long as called functions have only 1 parameter.
Obviously I check that in the list view and if any __PARAMx is used
that my code is using, then I introduce a new temporary variable.
regards peter
mtVAR··var·byte(6)
mtVARwdata·var·mtVAR(0)
mtVARrdata·var·mtVAR(1)
mtVARi2cid·var·mtVAR(2)
mtVARcount·var·mtVAR(3)
mtVARaddressL·var·mtVAR(4)
mtVARaddressH·var·mtVAR(5)
then the subroutine
SUB mtI2CwritePage
· mtVARaddressL = __PARAM1
· mtVARaddressH = __PARAM2
· mtVARrdata = __PARAM3
· mtVARcount = __PARAM4
· mtI2C_START
· mtI2C_SEND mtVARi2cid
· mtI2C_SEND mtVARaddressL
· mtI2C_SEND mtVARaddressH
· for mtVARwdata=1 to mtVARcount· 'error
··· __PARAM3 = mtVARrdata+mtVARwdata
··· mtI2C_SEND __RAM(__PARAM3)
· next
· mtI2C_STOP
· return
gives compile error
byte parameter expected "mtVARwdata"
but mtVARwdata is defined as a byte
How to resolve this?
regards peter