Hi,
It doesn't work like that - any of it I'm afraid.
First Malcolms example,
When you declare an alias to a variable or register, like dht_data1 var PORTA.0 the dht_data1 part of it is just a name for you and me to remember. For the compiler it gets converted to an adress in memory which in this case will be the exact same adress as PortA.0 has.
This means that you can not do dht_data(y) because there is no variable called dht_data, the variable is called dht_data1.
So, HIGH dht_data1 works because it's exactly equivalent to HIGH PortA.0 - no difference.
But HIGH dht_data(y) doesn't work, (and doesn't compile) because there is no variable called dht_data. If you did dht_data var PortA.0 then doing HIGH dht_data(y) would set PortA.0+y....I think....which possibly could work in this particular case since the bits are consecutive (in a row) on PortA.
When you declare an array, which is what you're doing with dht_data VAR bit[4] the compiler reserves memory, in RAM, for 4 consecutive bits.
You can then, if you want, assign an alias (which is just a different name) TO these individual bits like Bit_0_of_dht_data_bit_array VAR dht_data[0]. This means that reading/writing Bit_0_of_dht_data_bit_array accesses the same memory location as reading/Writing dht_data[0]. The key here is that it's the very same bit in RAM that is accessed in both cases. You can not have an array of bits in ram and then try to alias any of those bit to another bit (like a port pin) because then it isn't pointing at the same location any more.
In Archangels example strange things will happen because HIGH/LOW is designed to work on PORT registers only and relies on a fixed "offset" between the PORT register and the TRIS register (since HIGH/LOW clears the TRIS bit). Using HIGH/LOW on a variable in RAM will likely corrupt other parts of the memory since it will then (when trying to clear the TRIS bit) clear another bit - which you don't want.
Malcolm, you're still on PBP2.6 aren't you? That's fine but if download the PBP3 manual there's an updated section (7.6) that explains how arrays and offsets work.
/Henrik.




Bookmarks