So,
PORTB.6=AR[1] won't work?
So,
PORTB.6=AR[1] won't work?
Hi,
Well, yes, it'll work.
It'll set the state of PortB.6 to what is stored in AR[1], either 1 or 0 at the time that the instruction executes.
What it will NOT do is create a "mirror" where the state of PortB.6 automatically changes whenever AR[1] changes - which I suspect is what you're looking for.
/Henrik.
well,
say I can have
ledpin1 var PORTB.1
then when I issue
high ledpin1
it will make ledpin1 high, right?
so why I can't have array member aliased as port, so when I'll issue
high array[1]
since this previously was set to as alias of portb.1
portb.1 become high?
More simple.
I can have port name aliased to variable, and then I can change the value of variable and this change will change port state, too.
So, I can't have port name aliased to array variable?
Hi,
Yes, that's correct, it'll make PortB.1 high because "all" you've done is assigned the "name" or "identifier" ledpin1 to bit 1 of the register PortB. So when you do HIGH ledpin1 it'll "translate" to HIGH PortB.1 - see, ledpin1 and PortB.1 are one and the same.well,
say I can have
ledpin1 var PORTB.1
then when I issue
high ledpin1
it will make ledpin1 high, right?
Beacuse PortB.1 is at one location in the memory map and Array[1] is at another - they are not one and the same.so why I can't have array member aliased as port, so when I'll issue
high array[1]
since this previously was set to as alias of portb.1
portb.1 become high?
When you create an array you are actually allocating space in RAM for that array as opposed to the previous example where you simply assigned a different "name" to an already existing register. Array[1] and PortB.1 are two different locations.
If you're example would work then one should be able to do
PortB VAR PortA
PortC VAR PortB
PortD VAR PortC
PortA = 0
and expect all ports to clear - it doesn't work that way because PortA is not the same register as PortB just as Array[1] not the same PortB.1 - they are two different things. On the other hand
myPort VAR PortA
myPort = 0
Will clear PortA because all you've done is to create an alternative name or identifier for an already existing register.
You can have multiple names for a single location.
You can not have one name for multiple location.
Does that make sense?
/Henrik.
Ok, I understood the limitations. But why they are present here, and aren't present elsewhere?
And is there a way to overcome them?
Hi,
Where are they not present? Can you show me an example in Sinclair BASIC that does what you want?Ok, I understood the limitations. But why they are present here, and aren't present elsewhere?
Yes and no.And is there a way to overcome them?
There is, to my knowledge, no way to have a pin or port or any other register for that matter aliased into an array in a way that makes the pin/port automagically change when you write to the array. You need to write code that iterates thru the array and writes each port/pin individually and then call that routine each time you change the array. There might be a way (by specifying the absolute adress) to create a BIT array "overlaying" the port register adress space but then all the pins will be consecutive within the array, ie if Array[0] is PortB.0 then Array[1] will be PortB.1 and so on.
If you could explain a little bit what the purpose of this operation is perhaps someone will provide a workable solution.
/Henrik.
Clearly I have erred, first in drawing assumptions and, second by posting untested code based on those assumptions. I dislike being wrong, but I dislike being ignorant even more. Ha! Is this not true for others as well?
So perhaps, it is germane to the discussion, will someone help me to understand my error? In the PBP manual, the statement SYMBOL is used to assign a second name to an existing variable - the process is described as aliasing; I presumed this meant then that both variable names would create pointers to the same RAM address - and be resolved during the assembly process. This misunderstanding was reinforced in the book PIC Basic Projects: 30 Projects Using PicBasic and PicBasic Pro by Dogan Ibrahim where he asserts on page 84:
"In order to make programs more readable, we can assign meaningful names to variables..." He uses the example: SYMBOL Count = B0. The author goes on to note: "This statement does not occupy any location in microcontroller RAM memory".
I accept Henrik's explanation; yet, I struggle to understand the purpose of SYMBOL and how it is used if not in this way.
As an aside, I also note that Curiousone did not make the SYMBOL assignments I suggested in the code he posted.
Bookmarks