RB0 interrupt and toggle issue


Closed Thread
Results 1 to 36 of 36

Hybrid View

  1. #1

    Question RB0 interrupt and toggle issue

    Hello,
    I am running a hardware interrupt on RB0 (rising edge trigger). I use RB0 to interrupt the micro which is (I assume) sitting at a DEBUGIN waiting for serial data.

    The inline assembly code (as listed in the datasheets 16F877A) to take care of house keeping going in and coming out of the interrupt is present. During an interrupt I jump to a "call routine" which jumps out and runs some code in Picbasic, then returns. The problem I have is in this routine called from within the interrupt is supposed to toggle port bits (1 through 8, bitwise) written in Picbasic. The problem is it does not toggle. It seems to only go HIGH but will not go LOW.

    Anyone run into this issue where toggle does not work? I will post the code tomorrow for reference...I have been trying to figure this out for over 1.5 days now.

    Thanks!
    Nick

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Macgman2000 View Post
    Hello,
    I am running a hardware interrupt on RB0 (rising edge trigger). I use RB0 to interrupt the micro which is (I assume) sitting at a DEBUGIN waiting for serial data.

    The inline assembly code (as listed in the datasheets 16F877A) to take care of house keeping going in and coming out of the interrupt is present. During an interrupt I jump to a "call routine" which jumps out and runs some code in Picbasic, then returns. The problem I have is in this routine called from within the interrupt is supposed to toggle port bits (1 through 8, bitwise) written in Picbasic. The problem is it does not toggle. It seems to only go HIGH but will not go LOW.

    Anyone run into this issue where toggle does not work? I will post the code tomorrow for reference...I have been trying to figure this out for over 1.5 days now.

    Thanks!
    Nick
    Hi Nick, yeah I have had toggle not work and never figured out why. BTW Call as I understand it is for use in ASM and gosub for PBP. When you post your code we can all chew on it a while, see what we can learn. I bet the BIG GUNS here CAN answer this problem.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3


    Did you find this post helpful? Yes | No

    Question code

    OK...here it is. The stuff in the mainloop is waiting for serial data to update the port bits which each control the activation of a relay (8 relays). The interrupt port RB0 is tied to 8 button inputs, the idea is to push any of the 8 buttons and interrupt out of the DEBUGIN to decode key presses. It goes through the interrupt, loads payload in the interrupt (it works). Where it is not working is in the CALL outside of the interrupt. It does NOT toggle the port bits. I saw something strange that I could not replicate, when it did toggle it undid the logic of any bits that were set high. Anyway...here it is, I would appreciate the help!

    Nick


    INCLUDE "Modedefs.Bas"
    @ device HS_OSC, LVP_OFF, WDT_OFF
    ; @ Device pic16F877A, HS_OSC, BOD_OFF, PWRT_ON, WDT_ON, PROTECT_OFF

    DEFINE OSC 20



    DEFINE DEBUGIN_REG PORTC ' Set portC as software RX in
    DEFINE DEBUG_BAUD 2400 ' Set bit rate
    DEFINE DEBUGIN_BIT 7 ' Set portC bit 7
    DEFINE DEBUGIN_MODE 1 ' Set Debugin mode: 0 = true, 1 = inverted

    DEFINE INTHAND myint ' Setup interrupt handler button presses




    ; initialize Interrupts
    OPTION_REG.6 = 1 ; option_reg RB0 interrupt rising=1, falling=0 edge
    INTCON = %10010000 ; Enable INTE RB0 interrupt $90


    ;set ports to input
    TRISD = %11111111 ; 8 button press inputs + RB0 interrupt for all off


    ;set ports to output
    TRISA = %00000000 ; set port A to outputs for relays
    TRISE = %00000000 ; set port E to outputs for relays

    ;set port initializations
    PORTA = %00000000
    PORTE = %00000000

    ' Configure internal registers

    wsave VAR BYTE $70 system ' Saves W
    ssave VAR BYTE bank0 system ' Saves STATUS
    psave VAR BYTE bank0 system ' Saves PCLATH
    fsave VAR BYTE bank0 system ' Saves FSR

    payload VAR byte bank0 system ' data location for selecting relays
    payload1 var byte bank0 system ' previous good data
    chksum var byte bank0 system ' check sum calculated at the TX side and sent over RF link


    payload = 0



    goto mainloop


    asm

    ; Save W, STATUS and PCLATH registers, if not done previously
    myint
    ; bsf INTCON, 1
    movwf wsave ; these commands are necessary to preserve registers to prevent
    swapf STATUS, W ; corruption
    clrf STATUS
    movwf ssave
    movf PCLATH, W
    movwf psave


    movf portd, w ; 8 momentary button press value
    movwf payload ; move portd value into payload to handoff to update_keys2
    call _keys2

    ; Restore saved registers
    bsf porte,0
    movf psave, W ; reload system register to previous values before interrupt was called
    movwf PCLATH
    swapf ssave, W
    movwf STATUS
    swapf wsave, F
    swapf wsave, W
    retfie ; Return from interrupt

    endasm




    keys2: ; called by interrupt to update relay
    if payload = 0 then
    portE = 0
    portA = 0
    endif
    if payload = 1 then
    toggle portA.0
    endif
    if payload = 2 then
    toggle portA.1
    endif
    if payload = 4 then
    toggle portA.2
    endif
    if payload = 8 then
    toggle portA.3
    endif
    if payload = 16 then
    toggle portA.4
    endif
    if payload = 32 then
    toggle portA.5
    endif
    if payload = 64 then
    toggle portE.0
    endif
    if payload = 128 then
    toggle portE.1
    endif

    return


    mainloop:
    INTCON = %10010000 ; Enable INTE RB0 interrupt $90
    ; receive data packets and check sum, throwing out sync byte (255)
    debugin [wait (255),payload,chksum]
    if chksum != payload then ; verify good packets by comparing check sums
    goto mainloop ; check sum does not match transmitted data
    endif

    update_keys:

    if payload = 0 then
    portE = 0
    portA = 0
    endif
    if payload = 1 then
    toggle portA.0
    endif
    if payload = 2 then
    toggle portA.1
    endif
    if payload = 4 then
    toggle portA.2
    endif
    if payload = 8 then
    toggle portA.3
    endif
    if payload = 16 then
    toggle portA.4
    endif
    if payload = 32 then
    toggle portA.5
    endif
    if payload = 64 then
    toggle portE.0
    endif
    if payload = 128 then
    toggle portE.1
    endif

    goto mainloop

  4. #4
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Hi Macgman2000,
    I didn't analyze your code too closely, because frankly I am not smart enough to understand all the assembly code, and it compiled with too many errors here for me to sort out, so I did the next best thing, I tossed out the assembly interrupts and installed Darrel's DT_INTS, and recompiled. Please try it as you have the breadboard already set up. MPASM Required.
    Code:
    'http://www.picbasic.co.uk/forum/showthread.php?p=73542#post73542
    'Macgman2000.bas
    '********************************************************************
    
    
    
    
    
    
    
    INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
    
    INCLUDE "Modedefs.Bas"
    ;@ device HS_OSC, LVP_OFF, WDT_OFF
    ; @ Device pic16F877A, HS_OSC, BOD_OFF, PWRT_ON, WDT_ON, PROTECT_OFF
    @ __config _HS_OSC & _BODEN_OFF & _PWRTE_ON & _WDT_ON
    DEFINE OSC 20
    
    
    
    DEFINE DEBUGIN_REG PORTC ' Set portC as software RX in
    DEFINE DEBUG_BAUD 2400 ' Set bit rate
    DEFINE DEBUGIN_BIT 7 ' Set portC bit 7
    DEFINE DEBUGIN_MODE 1 ' Set Debugin mode: 0 = true, 1 = inverted
    
    ;DEFINE INTHAND myint ' Setup interrupt handler button presses
    
    ASM
    INT_LIST macro ; IntSource, Label, Type, ResetFlag?
        INT_Handler RBC_INT, _keys2, PBP, yes
      endm
      INT_CREATE ; Creates the interrupt processor
    ENDASM
    
    
    ; initialize Interrupts
    OPTION_REG.6 = 1 ; option_reg RB0 interrupt rising=1, falling=0 edge
    INTCON = %10010000 ; Enable INTE RB0 interrupt $90
    
    
    ;set ports to input
    TRISD = %11111111 ; 8 button press inputs + RB0 interrupt for all off
    
    
    ;set ports to output
    TRISA = %00000000 ; set port A to outputs for relays
    TRISE = %00000000 ; set port E to outputs for relays
    
    ;set port initializations
    PORTA = %00000000
    PORTE = %00000000
    
    ' Configure internal registers
    
    
    
    payload VAR byte bank0 system ' data location for selecting relays
    payload1 var byte bank0 system ' previous good data
    chksum var byte bank0 system ' check sum calculated at the TX side and sent over RF link
    
    
    payload = 0
    
    
    
    goto mainloop
    
    
    
    
    
    keys2: ; called by interrupt to update relay
    if payload = 0 then
    portE = 0
    portA = 0
    endif
    if payload = 1 then
    toggle portA.0
    endif
    if payload = 2 then
    toggle portA.1
    endif
    if payload = 4 then
    toggle portA.2
    endif
    if payload = 8 then
    toggle portA.3
    endif
    if payload = 16 then
    toggle portA.4
    endif
    if payload = 32 then
    toggle portA.5
    endif
    if payload = 64 then
    toggle portE.0
    endif
    if payload = 128 then
    toggle portE.1
    endif
    
    @ INT_RETURN
    
    
    
    mainloop:
    INTCON = %10010000 ; Enable INTE RB0 interrupt $90
    ; receive data packets and check sum, throwing out sync byte (255)
    debugin [wait (255),payload,chksum]
    if chksum != payload then ; verify good packets by comparing check sums
    goto mainloop ; check sum does not match transmitted data
    endif
    
    update_keys:
    
    if payload = 0 then
    portE = 0
    portA = 0
    endif
    if payload = 1 then
    toggle portA.0
    endif
    if payload = 2 then
    toggle portA.1
    endif
    if payload = 4 then
    toggle portA.2
    endif
    if payload = 8 then
    toggle portA.3
    endif
    if payload = 16 then
    toggle portA.4
    endif
    if payload = 32 then
    toggle portA.5
    endif
    if payload = 64 then
    toggle portE.0
    endif
    if payload = 128 then
    toggle portE.1
    endif
    
    goto mainloop
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  5. #5


    Did you find this post helpful? Yes | No

    Question

    Hello Joe,

    Is it possible to send me the include files?

    INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts

    Also, Why is MPASM needed if the files are .bas ? I haven't used this interrupt module before. I need a tad bit hand holding through this. I appreciate your help!!!!!!

    Nick

  6. #6
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    http://darreltaylor.com/DT_INTS-14/intro.html
    http://darreltaylor.com/DT_INTS-14/downloads.htm
    http://darreltaylor.com/DT_INTS-18/home.html

    Darrel's include files Require MPASM to work. Darrel Requires you not to copy paste the code into your code, rather use them as include files as I did. They exist in versions for the 14 bit core and for the 18F series. He has generously made these available to us, and I am grateful to him. THANKS DARREL !

    Quote Originally Posted by Macgman2000 View Post
    Also, Why is MPASM needed if the files are .bas ?
    Nick
    If you need help switching assemblers let me know, it's pretty easy.

    EDIT:
    Nick I think I set your code up with the wrong interrupt, I set it up as RBC_INT and that would be for on change interrupt whereas you want interrupt on portB.0 which should be INT_INT in the assy statement for INT_Handler .
    Last edited by Archangel; - 29th April 2009 at 23:41. Reason: ReEnterPBP-14.bas is in the .zip file
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

Similar Threads

  1. Instant Interrupts - Revisited
    By Darrel Taylor in forum Code Examples
    Replies: 772
    Last Post: - 17th February 2016, 22:14
  2. TMR0 interrupt and HSERIN
    By boban in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd September 2008, 11:48
  3. I have problem with interrupt RB0
    By chai98a in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 5th July 2008, 09:55
  4. tmr2 interrupt problem
    By ADCON in forum mel PIC BASIC Pro
    Replies: 27
    Last Post: - 2nd January 2008, 18:49
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

Members who have read this thread : 2

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