-
Input?
I'm new to PIC programming and i have a question
I want to know how to get an input on an 16f688
i want to switch on a led if some port is high and turn it of again when it's low, but i can't get it done :(
this is the code i use but it doesn't work yet
<code>Led Var PORTC.1
Sensor var PORTC.2
high Led
pause 5000
low led
input Sensor
loop: if sensor = 1 then
high led
else
low led
endif
pause 500
goto loop
end</code>
I previously programmed BASIC stamps so i have some programing experience.
Thanks in advance:
Chris
-
You're 99% of the way there... here's an amendment that should get you all the way...
Led Var PORTC.1
Sensor var PORTC.2
TRISC=%00000100
high Led
pause 5000
low led
loop:
if sensor = 1 then
high led
else
low led
endif
goto loop
end
-
On the PIC16F688 RC1 & RC2 (and others - see datasheet) are A/D inputs by
default on power-up. Add this to the first section of your code;
ANSEL = 0
That will allow use of these pins as digital.