pic 16f887 port holding problems


+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2011
    Posts
    19

    Default pic 16f887 port holding problems

    My portd is acting as if it is still being held down after i press a button and let go. it stays in that state until i turn off my curcit. Im having the problems in the hours mins and seconds loops.

    Code:
    @ ERRORLEVEL -306
    
    digit1 var portc.6'portd.0
    digit2 var portc.4'portd.1
    digit3 var portc.5'portd.2
    digit4 var portc.7'portd.3
    digit5 var portd.4          
    digit6 var portd.5
    check var byte
    cnt var word
    digit var byte
    pattern var byte
    i var word
    truby var byte
    first var byte
    second var byte 
    third var byte
    fourth var byte
    fifth var byte
    sixth var byte
    mills var word
    seconds var byte
    mins var byte
    hour var byte
    ampm var portb.7
    parker var byte
    num1 var portd.0'portc.6
    num2 var portb.5
    num3 var portb.4
    num4 var portb.3
    num5 var portb.2
    num6 var portb.1
    num7 var portb.0
    num8 var portd.1'portc.4 
    num9 var portd.2 'portc.5
    numstar var portb.6
    num0 var portd.3 'portc.7
    
    
    
    
    
    'CM2CON0=0
    'CM1CON0=0
    ANSELH=0
    seconds=45
    mins=59
    hour=1
    mills=1
    cnt=0
    ANSEL=0
    truby = 0
    
    INTCON=%10100000
    OPTION_REG=%00000000
    TMR0=6
    on interrupt goto isr
    INTCON=%10100000  
    
    trise=1
    trisa=0
    'trisd=0
    trisd=%11000000
    trisb=%01111111
    trise=1
    trisc=1
    ampm=1
    parker=0
    portb=1
    portc=1
    
    loopa:
    
    if portc.3=1 then
        mills=mills+1000
        while portc.3=1
        wend
        endif
    if mills>59 then
        mills=0
        seconds=seconds+30
        endif
    if seconds>59 then
        seconds=0
        mins=mins+1
        endif
    if mins>59 then
        mins=0
        hour=hour+1
        endif
    if hour>11 then
        hour=1
        parker=1 
      if parker=0 then
            ampm=0
      else
            ampm=1
        endif
        endif
        if numstar=0 then
        seconds = 0
        mins = 0
        hour = 0
        goto delay                
         endif
         goto loopa
    
         delay:
          for i=0 to 20
            pause 1     
        next i 
    goto loophour
    
    loophour:
    
    if num2 = 0 then 
        hour = 2
            for i=0 to 20
                pause 1     
            next i 
        goto loopmins
    endif
    if num1 = 0 then
        hour = 1
            for i=0 to 20
                pause 1     
         next i 
        goto loopmins
    endif
    if num3 = 0 then
        hour = 3 
    for i=0 to 20
            pause 1     
        next i 
     goto loopmins
    endif
    if num4 = 0 then
    hour = 4
    for i=0 to 20
            pause 1     
        next i 
     goto loopmins
    endif
    if num5 = 0 then
    hour = 5
    for i=0 to 20
            pause 1     
        next i 
     goto loopmins
    endif
    if num6 = 0 then
    hour = 6
    for i=0 to 20
            pause 1     
        next i 
     goto loopmins
    endif
    if num7 = 0 then
    hour = 7
    for i=0 to 20
            pause 1     
        next i 
     goto loopmins
    endif
    if num8 = 0 then
    hour = 8
    for i=0 to 20
            pause 1     
        next i 
     goto loopmins
    endif
    if num9 =0 then
    hour =9
    
    for i=0 to 20
            pause 1     
        next i
        goto loopmins
     endif
    'for i=0 to 20
            'pause 1     
       ' next i 
    ' goto loopmins
     if numstar=0 then
        for i=0 to 20
            pause 1     
        next i
        goto loopa
    else
    goto loophour
    endif
    
    loopmins:
    
    if num2 = 0 then 
    mins = 2
    for i=0 to 20
            pause 1     
        next i 
     goto loopsec
    endif
    if num1 =0 then
    mins=1
    for i=0 to 20
            pause 1     
        next i 
     goto loopsec
    endif
    if num3=0 then
    mins=3
    for i=0 to 20
            pause 1
        next i
        goto loopsec
        endif
    if num4=0 then
    mins=4
    for i=0 to 20
            pause 1
        next i
        goto loopsec
        endif
    if num5=0 then
    mins=5
    for i=0 to 20
            pause 1
        next i
        goto loopsec
        endif
    if num6=0 then
        mins=6
        for i=0 to 20
            pause 1
        next i
        goto loopsec
        endif
    if num7=0 then
    mins=7
    for i=0 to 20
            pause 1
        next i
        goto loopsec
        endif
    if num8=0 then
    mins=8
    for i=0 to 20
            pause 1
        next i
        goto loopsec
        endif
    if num9=0 then
    mins=9
    for i=0 to 20
            pause 1
        next i
        goto loopsec
        endif
        
        if numstar=0 then
        for i=0 to 20
            pause 1     
        next i
        goto loopa
    else
    goto loopmins
    endif
    
    loopsec:
    
    if num2 = 0 then 
    seconds = 2
    for i=0 to 20
            pause 1
        next i
    endif
    if num1 = 0 then
    seconds=1
    for i=0 to 20
            pause 1
        next i
    endif
    if num3=0 then
    seconds=3
    for i=0 to 20
            pause 1
        next i
    endif
    if num4=0 then
    seconds=4
    for i=0 to 20
            pause 1
        next i
    endif
    if num5=0 then
    seconds=5
    for i=0 to 20
            pause 1
        next i
    endif
    if num6=0 then
    seconds=6
    for i=0 to 20
            pause 1
        next i
    endif
    if num7=0 then
    seconds=7
    for i=0 to 20
            pause 1
        next i
    endif
    if num8=0 then
    seconds=8
    for i=0 to 20
            pause 1
        next i
    endif
    if num9=0 then
    seconds=9
    for i=0 to 20
            pause 1
        next i
    endif
    
    if numstar=0 then
        for i=0 to 20
            pause 1     
        next i
        goto loopa
    else
    goto loopsec
    endif
    
    
    
    
    disable
    isr:TMR0=6
    digit=hour dig 1
    lookup digit,[$3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$6F],pattern
    porta=pattern
    digit6=1
    pauseus 500
    digit6=0
    
    digit=hour dig 0
    lookup digit,[$3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$6F],pattern
    porta=pattern
    digit5=1
    pauseus 500
    digit5=0
    
    digit=mins dig 1
    lookup digit,[$3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$6F],pattern
    porta=pattern
    digit4=1
    pauseus 500
    digit4=0
    
    digit=mins dig 0
    lookup digit,[$3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$6F],pattern
    porta=pattern
    digit3=1
    pauseus 500
    digit3=0
    
    digit=seconds dig 1
    lookup digit,[$3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$6F],pattern
    porta=pattern 
    digit2=1
    pauseus 500
    digit2=0
    
    digit=seconds dig 0
    lookup digit,[$3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$6F],pattern
    porta=pattern
    digit1=1
    pauseus 500
    digit1=0
    cnt=cnt+1
    intcon.2=0
    resume 
    enable
    
    
    end

  2. #2
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107

    Default Re: pic 16f887 port holding problems

    I assume you have pull-ups on the input pin.
    Charles Linquist

  3. #3
    Join Date
    Feb 2011
    Posts
    19

    Default Re: pic 16f887 port holding problems

    yes, i have 10k pull ups on all of the pins

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405

    Default Re: pic 16f887 port holding problems

    Check all of your TRIS statements. It looks like you're using a lot of pins as inputs, but you have them setup as outputs.

    trisd=%11000000 ' this leaves D0 through D5 as outputs with only D6 and D7 as inputs.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5
    Join Date
    Feb 2011
    Posts
    19

    Default Re: pic 16f887 port holding problems

    thank you forgot to check the simple part

Tags for this Thread

Posting Permissions

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