PDA

View Full Version : problems with 16F887: config or hardware



keithv
- 3rd April 2014, 02:58
7295

Here's the schematic. I'm using 5 switches to toggle 8 different LEDs on and off. The problem I'm having is that if I have 7 of the LEDs (any combination) on, the 8th LED resets everything. And if I have 5, 6, or 7 of the LEDs on, it will reset after a few seconds. Seems to work OK if I only have 4 or less LEDs on at one time. I'll post the code in just a second. It's on a different computer.

keithv
- 3rd April 2014, 03:23
I'm not sure what I'm doing wrong here. Any help would be greatly appreciated.



TRISB = %11111111
TRISC = %00000000
ANSEL = %00000000 ' Make AN0-AN7 digital
ANSELH= %00000000 ' Make AN8-AN13 digital
PORTB = 0
PORTC = 0



mainloop:

' Check any button pressed to turn on LED
If PORTB.0 = 0 Then ' loop1
do until PORTB.0 = 1
if PORTB.1 = 0 then loop2
pause 20
loop
toggle PORTC.0
pause 30
Endif

If PORTB.1 = 0 Then ' loop3
do until PORTB.1 = 1
if PORTB.0 = 0 then loop2
if PORTB.2 = 0 then loop4
pause 20
loop
toggle PORTC.2
pause 30
Endif

If PORTB.2 = 0 Then ' loop5
do until PORTB.2 = 1
if PORTB.1 = 0 then loop4
if PORTB.3 = 0 then loop6
pause 20
loop
toggle PORTC.4
pause 30
Endif

If PORTB.3 = 0 Then ' loop7
do until PORTB.3 = 1
if PORTB.2 = 0 then loop6
if PORTB.4 = 0 then loop8
pause 20
loop
toggle PORTC.6
pause 30
Endif

if PORTB.4 = 0 then ' bypass
do until PORTB.4 = 1
pause 20
loop
PORTC = 0
pause 30
endif

Goto mainloop ' Do it forever

End

loop2:
pause 30
do until (PORTB.0 = 1) and (PORTB.1 = 1)
pause 20
loop
toggle PORTC.1
pause 30
goto mainloop

loop4:
pause 30
do until (PORTB.1 = 1) and (PORTB.2 = 1)
pause 20
loop
toggle PORTC.3
pause 30
goto mainloop

loop6:
pause 30
do until (PORTB.2 = 1) and (PORTB.3 = 1)
pause 20
loop
toggle PORTC.5
pause 30
goto mainloop

loop8:
pause 30
do until (PORTB.3 = 1) and (PORTB.4 = 1)
pause 20
loop
TOGGLE PORTC.7
pause 30
goto mainloop

keithv
- 3rd April 2014, 19:58
nevermind. Figured it out. It was a hardware problem. I was using a dying battery. Switched over to DC adapter power supply and it works good.