switch on a led depending on the switch state (using picbasic and pic16f877)

Status
Not open for further replies.

pouchito

New Member
Hi all,

i wrote a very simple code but it did not work

i want to turn on a led if the switch is on

this is the code:

TRISA = $ff
TRISB = 0
CMCON=7

main: if PORTA.1=1 THEN
PORTB.1=1
delay_ms (1000)
ELSE PORTB.1=0
END IF
GOTO MAIN

end.

and it did not work, i put the input on portb.b instead of the porta.1, it worked but i need to use the port A as input .

i think my problem is that i did not specify that i need the portA to be digital and not analog? is that right ?
if yes, how ?
please help
 
Last edited:
think it's ANSEL=0 to make it digital
also, your if statement should always return true, or perhaps not in the language you're using, I'm used to C where we'd do if x==1 to test to see if x is 1, whereas x=1 will place 1 in x and always return true on success
 
no, you'll still need to turn off the analog functions on porta, and make sure the TRISA bit for your pin is set to 1 (input)

picbasic should have a directive ALL_DIGITAL = TRUE which turns off any and all analog features, depending on the chip.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…