I am stumped!!!


Closed Thread
Results 1 to 20 of 20

Thread: I am stumped!!!

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default

    I'm just stumped with the original code above why am I already in the interrupt when I power up, just to confirm that I changed the INT handler to:
    '---[INT - interrupt handler]---------------------------------------------------
    ToggleLED1:
    TOGGLE LED
    pause 50
    @ INT_RETURN

    and sure enough the led is flashing...

    By the way, what program are you using to upload your schematic?

  2. #2


    Did you find this post helpful? Yes | No

    Default

    Hmmm, came back here today to focus on the post here from Bruce but it seems to have vanished, or am I losing my mind? Maybe its both

    Anyhow, it was mentioned that so to speak that I should take a snapshot of PortB, I am so lost. If on power up PortB.0 is high and pullups are enabled, on the rest of the pins: TRISB = %11111110 PortB = %00000001 then with my meter focusing on pins 4-7 shows 5VDC or logic HIGH, should I do this:

    WHILE (portb >> 4) != 15
    pause 20
    wend
    INTCON.0 = 0
    return

    or substitute 15 for a 0?

    Seems it would be 15 but with that I apparently staying in my interrupt routine.

    I've been experimenting with ON INTERRUPT and Darryl Taylor's Instant Interrupts:

    DEFINE OSC 4
    CMCON=%00000111
    VRCON = 0
    PAUSEus 10
    TRISA = %00000110
    TRISB = %11111110
    PORTA = %00000000
    PORTB = %00000001
    OPTION_REG.7 = 0
    OPTION_REG.6 = 0
    INTCON = %00001000

    led var portA.3
    INCLUDE "DT_INTS-14.bas" ; Base Interrupt System
    INCLUDE "ReEnterPBP.bas" ; Include if using PBP interrupts
    ASM
    INT_LIST macro ; IntSource, Label, Type, ResetFlag?
    INT_Handler RBC_INT, _check, PBP, yes
    endm
    INT_CREATE

    ENDASM
    @ INT_ENABLE RBC_INT
    PAUSE 50

    cycle:
    gosub readportb
    HIGH led
    pause 100
    LOW led
    pause 100
    @ Sleep
    @ Nop
    @ Nop
    goto cycle

    readportb:
    WHILE (portb >> 4) != 15
    PAUSE 20
    WEND
    INTCON.0 = 0
    return


    check:
    PAUSE 250
    WHILE (portb >> 4) != 15
    PAUSE 20
    WEND
    @ INT_RETURN


    Any Suggestion, preferably in Crayola so its clear?

    Thanks

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


    Did you find this post helpful? Yes | No

    Default

    Try this;
    Code:
    DEFINE OSC 4
    CMCON=%00000111
    VRCON = 0 
    PAUSEus 10 
    TRISA = %00000110
    TRISB = %11110000   ' using upper 4-bits for interrupt
    PORTA = %00000000 
    PORTB = %00000001
    OPTION_REG.7 = 0 
    OPTION_REG.6 = 0
     
    led var portA.3
     
    INCLUDE "DT_INTS-14.bas" ; Base Interrupt System
    INCLUDE "ReEnterPBP.bas" ; Include if using PBP interrupts
     
    ASM
    INT_LIST macro ; IntSource, Label, Type, ResetFlag?
        INT_Handler RBC_INT, _check, PBP, yes
        endm
        INT_CREATE 
    ENDASM
     
    @ INT_ENABLE RBC_INT 
     
    cycle:
        HIGH led
        pause 100
        LOW led
        pause 100
        @ Sleep
        goto cycle
     
    check: 
        WHILE (portb >> 4) != 15
          PAUSE 10
        WEND 
        @ INT_RETURN
    The purpose of WHILE (portb >> 4) != 15 is to wait until a button that generated the interrupt is released. It also reads the port, which is required before DT_INTs can clear the interrupt flag.

    To clear the interrupt-on-change flag bit you first have to read the port, then clear the flag. If you read the port while a button is still pressed, then clear the flag, another interrupt will be generated once the button is released.
    Attached Images Attached Images  
    Last edited by Bruce; - 28th July 2010 at 20:58. Reason: Forgot Crayola...;o)
    Regards,

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

  4. #4


    Did you find this post helpful? Yes | No

    Default

    Thanks a million Bruce, I will try that now.

    P.S. I about fell on the floor laughing when I refreshed the page and say the crayon

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


    Did you find this post helpful? Yes | No

    Default

    It took me a while to find one the color of my truck..;o)

    Experiment with this one too. You can have it wake from sleep without an interrupt handler.
    Code:
    DEFINE OSC 4
    CMCON=%00000111
    VRCON = 0 
    PAUSEus 10 
    TRISA = %00000110
    TRISB = %11110000   ' using upper 4-bits for interrupt
    PORTA = %00000000 
    PORTB = %00000001
    OPTION_REG.7 = 0 
    OPTION_REG.6 = 0
    led var portA.3
     
        INTCON = %00001000  ' int-on-change enabled. RBIE=1, RBIF=0
     
    cycle:
        HIGH led
        pause 100
        LOW led
        pause 100
        @ Sleep                 ' sleep until button press
        WHILE (portB >> 4) !=15 ' wait for button release
          PAUSE 10              ' and read port so RBIF can
        WEND                    ' be cleared below.
        INTCON.0=0              ' now clear RBIF int flag
        goto cycle
     
        END
    Global interrupts are disabled. Just enabled the int-on-change by setting RBIE, clearing RBIF, and it sleeps until a button is pressed.

    DT_INTs is more fun, but you can wake one up without an interrupt handler.
    Regards,

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

  6. #6


    Did you find this post helpful? Yes | No

    Default

    I compiled the code as shown, when powered up the led continues to blink but when I press a button on the keypad which would cause (PORTB >> 4) != 15 it still blinks.....


    I have even tried it with the following changes with same response:
    cycle:
    gosub checkstate
    HIGH led
    pause 100
    LOW led
    pause 100
    @ Sleep
    goto cycle

    checkstate:
    while (PORTB >> 4) != 15
    pause 20
    wend
    return

    its almost like it never see an interrupt to get out of cycle. I also confirmed on PortB by checking with my meter on switch closure. With a switch closed and the bit I checked was PortB.4 I measured it at 2.192Vrms, switch open 4.99Vrms.

    Thanks for hanging around

  7. #7


    Did you find this post helpful? Yes | No

    Default

    Bruce, just wanted to mention we must have posted about the same time the code that I just tried was the crayon version, I am about to try your latest.

    Again, Thank you.

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


    Did you find this post helpful? Yes | No

    Default

    Make sure you have the watchdog timer disabled when using the assembler @ SLEEP command.
    Regards,

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

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