Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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;
}
}
}

upload_2015-3-12_18-24-3.png


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).
 
How is it every student in the world has Proteus? I thought it was expensive.
I think there is a very cheap version on the black market!!! It cost me and arm and a leg!!! even the yearly subscriptions are expensive...
 
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.

Latest threads

New Articles From Microcontroller Tips

Back
Top