PDA

View Full Version : Help with button and 16F877a



gtrplaya101
- 13th October 2009, 05:28
Hi all! As you can see I am a new member here and even greener in the world of MCUs. So far I have been able to successfully accomplish small feets in programming such as interfacing a serial LCD, blinking an LED, etc. However I am having trouble getting a button to work. What I am trying to do is get a button input on PortA.2 to turn on an LED connected to PortA.1. I can turn the LED on and off I just cant get the button input to work. Not sure if I have the pin configured incorrectly but any help would be greatly appreciated!!!

Darrel Taylor
- 13th October 2009, 05:49
Since you're using PORTA (Analog pins) as digital ...
I might suggest ...

ALLDIGITAL.pbp
http://www.picbasic.co.uk/forum/showthread.php?t=11100
<br>

gtrplaya101
- 13th October 2009, 21:26
Thanks for the link.
Is there not just a short command that I can place into the code that will change all of PortA pins to digital input? I have been able to get the button to work on PortB so I am sure my code is right, is just doesnt work on PortA.
Sorry for the newb questions!

Would this work?

CMCON = 7
ADCON1 = 7

Darrel Taylor
- 13th October 2009, 22:02
Thanks for the link.
Is there not just a short command that I can place into the code that will change all of PortA pins to digital input?
That's what AllDigital does ...
INCLUDE "ALLDIGITAL.pbp"

Would this work?

CMCON = 7
ADCON1 = 7
Yes, that will work on a 16F877A.
And is exactly what AllDigital would do.

But when you go to use a different chip, those registers will probably not work anymore and you'll have to search the datasheets to see which ones are needed for that chip.

AllDigital will still work no matter which chip you are using.
<br>

gtrplaya101
- 13th October 2009, 22:16
thanks that did the trick!