Reading porta on a 28X1?

Grogster

Senior Member
Can you read the whole porta on the 28X1, or must you read each pin seperately?

I can read the standard port with a command like if pins = %00000010 then goto one, but no amount of playing with the syntax allows me to read all of porta.

Perhaps you quite simply can't do that on porta with a 28X1?
 

lanternfish

Senior Member
Have you read Section2, pg 87 of the manual. This describes the IF PORTA pin ?? value {AND/OR variable ?? value ...} THEN address command. So for what you have indicated IF PORTA 1 = 1 THEN GOTO ONE should work.
 

Texy

Senior Member
....but he's asking to be able to read the whole of port a one go, not just a single pin.

Texy
 

Technical

Technical Support
Staff member
nearly,

if portA pin1 = 1 then goto one

There is no command to read all of porta , but you can do it with a peek

peek 05,b1
let b1 = b1 & %00001111 ' mask off A0-3
if b1 = .....
 
Last edited:

Grogster

Senior Member
Hi - I'm in Dunedin too.
:)

Yep, and what you say will work, but I was wanting to read the whole port at once, not just one input pin. This is because there can be more then one pin high at any one time, and depending on the state of ALL pins at any one moment, then do something else.
:)

Hopefully you can see what I mean...
 

Grogster

Senior Member
nearly,

if portA pin1 = 1 then goto one

There is no command to read all of porta , but you can do it with a peek

peek 05,b1
let b1 = b1 & %00001111 ' mask off A0-3
if b1 = .....
Cool thanks - will try that and let you know.
We just had a small earthquake here, so think I will call it quits for tonight...
 

lanternfish

Senior Member
OT - Dunedin earthquake

Cool thanks - will try that and let you know.
We just had a small earthquake here, so think I will call it quits for tonight...
I am at work at the Town Hall. It sure got my lighting trusses swinging, along with a few other things. Rang the wife at home and she didn't even notice it!

Cheers
 

westaust55

Moderator
If you read Manual 1 (Rev 6.8) page 85 it covers Port A use as simple digital inputs.

In particular the pargraph which states:
It is not possible to access the portA pins with any other ‘input’ type commands
(count, pulsin etc). Therefore these pins should be reserved as simple on/off
switches.
[.quote]

But, . . . Technical has given you a solution
 

stocky6409

Senior Member
There is no command to read all of porta , but you can do it with a peek

peek 05,b1
let b1 = b1 & %00001111 ' mask off A0-3
if b1 = .....
Cant seem to get this to do anything on my 28x1 (FW A.2)

i have a loop like this (just testing)

Code:
Loop:
peek 05,b1
let b1 = b1 & %00001111
debug
pause 2000
goto loop
b1 value in debug isn't changing no matter what digital data in on portA - ideas?

Stocky
 
Last edited:

hippy

Ex-Staff (retired)
Added : There does seem to be an issue with PEEK 05 which we will investigate.


The following test should work, but doesn't on 28X1 A.6 with Programming Editor 5.2.7 ...

#Picaxe 28X1
#Terminal 4800
Pause 2000
Do
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
SerTxd( #bit3, #bit2, #bit1, #bit0, 9 )
Peek 05, b0
SerTxd( #bit3, #bit2, #bit1, #bit0, CR, LF )
Pause 1000
Loop

Both columns of four binary digits should show the same. If seeing '0000 0000' in all cases of input that suggests the input signals are not correctly wired.
 
Last edited:

stocky6409

Senior Member
ok - will try that tomorrow when i get back to work and let you know.
The inputs are wired correctly - checked with logic probe right up to the picaxe pin!

Stocky
 

stocky6409

Senior Member
Thanks Eclectic!

Proves i wasnt going mad today - spent whole day doing a new design - hardware go-to-woah today and then got stumped on using PortA for inputs!!!

Hippy's method of "assembling" a value looks like it will work for me - tried a few ways off the top of my head but all i got was syntax errors - Hippy has shown me the way!

I need to test the 4 inputs as a single 4bit value - otherwise I am ONE input short if I cant use PortA - TA HIPPY!

Stocky
 
Top