How Do I Read Port A on a 40X

vk3jme

New Member
G'day All,

I'm finally programming a 40x that I purchased about 2 years ago.
When I first started playing with picaxe, I bought one at each end of the spectrum as I really didn't know what I was playing with, (2 08Ms, 1 18X and a 40X)

I'm a little lost on how I am meant to use port A on the 40X.

My 40X reports as the following:
Firmware Version 7.8
(PICAXE-28X(40X) Firmware Version 8)

My Program Editor is v5.20.0

Maybe it is the manual has been updated a little since the 40X was the choice, but I can't find much on how to use this port.
Maybe it's just me.

if porta 0=1
if pinsA=$0f
let b1 = pinsA

All of these return a syntax or symbol error.

READADC 0,b1
This appears to check out OK.

I would like to read port A (a0 to a4) as a byte to a register if possible, but I would be happy to check it with a series of if-then if I have to.

Please help.

Jamie
 

hippy

Technical Support
Staff member
I believe you only have the option of "If PortA pinX = Y Then". To read all A0 to A4, the best 'official' option would likely be ...

b0 = 0
If PortA pin0 = 1 Then : bit0 = 1 : End If
If PortA pin1 = 1 Then : bit1 = 1 : End If
If PortA pin2 = 1 Then : bit2 = 1 : End If
If PortA pin3 = 1 Then : bit3 = 1 : End If
If PortA pin4 = 1 Then : bit4 = 1 : End If

Variable 'b0' will then contain a value 0 to 31. You have a problem there if any of the pins change whilst in the process of reading them. It would be recommended to read the pins until you get two readings which match.

You might be able to use the following, but I haven't tested it ...

Peek $05,b0

You may have to use ...

Peek $05,b0 : b0 = b0 & $1F
 

westaust55

Moderator
I would like to read port A (a0 to a4) as a byte to a register if possible
In general terms of pin out functionality the 40X is really no different to the 40X1 in terms of use (other than some pins on the 40X1 having extra possible functions).

As an 8-bit port, Port A is pre defined in the PICAXE firmware as 4 analogue inputs, the two serial I/O pins and the external oscillator pins.

Based on the above, you will only ever be able to use 4 of the 8 Port A signal lines and cannot therefore enter an 8-bit byte of data in parallel.
 
Top