problems with 16F887: config or hardware


Closed Thread
Results 1 to 3 of 3
  1. #1

    Default problems with 16F887: config or hardware

    Name:  16f887LEDs.bmp
Views: 156
Size:  78.7 KB

    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.

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: problems with 16F887: config or hardware

    I'm not sure what I'm doing wrong here. Any help would be greatly appreciated.

    Code:
    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

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: problems with 16F887: config or hardware

    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.

Similar Threads

  1. pic 16f887 port holding problems
    By lockjawz in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 12th April 2011, 14:01
  2. 16f887 portc input problems
    By lockjawz in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 31st March 2011, 14:02
  3. PIC12F683 Config Problems
    By Electroman87 in forum General
    Replies: 1
    Last Post: - 22nd April 2009, 08:18
  4. 16F887 20Mhz External Clock Problems
    By modifyit in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 3rd September 2008, 13:11
  5. PIC18 Config Problems
    By eoasap in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 3rd January 2006, 01:08

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts