Outpins Again

retepsnikrep

Senior Member
http://www.picaxeforum.co.uk/showthread.php?t=7546&highlight=outpins

Looking at the above thread i though I had this right, however when I simulate the code below it never detects the state of the pin even though you can see Outpins changing in the variable panel. :confused:

Code:
	symbol WatchDogLed       = 3	;Watchdog flashing Green Led on Output 3 (Flashes every other program loop)
	
Start:

	toggle WatchDogLed		;Keeps watchdog happy, flashes every other time through loop

	pause 1000

	if outpin3 = 1 then
	stop
	endif

	goto Start
What am I doing wrong? Thanks Peter
 

Technical

Technical Support
Staff member
You cannot use outpin like this on any part.
You need to use readoutputs to know the state of an output pin.


readoutputs b0 ; (b0 is bit7:bit0)
if bit3 = 1 then
 
Last edited:

retepsnikrep

Senior Member
I'm using it on a 28X1, so should it work?

I'm using the latest editor set to 28X1 mode the chip firmware is A3 if I remember correctly.
 
Last edited:

retepsnikrep

Senior Member
It didnt work downloaded to the chip in my program, so I went back to the simple simulation above and that dosent appear to work either :confused:

That code should work in the 28X1 simulation should it not?
 

Technical

Technical Support
Staff member
outpinsX are only for 'writing' to output pins. They do not read individual pins, sorry if we mislead you earlier.

This is because on Microchip PICs you cannot read the status of an output by reading the 'input state' of a pin that is set up as an output - the technology of the i/o driver in the chip means you will not always get a valid reading doing this (although often you do!). You can only 'read' a pin reliably when it is set as an input.

So you have to read the 'shadow register', which stores the output pin values. This is achieved via the 'readoutputs' command. This command actually reads the shadow register of what the pins have previously been set to, not the actual pins themselves.

On all parts you can do this as

readoutputs b0 ; (b0 is bit7:bit0)
if bit3 = 1 then
 

retepsnikrep

Senior Member
Thanks I appreciate that. Can I suggest correct that old thread as well as that clearly indicates it would work as I thought, which it doesn't causing much confusion.
 
Top