problem with Interrupt and MCLR 18F4550


+ Reply to Thread
Results 1 to 10 of 10

Thread: problem with Interrupt and MCLR 18F455028 days old

  1. #1
    Junior Member dawaherjesus,'s Avatar
    Join Date
    May 2020
    Posts
    4
    Thumbs Up
    Received: 0
    Given: 2
    Total Downloaded
    84.06 MB

    0 Not allowed!

    Default problem with Interrupt and MCLR 18F4550

    a cordial greeting from Venezuela.
    I am experimenting with interruptions and I have the following problem.
    the code works perfectly, but when pressing MCRL, the interrupt is activated and the PIC 18F4550 is not reset.
    I have only tested the operation in proteus.

    Code:
    Device 18F4550
    Xtal 20
    Config_Start
        FOSC=HS,MCLRE=On,PBADEN=OFF,ICPRT=On
        FCMEN=Off,IESO=Off,PWRT=On,WDT=OFF,LVP=OFF 
    Config_End
    INTCON = 010000              ; Activar interrupción por RB0
    On_Hardware_Interrupt GoTo Inter_Lebel 
    
    
    Inter_Lebel:
        Context Save
        Cls
        Print At 2,1,"INTERRUPCION"
        INTCONbits_INT0IF = 0
        GoTo main
        Context Restore

  2. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  3. #2
    Member keytapper's Avatar
    Join Date
    Jun 2019
    Posts
    244
    Thumbs Up
    Received: 11
    Given: 6
    Total Downloaded
    463.40 MB

    1 Not allowed!

    Default Re: problem with Interrupt and MCLR 18F4550

    It is preferable that you use the plugin to configure your fuses. Probably some still missing.

  4. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  5. #3
    Prolific Poster charliecoultas's Avatar
    Join Date
    Sep 2010
    Posts
    1,474
    Thumbs Up
    Received: 51
    Given: 48
    Total Downloaded
    3.45 GB

    0 Not allowed!

    Default Re: problem with Interrupt and MCLR 18F4550

    You have a label "main" but it is not in the source.

    Charlie

  6. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  7. #4
    Prolific Poster John Drew's Avatar
    Join Date
    Feb 2002
    Posts
    2,966
    Thumbs Up
    Received: 96
    Given: 34
    Total Downloaded
    5.15 GB

    1 Not allowed!

    Default Re: problem with Interrupt and MCLR 18F4550

    Hello,
    It is not a good idea to use CLS, or a print statement in an interrupt routine.
    Also you should not use a goto outside the routine. By doing this you bypass the context restore. All sorts of bad things can happen.
    Generally, an interrupt routine should do just enough to alter a variable or so or a simple and short task.

    Keep in mind that the context restore takes the program back to where it was before the interrupt.
    Best wishes John

  8. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  9. #5
    Prolific Poster See_Mos's Avatar
    Join Date
    Feb 2004
    Posts
    1,332
    Thumbs Up
    Received: 20
    Given: 0
    Total Downloaded
    1.01 GB

    0 Not allowed!

    Default Re: problem with Interrupt and MCLR 18F4550

    It is really tempting to write code to show you how to do this but first have a look at the samples folder and try to work out how it can be done.
    My RAM is failing

  10. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  11. #6
    Junior Member dawaherjesus,'s Avatar
    Join Date
    May 2020
    Posts
    4
    Thumbs Up
    Received: 0
    Given: 2
    Total Downloaded
    84.06 MB

    0 Not allowed!

    Default Re: problem with Interrupt and MCLR 18F4550

    See_Mos, I always check in the examples folder, and I have already seen how to use insterruptions. I'm just trying to adapt the interrupt to that I need.


    I want to do is the following:


    I have a main program that will stop when an external event occurs, when the interruption occurs, some data will be sent by RS232, then the main program will resume where it left off.

  12. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  13. #7
    Prolific Poster John Drew's Avatar
    Join Date
    Feb 2002
    Posts
    2,966
    Thumbs Up
    Received: 96
    Given: 34
    Total Downloaded
    5.15 GB

    0 Not allowed!

    Default Re: problem with Interrupt and MCLR 18F4550

    Hello,
    Try removing the line "goto main" from the interrupt routine. That is the main cause of your problem.
    Cheers
    John

  14. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  15. #8
    Senior Member Stephen Moss's Avatar
    Join Date
    Jan 2006
    Posts
    558
    Thumbs Up
    Received: 34
    Given: 7
    Total Downloaded
    3.87 GB

    0 Not allowed!

    Default Re: problem with Interrupt and MCLR 18F4550

    I hope that does not represent to sum of your test code, if not then including the full code is often helpful as sometimes the problem is not where you expect it to be.
    That aside it looks to me like you have set bit 4 of the Intcon register (Timer) not bit 3 (PortB) try...
    Intcon = %00001000 or Intcon = $08 or Intcon.3 = 1.

    Additionally unless it is performed in some missing code you have not enabled the Global Interrupt bit (Intcon.7, INTCON = $88 for both GIE & PortB) so are you certain your issues are caused but an acutal the interrupt rather than your code jumping to the interrupt handler when it should not, i.e. no Goto main instruction listed before the interrupt handler to jump over it and stop it being executed immediately.
    Inside you interrupt handler check INTCON bit 0 to see if the interrupt was triggered by port B, if it was it certainly was not triggered by RB0 which it appear you want as portB interrupts are only availabe on RB-RB7, not RB0 -- try reading the datasheet!

    Finally a John stated do not use Goto Main within your interrupt handler, always use Return to exit a subroutine and after a context restore, what is the point in saving it if you do not restore it before exiting.

  16. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  17. #9
    Prolific Poster See_Mos's Avatar
    Join Date
    Feb 2004
    Posts
    1,332
    Thumbs Up
    Received: 20
    Given: 0
    Total Downloaded
    1.01 GB

    0 Not allowed!

    Default Re: problem with Interrupt and MCLR 18F4550

    OK, here is one way. Tested in Proteus.

    Code:
    ' Test interrupt on RB0, default is rising
    ' LCD default is PortB
    ' RB2 = EN
    ' RB3 = RS
    ' RB4...7 = Data 
    
    Device 18F4550
    Xtal 20
    Config_Start
        FOSC=HS,MCLRE=On,PBADEN=OFF,ICPRT=On
        FCMEN=Off,IESO=Off,PWRT=On,WDT=OFF,LVP=OFF 
    Config_End
    
    Dim Interrupt_Flag As Bit
    Dim True As 1
    Dim False As 0
    
    On_Hardware_Interrupt GoTo Inter_Lebel 
        GoTo Main
    
    Inter_Lebel:                        ' THE INTERRUPT HANDLER
        Context Save
        If INTCONbits_INT0IF = True Then Interrupt_Flag = True ' INTERRUPT SO SET INDICATOR
    '    INTEDG0 = 0                    ' SET TO 0 FOR INTERRUPT ON FALLING EDGE
    '    INTEDG0 = 1                    ' DEFAULT IS INTERRUPT ON RISING EDGE
    
        INTCONbits_INT0IF = False       ' CLEAR INTERRUPT READY FOR NEXT ONE
        Context Restore
        
    Main:
        DelayMS 200                         ' ALLOW TIME FOR LCD TO START UP
        Cls                                 ' INITIALISE LCD
        INTCON = $90                        ' SAME AS BINARY 10010000
                                            ; Activar interrupción por RB0 AND ENABLE INTERRUPTS    
        Print At 1,1,"Ready"                ' SHOW IT IS WORKING
        While 1 = 1                         ' SET UP AN ENDLESS LOOP
            If Interrupt_Flag = True Then    ' CHECK IF INTERRUPT HAS HAPPENED
                Print At 2,1,"INTERRUPCION"  ' YES SO SHOW MESSAGE
                DelayMS 1000                 ' WAIT FOR 1 SECOND
                Interrupt_Flag = False       ' CLEAR INDICATOR READY FOR NEXT INTERRUPT
                Print At 2,1,"            "  ' CLEAR MESSAGE
            EndIf
        Wend                                 ' DO IT FOREVER
    
    ' INTCON2 REGISTER BITS    
    Symbol RBIP = INTCON2.0     ' RB Port Change Interrupt Priority bit
    Symbol TMR0IP = INTCON2.2   ' TMR0 Overflow Interrupt Priority bit
    Symbol INTEDG2 = INTCON2.4  ' External Interrupt2 Edge Select bit
    Symbol INTEDG1 = INTCON2.5  ' External Interrupt1 Edge Select bit
    Symbol INTEDG0 = INTCON2.6  ' External Interrupt0 Edge Select bit
    Symbol NOT_RBPU = INTCON2.7 ' PORTB Pull-up Enable bit
    My RAM is failing

  18. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  19. #10
    Member keytapper's Avatar
    Join Date
    Jun 2019
    Posts
    244
    Thumbs Up
    Received: 11
    Given: 6
    Total Downloaded
    463.40 MB

    0 Not allowed!

    Default Re: problem with Interrupt and MCLR 18F4550

    Well, for certain situation one might keep watching the Interrupt flag without to engage another flag for it and a double IF/THEN. But then if any interrupt occurs with the flag not yet clear then it may stumble every times on it.

    So for same extent one may use in the main loop
    Code:
    '==============================================================================
    '                               Main loop
    '==============================================================================
    Do                                  ' new version of proton allows this
      If INTCONbits_INT0IF = 1 Then     ' polling the interrupt
        INTCONbits_INT0IF = 0           ' as soon as it happe
        Cls                             ' do the action
        Print At 2,1,"INTERRUPCION"     ' e buena noche
      End If
    Loop
    '==============================================================================
    '                            End   Main loop
    '==============================================================================

  20. Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. 18F25k22 MCLR OFF problem
    By xldaedalus in forum Proton Plus Compiler v3
    Replies: 11
    Last Post: 7th January 2015, 17:49
  2. [SOLVED !] 18F4550 TMR0 interrupt
    By wirecut in forum Proton Plus Compiler v3
    Replies: 15
    Last Post: 28th January 2010, 13:39
  3. [SOLVED !] usb problem using 18f4550
    By dodonet in forum Labcenter Proteus VSM
    Replies: 3
    Last Post: 20th July 2009, 14:00
  4. [SOLVED !] again problem with MCLR and I/O on 18F1320
    By luciano in forum Proton Plus Compiler v3
    Replies: 2
    Last Post: 25th September 2006, 07:44
  5. [SOLVED !] 18F4550 - Text LCD problem
    By joantabb in forum Proton Plus Compiler v3
    Replies: 27
    Last Post: 6th December 2005, 18:19

Posting Permissions

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