Simple if input not working.

Status
Not open for further replies.

SwingeyP

Member
Pic 16F876A

Can anyone please tell me what im doing wrong here in pic basic.

Symbol leg1servo1 = PORTB.7 'J3 - Pin 28'

Symbol leg2servo1 = PORTB.4 'J6 - Pin 25'

Symbol leg3servo1 = PORTB.1 'J9 - Pin 22'

Symbol leg4servo1 = PORTA.4 'J12 - Pin 6'

Config RA0 = Input
Config RA1 = Input
Config RA2 = Input
Config RA3 = Input
Config RA4 = Output


Config PORTB = Output

Config PORTC = Output


start:
If RA0 = 1 Then
Goto stop
Endif

ServoOut leg1servo1, 10

ServoOut leg2servo1, 10

ServoOut leg3servo1, 10

ServoOut leg4servo1, 10
Goto start

stop:
End

I am trying this on the oshon simulator with a 4 button extra given to me by Eric - a forum user. I just can't get any of the inputs to trigger either in simulation or for real.

I must be doing something stupid. I have tried both states it sees logic 0 but never logic 1 why?

Regards - Paul
 
i dont use basic but can you do...
Code:
if RA0 == 1
if not why cant you do
Code:
if PORTA.0 = 1
or
Code:
if PORTA.0 == 1
EDIT:

ADD BEFORE IF...
Code:
ADCON1 = 0x06;
which will Configure all pins as digital inputs
 
Last edited:
Yep Atomsoft hit the nail on the head the port pins were in analogue mode which will always read '0'. In the oshonsoft basic one can just write ' ALL DIGITAL' and the analogue pins will be turned off.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…