Cant get pin C.4 on an 18M2 to act as an input

Grant666

Member
Hi All

I have been trying to use input pin C.4 ( pin3 on the chip ) as an discrete input.

The test code is just to switch the output states of pins B0 to B7 to see what happens.

However , on the simulator and the real world device, Its like the 18M2 Crashes until the input goes low again? So Im not sure what Im doing wrong?

Any ideas would be welcome, thanks

this is the test code Im using
start:
input c.4
let dirsB=%11111111
goto main

main:
let outpinsB = %11111111
if pinc.4=1 then four
goto main


four:
let outpinsB=%10101010
if pinc.4=1 then four
if pinc.4=0 then main
 

AllyCat

Senior Member
Hi,

Do you really need to use that pin as an input? Before you do, make sure that you fully understand the hard reset procedure or you'll be back saying that you've "killed" the PICaxe. :(

Of course sometimes every pin does need to be used (particularly with an 08M2), but usually there are better ways. ;)

Cheers, Alan.
 

hippy

Technical Support
Staff member
Pin C.4 being Serial In is probably the cause of your main problem; in the simulator and real world the PICAXE will reset and the program will restart if a DISCONNECT command is not included.

There is another potential trap waiting to bite, with DISCONNECT added, or even if you choose to use a different pin ...

Code:
four:
let outpinsB=%10101010
if pinc.4=1 then four
if pinc.4=0 then main
When pinC.4 becomes 0 it drops trough the first 'if pinc.4=1' test as required. But there is a small chance that it could immediately become 1 through 'button bounce' so drops through the second 'if pinc.4=0' test, falls of the end of the program and stops execution.

It might seem unlikely that would happen between two consecutive commands but Sod's Law will have it that the most unlikely thing will happen when you don't want it to.

It would be better to just do the first 'if pinc.4=1' and, if pinC.4 isn't 1, you know it must have been 0, and you can simply 'goto main' ...

Code:
four:
let outpinsB=%10101010
if pinc.4=1 then four
goto main
 
Top