Connect with us

12f675 delay issue

Discussion in 'Microcontrollers, Programming and IoT' started by nepow, Sep 21, 2018.

  1. nepow

    nepow

    99
    1
    Jul 18, 2011
    Having a problem with a delay_ two led's switch states after a short delay period when a button is pressed to start the sequence. When the sequence ends the program returns to begin ready fr next press. A switch selects the timing period either long 15 min or short 5 min. My problem is the first delay period times OK the second period just hangs.
    I only use PIC assembly as can be seen in my example.
    Any help appreciated please. Regards Dupe

    Code:
    ;processor 12F675   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        org 0
    
    
    ; This shorthand assigns COUNT1=0x20, COUNT2=0x21, etc.
     cblock 0x20
          
    DCounter1
    DCounter2
    DCounter3
    DCounter4
     endc
    
    
    ; _INTRC_OSC_NOCLKOUT: we want to use the internal oscillator to drive the PIC,
    ; so that we don't need to connect a crystal, see "Section 2. Oscillator".
    
        #include <p12f675.inc>
        __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF
    
        errorlevel -302
    
        bcf STATUS, RP0
        clrf GPIO      ; Set byte at address GPIO in Bank 0 to 0, so that digital pin outputs will be
                                                                ; a known value (0, low)
        movlw 07H      ;movlw b'111'      ; This turns the comparator off, pins GP{0,1,2} act as digital I/O pins.
        movwf CMCON
        bsf STATUS, RP0   ; Select Bank 1.
        movlw 3454h       ;=============  read last program memory  location at 3ffh and enter hear
        movwf OSCCAL
        clrf ANSEL
        movlw 3ch  ;first two bits are outputs . third & fourth bits are input
        movwf TRISIO 
     
       bcf STATUS, RP0 ; Back to Bank 0 so that we have access to GPIO.
    
     
    
       goto begin
    
    ; ================================== 100 millisecond delay for debounce ======
    delaysw
    MOVLW 0Xdc
    MOVWF DCounter1
    MOVLW 0X82
    MOVWF DCounter2
    LOOPc
    DECFSZ DCounter1, 1
    GOTO LOOPc
    DECFSZ DCounter2, 1
    GOTO LOOPc
    RETURN
    
    ; ================================= delay 5 mins ============
    
    delay5
    MOVLW 0X67
    MOVWF DCounter1
    MOVLW 0Xe7
    MOVWF DCounter2
    MOVLW 0Xf2
    MOVWF DCounter3
    MOVLW 0X06
    MOVWF DCounter4
    LOOP
    DECFSZ DCounter1, 1
    GOTO LOOP
    DECFSZ DCounter2, 1
    GOTO LOOP
    DECFSZ DCounter3, 1
    GOTO LOOP
    DECFSZ DCounter4, 1
    GOTO LOOP
    NOP
    NOP
    RETURN
    
    
    ; ==================================== delay 15 mins =========
    delay15
    MOVLW 0X3f
    MOVWF DCounter1
    MOVLW 0Xb4
    MOVWF DCounter2
    MOVLW 0Xd6
    MOVWF DCounter3
    MOVLW 0X12
    MOVWF DCounter4
    LOOPb
    DECFSZ DCounter1, 1
    GOTO LOOPb
    DECFSZ DCounter2, 1
    GOTO LOOPb
    DECFSZ DCounter3, 1
    GOTO LOOPb
    DECFSZ DCounter4, 1
    GOTO LOOPb
    RETURN
    
    ; ======================== selecting run period ===============
    begin
     
     
        btfsc GPIO,5
        goto begin
        call delaysw                 ;call delay.5    ; wait before start
     
    
        btfsc GPIO,3
        goto sh
        goto lng     
    sh                 ; 5 minute swtching period
        bsf GPIO,0     ; green led on                               
        bcf GPIO,1                                   
        call delay5
        nop
        bcf GPIO,0
        bsf GPIO,1
        call delay5     
        nop
        goto begin
     lng
        
        bcf GPIO,0                                   
        bsf GPIO,1                                   
       call delay15
        nop
        nop
        bsf GPIO,0
        bcf GPIO,1
        call delay15     
        nop
        goto begin
    
    ;------------------------------------------------------------------------------
     END
     
    Last edited by a moderator: Sep 21, 2018
  2. Harald Kapp

    Harald Kapp Moderator Moderator

    8,687
    1,691
    Nov 17, 2011
    Please use the "insert code" option for lenghty bits of code. It makes the posts so much better readable.
    I modified your post accordingly.
     
  3. nepow

    nepow

    99
    1
    Jul 18, 2011
    Thank you Harald,
     
  4. nepow

    nepow

    99
    1
    Jul 18, 2011
    Assistance no longer required regarding this thread. problem sorted. Nepow
     
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.