Testing an output

Pic8581

New Member
Hi (still a beginner)


I'd let to set an output LED if a certain condition is true

Code:
symbol NoCreep = B.6
low NoCreep

if condition = true  then
   high NoCreep
  endif
so far so good

later in the program I'd like to see if this has been set

but

Code:
if NoCreep =1 then
;blahblah
endif
give me a syntacs error

I realize that b.6 is an output pin, but do I really have to set a second variable to test?

Thanks
 

oracacle

Senior Member
Can you post a full programme (and picaxe for that matter), but from what I can surmise you are asking of an output is low and the picaxe does not know the state of its own outputs. there may well be a way of find the state of an output port and then finding what pins are high from that, but its not something I have ever needed.

the syntax error just see the fact that you are trying to read on output and not an input
 

westaust55

Moderator
instead of:
symbol NoCreep = B.6
try:
symbol NoCreep = OutpinB.6

or by way of example this works:
Code:
#PICAXE 20M2
symbol NoCreep = B.6
Symbol Test_No_Creep = OutpinsB
DO
low NoCreep

if b0 = 1  then
   high NoCreep
   b0 = 0
  endif
  
  b1 = Test_No_Creep AND 64 ; test for bit 6 = B.6  (2^6 = 64)
  if b1 =1 then
high b.7
endif
pause 1000
b0 = 1
LOOP
 
Last edited:

Pic8581

New Member
oracacle, you did understand the problem. I some part of the program I want to test if an output pin
was set to high in some other subroutine. (Its a 20M2 BTW).
I was hoping the there is some internal register that represents the output pins.

Westaust55, you are doing something something like that, OutpinsB is loaded into a variable which then is then tested for a bitvalue. (Not sure how you got to b0 though).

But now you got to this idea:

Code:
let b0 = pinsB

if bit6=0 then
..
else
..
endif
But that is still using an extra variable. So I might as well use another variable in the program to "remember" if the condition was set earlier.
Thanks
 

AllyCat

Senior Member
Hi,

Yes, there should be a "Special Function Register" which stores the output state, regardless of the actual pin state. I believe it's the LATx register, but there's a complication with the 14/20M2 that the output pins are "remapped" from the PIC base chip (which has three partial ports A, B and C). Pin B.6 is still on Port B, but it's bit 5, not 6. Many of the other pins are not even mapped onto the same port letter, six pins use "Port A", although two of these are the serial Programming In and Out.

So it looks (not checked) that you might be able to use a "PEEKSFR $4D , b0" for "LATB" and then test bit5. But this can only be done on a "real" chip, not the simulator. For the other pins you'll need to delve into the (500 page) PIC16(L)F1825/1829 Data Sheet, not really recommended for a PICaxe beginner.

Usually, it will be better and easier just to keep an "image" of the required port pins. For example, reserve b0 for PortB and b1 for PortC (if required). Always when you set B.6 High, also issue a "bit6 = 1" (and 0 for a Low), then you can check the state with "IF bit6 = 1 ....." whenever required. If there are no more than 8 pins to "remember" then a single byte (of b0 - b3) can be mapped to the relevant output pins with Symbol statements.

Cheers, Alan.
 

westaust55

Moderator
Westaust55, you are doing something something like that, OutpinsB is loaded into a variable which then is then tested for a bitvalue. (Not sure how you got to b0 though).
:
:
But that is still using an extra variable. So I might as well use another variable in the program to "remember" if the condition was set earlier.
Thanks
Without an extra variable for the test, an inline test with:

if Test_No_Creep =64 then ; test for B.6 high (2^6 = 64)

will not work if another pin on portB is high such as when my code sets B.7 high prior to looping.
The IF...THEN command cannot have a math calculation such as
Test_No_Creep AND 64 = 64
as part of the test
 
Last edited:
Top