Picaxe28X1 - PortC masking

kenmac

Member
Hi folks,
I haven't been here for a while.
I'm starting a new project using a 28X1 chip, a type I haven't used before.
I've configured PortC as all outputs [ dirsc = %11111111 ]
The first four bits will be varied together, while maintaining the current status of the other bits.
To do this, I was attempting to use masking.
However, when I used the code [ pinsc = pinsc | value ] it didn't pass the syntax check.
Should that method work?
If not, what would be the correct method?

Editor V5.4.0, Win XP Pro

kenmac
 

Technical

Technical Support
Staff member
That would work with the 28X2 usings outpinsC, but for the 28X1 you need to keep a local 'shadow' copy and work on that instead (as outpinsc is not a 'real' variable as it on the 28X2):

symbol mypinsc = b2

mypinsc = mypinsc & % 10101010
pinsc = mypinsc
 

kenmac

Member
Thanks Technical.
I must have misinterpreted the manual info.

Hi westaus55,
I've been in Propeller world for awhile - very interesting.

kenmac
 

kenmac

Member
Technical.
Actually that doesn't solve the problem.
To retain the status of the portC "other pins" we need to be able to read the current value of portC.
I tried to do this with [ mypinsc = pinsc ] but this was also rejected in the syntax check.
Without the ability to read the current portC data , masking on that port cannot be achieved.

kenmac
 

westaust55

Moderator
Try with the OUTPINSC function/variable

By way of example this simulates okay:

Code:
pinsc = %01010101
FOR b0 = 1 TO 255
  b1 = b0 AND $1F		         ; only "counting on the lower 5 bits for demo
  pinsc = outpinsC AND $E0 OR b1 ; keep the upper three bits in this case and adjust the lower 5 bits as desired
NEXT b0
 
Last edited:

hippy

Technical Support
Staff member
To retain the status of the portC "other pins" we need to be able to read the current value of portC.
It's not necessary to read the current value of Port C, you only need to know what Port C value is.

Let's imagine you need to send someone a list of things to buy from the shops. You write a list. You keep that list and send a copy of that list to your personal shopper. If you think of something else you need you add it to your list and send them a new copy of that list. They throw the old one away and use the latest.

You can't update the list they have ( because you don't have it ) but you can update your list because you do have it. They have the instructing shopping list, and you keep a 'shadow copy'.

So it starts like this ...

myList = Eggs + Bacon + Milk

Then you pass your list to them ...

theirList = myList

Then you remember some more things and decide you don't need eggs ...

myList = myList + Bread + Butter - Eggs

And again pass it to them ...

theirList = myList

In terms of a PICAXE program 'myList' is a variable, 'theirList' is actually 'pinsc', so ...

b0 = %1000000 | %00100000
pinsc = b0

b0 = b0 | %00000001 &/ %00100000
pinsc = b0
 

kenmac

Member
Hi Hippy,
I've been away from this thread for a couple of days and have just read your reply.
I understand the method of using a "shadow" variable to update the pinsc state.
This will mean that all changes to pinsc must be routed via the "shadow", otherwise any update will overwrite anything that is set/reset by a direct write to a pin/s.
So we must take care not to address the pins individually if using the "shadow" method.

Re your example - I refer to the symbol "&/" (ANDNOT) - what is the difference between that and the logic NAND?
The manual says it's not the same.

kenmac
 

hippy

Technical Support
Staff member
Re your example - I refer to the symbol "&/" (ANDNOT) - what is the difference between that and the logic NAND?
The manual says it's not the same.
A Nand B == Not ( A And B )

A AndNot B == A And ( Not B )
 
Top