+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    224

    Default 16f627a Loop issues

    Help Please..... Thank you for reading

    I have a loop (Mainloop) that is looking at some RTC (DS1302) values and switching an LED depending on time of day.
    All is good as is.

    What I am attempting to do now is put a simple active low Press button in the circuit so I hit the button the LED is on for an amount of time. I have enabled my pullups OPTION_REG.7=0 and am using PORTB.3 as the input, button is switching 0v onto this pin when pressed.

    Main loop looks like this... suspect code in red :-

    Code:
    mainloop:   GOSUB gettime        ' Read the time from the RTC
    
                IF (RTCHour=$17) AND (RTCMin=$15) THEN  
                GOSUB Message ' flash 
                ENDIF
                
                IF (RTCHour=$18) AND (RTCMin=$15) THEN  
                GOSUB Message ' flash 
                ENDIF
                
                IF (RTCHour=$19) AND (RTCMin=$15) THEN  
                GOSUB Message ' flash 
                ENDIF
                
                IF (RTCHour=$20) AND (RTCMin=$15) THEN 
                GOSUB Led_On ' Led on
                ENDIF
                
                IF (RTCHour=$21) AND (RTCMin=$45) THEN 
                GOSUB Led_Off ' Led off
                ENDIF
                
                IF PORTB.3=0 THEN
                high led
                pause 1000
                Low led
                ENDIF
    
                GOTO mainloop        ' Do it forever and ever and ever
            
    Led_On:     HIGH Led
                RETURN 
                
    Led_Off:    LOW Led
                RETURN
    What my issue is is the LED is on all the time in 1second bursts regardless of Button in or out..... I have tried with real hard pullups 10k but same outcome.

    I would expect the LED to come on for a second with a button press..... Well that is what I want (Just a lamp test function)


    Thank you again for reading ...... and hopefully pointing out the obvious

    BR
    Andy

  2. #2
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,157

    Default Re: 16f627a Loop issues

    In the config, make sure "LVP_OFF".

    and

    TRISB.3 = 1 comes first
    OPTION_REG.7=0 comes second
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  3. #3
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    224

    Default Re: 16f627a Loop issues

    Quote Originally Posted by sayzer View Post
    In the config, make sure "LVP_OFF".

    and

    TRISB.3 = 1 comes first
    OPTION_REG.7=0 comes second
    I understand TRISB.3 and OPTION_REG.7=0

    Why LVP_OFF, I think it is off anyway ?

    Still not working :-(

    BR
    Andy

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    1,496

    Default Re: 16f627a Loop issues

    the problem is in the code not posted

    this works as expected on a 16f648a (basically the same as a 627a)



    Code:
    #CONFIG
    cfg = _INTOSC_OSC_NOCLKOUT
    cfg&= _WDT_ON
    cfg&= _PWRTE_OFF
    cfg&= _MCLRE_ON
    cfg&= _BODEN_ON
    cfg&= _LVP_OFF
    cfg&= DATA_CP_OFF
    cfg&= _CP_OFF
      __CONFIG cfg
    #ENDCONFIG
    
     led var porta.1
     OPTION_REG.7=0
     
     
    
    mainloop:  
                
                IF PORTB.3=0 THEN
                high led
                pause 1000
                Low led
                ENDIF
     GOTO mainloop        ' Do it forever and ever and ever
    This is more entertaining than Free to Air TV

  5. #5
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    224

    Default Re: 16f627a Loop issues

    Out of desperation I checked TRISB=%00000100

    Should be :- TRISB=%00001000 for RB3 Input :-)

    Not near the project at moment but might be the issue ????

    Possible lesson learnt. :-)

    BR
    Andy

Similar Threads

  1. Issues with a feedback loop.
    By jmgelba in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 11th June 2012, 18:54
  2. Newbie need Help 16F627a
    By azmax100 in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 21st January 2009, 08:38
  3. Comparator help (16F627A)
    By JohnnyV in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 24th May 2008, 04:09
  4. 16F627A portA4 problem?
    By markedwards in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 22nd October 2005, 19:54
  5. Programmer For 16f627a
    By TONIGALEA in forum General
    Replies: 1
    Last Post: - 13th January 2005, 13:55

Members who have read this thread : 19

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