Reading inputs on 28X2 port A and some of Port C?

gerrymcc

New Member
I used several smaller PICAXEs about five years ago for projects, but I have not done any more with them since then- until now. I am doing a project using a 28X2, because I need to use almost all the I/O pins. I am absolutely fine with the hardware aspects, but very rusty with the programming, having to almost start again and relearn it all. This is probably a very naive question, but I cannot find the answer.

I am trying to work out how to read 4 (of the possible 5) pins of Port A (used as inputs) and 6 of the possible 8 pins of Port C (used as inputs, with the remaining two used as outputs), as bytes. i.e. read Port A as one group, and then Port C as a second group. I can then manipulate the bits to do what I want to do.

How do I do this?

Thank you.
 

Buzby

Senior Member
b0 = pinsD will copy all 8 bits of port D into b0, where you can then read them as bit0, bit1, etc.

See Manual 2, page 23.
 

lbenson

Senior Member
For example:
Code:
#picaxe 28x2

dirsC=%00000011 ' outputs: pinC.0,1; inputs: pinC.2-7
dirsA=%00010000 ' output: pinA.4; inputs: pinA.0-3
dirsB=%11111111 ' outputs: pinB.0-7

do
  b0 = pinsC
  b1 = pinsA
  pinsB = pinsC
  pinB.0=bit8
  pinB.1=bit9
  pause 3000
loop
In simulation:
sim28x2pins.jpg
(Trying to attach this image twice caused my browser window in IE to lock up. Worked in Chrome.)
(Note that with the line, "pinsB = pinsC" the pins which are outputs in portC will result in 0 values for the corresponding portB pins.)

Better (for this example) would be
Code:
do
  b0 = pinsC
  b1 = pinsA
  bit0=bit8
  bit1=bit9
  pinsB = b0
  pause 3000
loop
Alternatively
Code:
do
  b0 = pinsC
  bit0=pinA.0
  bit1=pinA.1
  pinsB = b0
  bit8=pinA.2
  bit9=pinA.3
  pause 3000
loop
Any number of ways to do it
 
Last edited:

gerrymcc

New Member
Thank you both replyees above for taking the time to reply. Very much appreciated. Will work through both replies- to help refresh my poor old retiree's brain, and to relearn the PICAXE.
 
Top