PDA

View Full Version : Newbie problem :)



sokrad
- 24th January 2008, 19:44
Hi, I have some problems with my code for controlling some leds on my portB.

I use MicroCode Studio/PBP 2.5a/16f877a


TrisA=1
TrisB=0

If portA.0 = 1 then
PortB = %11111111
pause 2000
else
PortB = %00000000
Endif



When I press my key on portA.0 I wont to turn on all leds on portB, they should stay 2sec after I release it, and then turn off. But it wont work, is there some missing code here?

Please help , I am Newbie :)

skimask
- 24th January 2008, 19:54
PortA.0 on the 16F877A (as well as many others) is an analog input by default and as such, will not work with 'digital commands'.
You must change it to a digital input.
This is also true of many PICs with built-in ADC's.

paul borgmeier
- 24th January 2008, 20:09
>>You must change it to a digital input. (from SkiMask)

He is correct - to do this add


ADCON1 = 6

before your TRIS commands and all should be well (see datasheet PORTA section for explanation)

sokrad
- 25th January 2008, 10:34
Thank you, it work's. :)