Interfacing button with led to PIC16f877a

Status
Not open for further replies.
iam new to PIC micro controller
i was doing an interfacing of button and led to the micro controller
objective is simple on pressing the button led should glow.. on releasing the button led should off

following is the program in Mikro C compiler

void main() {

TRISC.F0=0; // for making pin 0 of PORTC as output, for led

TRISC.F1=1; // for making pin 1 of PORTC as input for button
while(1)
{
PORTC.F0=0;
while(PORTC.F1==0)
{
PORTC.F0=1;
}
}
}



the problem here is led glows independent on the button... its not working please correct me
the same logic does work for 8051... but not here... why?
 
You need to add a pullup resistor (10K) to pin C1. When the button isn't pressed the pin just floats.

Or you can turn on the pullup resistor in software, if available.
 
You need to add a pullup resistor (10K) to pin C1. When the button isn't pressed the pin just floats.

He also needs a current limiting resistor in series with the LED - while it might work it's VERY bad practice, and could kill both LED and PIC.

Or you can turn on the pullup resistor in software, if available.

It's not, it's only on PortB - but he could move to PortB.

If he'd like to visit my tutorials (in assembler though, but with C versions in these forums) then there's numerous hardware examples (of both pull-ups and series resistors).
 
That's what I found to it cost to much.
But a breadboard and real pic is much better and you know it works. In real life.
 
That's what I found to it cost to much.
But a breadboard and real pic is much better and you know it works. In real life.
But the real time debugger is worth its weight in gold!!!
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…