Basic problem with interrupts and sleep command


Closed Thread
Results 1 to 7 of 7

Hybrid View

  1. #1
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: Basic problem with interrupts and sleep command

    I thought the Interrupt on change bits were only available on port B?
    Dave Purola,
    N8NTA
    EN82fn

  2. #2
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    966


    Did you find this post helpful? Yes | No

    Default Re: Basic problem with interrupts and sleep command

    Hi David

    The pin interrupt bits are only on Port B. I showed you the pseudo code as a guideline of how to do it. Of course you need to look into the datasheets and read a lot to make it work. I am guessing that you are new to PBP judging by the few posts you've made. You may also look at this thread
    http://www.picbasic.co.uk/forum/showthread.php?t=11100

    Still more questions, feel free to ask here. Someone will surely chime in.

    Regards

    ps: forgot. While posting your code, enclose them within [ code] and [ /code] tags. Makes it easier to read and keeps your formatting.
    Last edited by Jerson; - 20th February 2012 at 14:11.

  3. #3
    Join Date
    Dec 2009
    Posts
    21


    Did you find this post helpful? Yes | No

    Default Re: Basic problem with interrupts and sleep command

    Hi,
    Not exactly new but sporadic (and ancient) Have dumped code using RA2 and after more study produced the following using rb4. Amost works! i can now sequence through the patterns if I allow them to complete but if I press the button whilst the pattern is in progress I can only toggle between patterns 1 and 2 and am unable to get it to shut down ! Sorry about the code layout I seem to be using the tags incorrectly will try again here goes;
    code:
    '************************************************* **************************
    ' Lighthouse led flashing routines in which pressing button on rb4 is intended
    ' to sequence thru Pattern1 -- Pattern2 --off or if no button is pressed
    ' shutdown will occur when pattern is completed'
    ' When (if ?) program finally works the simple flashing will be replaced
    ' by appropriate lighthouse patterns.
    ' ************************************************** *************************
    @ DEVICE pic16f628a,intrc_osc_noclkout,mclr_on,wdt_off
    x var byte
    TRISB = %11110000
    TRISA = %00000000
    CMCON = 7
    OPTION_REG.7=0 ' 0 = Enable PORTB Pull Ups
    @ Device wdt_off ' Disable the WatchDog Timer
    INTCON.3=1 ' Interrupt Control Register
    PORTB = 0
    PORTA = 0
    flag var byte

    flag = 0
    porta.0 = 1
    porta.1 = 1
    porta.2 = 1

    main:
    INTCON.0=0 '
    @ SLEEP ' Start program with pic asleep
    INTCON.0=0 ' rb4 pulled low to wake

    pattern1:
    for x = 1 to 100
    if flag = 1 and portb.4 = 0 then pattern2 ' Interrupts loop to jump to
    PORTA.0 = 0 ' pattern 2 flag prevents
    pause 200 ' premature jump when rb4
    porta.0 = 1 ' first pulled low
    pause 200
    flag = 1
    next x
    INTCON.0=0 ' puts pic to sleep at natural
    @ SLEEP ' end of pattern1
    INTCON.0=0
    goto main

    pattern2:
    flag = 0
    for x = 1 to 100
    if flag = 1 and portb.4 = 0 then shutdown ' Interrupts loop to jump to
    flag = 0 ' shutdown
    PORTA.1 = 0
    pause 200
    porta.1 = 1
    pause 200
    flag = 1
    next x
    INTCON.0=0 'puts pic to sleep at natural
    @ SLEEP 'end of pattern2
    INTCON.0=0
    goto main

    shutdown: 'puts pic to sleep and returns to program start
    INTCON.0=0
    @ sleep
    INTCON.0=0
    goto main
    end
    /code

  4. #4
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    966


    Did you find this post helpful? Yes | No

    Default Re: Basic problem with interrupts and sleep command

    Hello David

    You've done quite a bit. I have re-arranged the code a bit. I think this will work. I am awed by your enthusiasm. Changes that I made are highlighted by capitals.

    Code:
    '************************************************* **************************
    ' Lighthouse led flashing routines in which pressing button on rb4 is intended
    ' to sequence thru Pattern1 -- Pattern2 --off or if no button is pressed
    ' shutdown will occur when pattern is completed'
    ' When (if ?) program finally works the simple flashing will be replaced
    ' by appropriate lighthouse patterns.
    ' ************************************************** *************************
    @ DEVICE pic16f628a,intrc_osc_noclkout,mclr_on,wdt_off
    
    x         var byte
    pattern   var byte
    
    
      TRISB = 110000
      TRISA = 000000
      CMCON = 7
      OPTION_REG.7=0    ' 0 = Enable PORTB Pull Ups
      @ Device wdt_off  ' Disable the WatchDog Timer
      INTCON.3=1        ' Interrupt Control Register (RBIE)
      PORTB = 0
      PORTA = 0
    
      porta.0 = 1
      porta.1 = 1
      porta.2 = 1
    
      PORTB.4 = 1       ' THIS NEEDS TO BE SET HIGH SINCE YOU ARE LATER
                        ' USING A LOW TO SENSE A BUTTON PRESS
      PATTERN = 1
    
    main:
      INTCON.0=0 ' clear any pending (RBIF)
      @ SLEEP ' Start program with pic asleep
      INTCON.0=0 ' clear any pending (RBIF) rb4 pulled low to wake
    
      ' BIFURCATE THE OPERATION DEPENDING ON PATTERN SELECTED
      IF PATTERN = 1 THEN GOTO PATTERN1
      IF PATTERN = 2 THEN GOTO PATTERN2
    goto main
    
    pattern1:
      for x = 1 to 100
        PORTA.0 = 0     ' pattern 2 flag prevents
        pause 200       ' premature jump when rb4
    
        ' PUTTING THE EVALUATION HERE, SPEEDS UP THE BUTTON SENSING
        IF PORTB.4 = 0 THEN 
          PATTERN = 2 ' INTERRUPTS LOOP TO JUMP TO
          GOTO   PATTERN2
        ENDIF
    
        porta.0 = 1     ' first pulled low
        pause 200
        
        ' PUTTING THE EVALUATION HERE, PREVENTS A PREMATURE JUMP
        IF PORTB.4 = 0 THEN 
          PATTERN = 2 ' INTERRUPTS LOOP TO JUMP TO
          GOTO   PATTERN2
        ENDIF
      next x
    goto main           'puts the pic to sleep
    
    pattern2:
      for x = 1 to 100
        PORTA.1 = 0
        pause 200
    
        IF PORTB.4 = 0 THEN 
          PATTERN = 1 ' INTERRUPTS LOOP TO JUMP TO
          GOTO   PATTERN1
        ENDIF
    
        porta.1 = 1
        pause 200
    
        IF PORTB.4 = 0 THEN 
          PATTERN = 1 ' INTERRUPTS LOOP TO JUMP TO
          GOTO   PATTERN1
        ENDIF
    
      next x
    goto main           'puts the pic to sleep
    
    shutdown: 'puts pic to sleep and returns to program start
    goto main
    end

Members who have read this thread : 0

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

Posting Permissions

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