Menu

PIC16F887 PORTB issues

Help
2013-12-10
2013-12-11
  • Clint Koehn

    Clint Koehn - 2013-12-10

    Could some tell me why this doesn't work. RB6 And RB7 do not work when set individually.

    #chip 16F887, 20
    
    Dir PORTB Out
    Do
      PORTB=255         ;<---- This works to turn them all on
      wait 1 s
      PORTB=0           ;<---- This turns all of them off
    
      for gn_i=1 to 8
          SetRelay 1, gn_i     ;This will not turn on 7 & 8
          wait 250 ms
          SetRelay 0,gn_i
          Wait 250 Ms
      next
      Wait 750 ms
    Loop
    
    sub SetRelay(In rStatus as byte, In RelayNum as byte)
    
        select case RelayNum
            case 1
                 if rStatus=0 then
                    Set PortB.0 Off
                 else
                    Set PortB.0 On
                 end if
            case 2
                 if rStatus=0 then
                    Set PortB.1 Off
                 else
                    Set PortB.1 On
                 end if
            case 3
                 if rStatus=0 then
                    Set PortB.2 Off
                 else
                    Set PortB.2 On
                 end if
            case 4
                 if rStatus=0 then
                    Set PortB.3 Off
                 else
                    Set PortB.3 On
                 end if
            case 5
                 if rStatus=0 then
                    Set PortB.4 Off
                 else
                    Set PortB.4 On
                 end if
            case 6
                 if rStatus=0 then
                    Set PortB.5 Off
                 else
                    Set PortB.5 On
                 end if
            case 7                   ;<----- from here on down, doesn't work
                 if rStatus=0 then
                    Set PortB.6 Off
                 else
                    Set PortB.6 On
                 end if
            case 8
                 if rStatus=0 then
                    Set PortB.7 Off
                 else
                    Set PortB.7 On
                 end if
    
        end select
    end sub
    
     
  • mmotte

    mmotte - 2013-12-11

    The code work as it should, made every led (all 8) lite together and individually, on my 44 pin demo board but i had to change PORTB to PORTD because that is where the 8 leds are at.
    check your hdwe.

    73
    M

     
  • Clint Koehn

    Clint Koehn - 2013-12-11

    Thanks for taking time to look at it. If I can get them to all light together (and I can), they should light individually (which RB6 & RB7 don't). I think it has something to do with those 2 pins being the ICSP pins, but I don't know that for sure. I am expecting a couple more chips tomorrow, but I don't think it is the chip. I have a PIC 16F1519 and it acts the same way. It almost appears to be a compiler issue.

     
  • Chuck Hellebuyck

    Check your configuration settings for bit 13 of the CONFIG1 register.
    If you have it set to 0 then RB6 and RB7 are dedicated to Debug mode.

    bit 13 DEBUG: In-Circuit Debugger Mode bit
    1 = In-Circuit Debugger disabled, RB6/ICSPCLK and RB7/ICSPDAT are general purpose I/O pins
    0 = In-Circuit Debugger enabled, RB6/ICSPCLK and RB7/ICSPDAT are dedicated to the debugger

     
  • Clint Koehn

    Clint Koehn - 2013-12-11

    How do you do that in GCBASIC? It doesn't work to do CONFIG1.13. It generates an error that says CONFIG1 is a byte.

    EDIT: I checked with PICKIT2 download and bit 13 is set to 1. It looks like mmotte is right. I think I do have a hardware issue. Will report back when I get it fixed.

     

    Last edit: Clint Koehn 2013-12-11
  • Chuck Hellebuyck

    Refer to the Configuration section of the help file for more detail.
    GCB sets the configuration automatically with defaults (which must turn debug on). You can override the settings.

    Place this in the top section of your program to turn it off:

     #config debug_off
    

    The list of config options in GCB can be found in the chipdata folder of GCB.
    Find the PIC16F887.dat file and open it in notepad, then scroll to the bottom and you'll see the list of configuration settings to choose from.
    You should also refer to the Special Features section of the data sheet to get more information on the configuration registers.

    I cover this briefly in my Great Cow Basic CHIPINO user manual at greatcowbasic.com or at this direct link:
    http://www.greatcowbasic.com/uploads/9/2/9/8/9298268/gcb_chipino_user_manual_v1.0_-_sample.pdf

    But I need to add more detail since I just cover about the same detail as the help file.

    When you compile and assemble it you will see these lines in the assembly file.

    ;Set up the assembler options (Chip type, clock source, other bits and pieces)
     LIST p=16F887, r=DEC
    #include <P16F887.inc>
     __CONFIG _CONFIG1, _INTOSCIO & _WDT_OFF & _MCLRE_OFF & _LVP_OFF & _DEBUG_OFF
    
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.