pic16f887 clock project, need help


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2011
    Posts
    19

    Default pic16f887 clock project, need help

    I am trying to set the time of my clock with a key pad. I start a loop by pressing the * which sends it to my hours loop which starts checking for my key pad inputs. Like if num1=1 then hour=1 or if num1 & num0=1 then hour=10. The problem is when i get to minutes and you have to numbers like 21 and 12 i dont what i can do to distinguish between the two.Another problem is when you get double digits like 11 or 22.

    Also is there an better way to do this without doing TONS of if thens.

    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
    
    
    DEFINE num1_PAUSE 1000
    define num2_PAUSE 1000
    define num3_PAUSE 1000
    define num4_PAUSE 1000
    define num5_PAUSE 1000
    define num6_PAUSE 1000
    define num7_PAUSE 1000
    define num8_PAUSE 1000
    define num9_PAUSE 1000
    define numstar_PAUSE 1000
    define num0_PAUSE 1000
    
    
    '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=%00001111
    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
    pause 100
    if num1 = 0 & num0=1 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
     pause 100
     if num1=0 and num0=0 then
     hour=10
     for i=0 to 20
            pause 1     
        next i
        goto loopmins
     endif
    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 num1&num0=0 then
    mins=10
    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
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: pic16f887 clock project, need help

    minutes and you have to numbers like 21
    (2*10)+1
    minT VAR BYTE
    minO VAR BYTE
    minT = 2*10
    minO = 1
    minT + minO
    Dave
    Always wear safety glasses while programming.

Members who have read this thread : 1

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

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