• AVR Freaks

Hot!Where can I find informatio on xc8 assembly interrupt handling?

Author
CollieJim
New Member
  • Total Posts : 16
  • Reward points : 0
  • Joined: 2010/12/29 05:27:19
  • Location: 0
  • Status: offline
2020/06/21 00:34:20 (permalink)
0

Where can I find informatio on xc8 assembly interrupt handling?

Hi,
I have a small MPASM program for a PIC16F1827 that uses interrupts, and find that I need to migrate to xc8 assembly to update it.
Coding the ISR and locating it are not the problem. 
Setting the interrupt vector is.  How do I do that in xc8 assembly?
Thanks
 
post edited by CollieJim - 2020/06/21 00:46:52
#1

19 Replies Related Threads

    ric
    Super Member
    • Total Posts : 28006
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Where can I find informatio on xc8 assembly interrupt handling? 2020/06/21 01:27:12 (permalink)
    +1 (1)
    What do you mean "setting the interrupt vector" ?
    Is it just placing the code at location 0x004 ?
     
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    upand_at_them
    Super Member
    • Total Posts : 585
    • Reward points : 0
    • Joined: 2005/05/16 07:02:38
    • Location: Pennsylvania
    • Status: online
    Re: Where can I find informatio on xc8 assembly interrupt handling? 2020/06/21 03:54:57 (permalink)
    +1 (1)
    Isn't it right in the XC8 manual?
    #3
    ric
    Super Member
    • Total Posts : 28006
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Where can I find informatio on xc8 assembly interrupt handling? 2020/06/21 04:09:30 (permalink)
    +1 (1)
    upand_at_them
    Isn't it right in the XC8 manual?

    I think you're referring to the C User Guide.
    The XC8 Assembler manual (MPLAB_XC8_PIC_Assembler_User_Guide.pdf) has nothing to say about interrupt services, presumably because you have to write it all yourself.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #4
    CollieJim
    New Member
    • Total Posts : 16
    • Reward points : 0
    • Joined: 2010/12/29 05:27:19
    • Location: 0
    • Status: offline
    Re: Where can I find informatio on xc8 assembly interrupt handling? 2020/06/21 08:46:52 (permalink)
    0
    That is what I thought, but I read that xc8 makes things relocatable and that confused me.  If the only code psect will start at 0x0000 I can use existing code unchaged.
    Thanks
    #5
    dan1138
    Super Member
    • Total Posts : 3730
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: Where can I find informatio on xc8 assembly interrupt handling? 2020/06/21 11:13:15 (permalink)
    +1 (1)
    CollieJim
    If the only code psect will start at 0x0000 I can use existing code unchnaged.

    Not in my experience.

    The pic-as(v2.20) assembler is different enough from MPASM that a thorough review and forensic port of your code is required to get it to build correctly with the XC8 assembler.
     
    MPLABX v5.40 debug for a project using the pic-as(v2.20) assembler is nonexistent.
     
    I have completed a few ports, success was hard won. See this git repository for one.
    post edited by dan1138 - 2020/06/21 15:09:39
    #6
    1and0
    Access is Denied
    • Total Posts : 10999
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Where can I find informatio on xc8 assembly interrupt handling? 2020/06/21 12:52:10 (permalink)
    +3 (3)
    CollieJim
    I have a small MPASM program for a PIC16F1827 that uses interrupts, and find that I need to migrate to xc8 assembly to update it.
    Coding the ISR and locating it are not the problem. 
    Setting the interrupt vector is.  How do I do that in xc8 assembly?

     
    For that PIC device, I would stick with MPASM and even with MPLAB v8.92. ;)
     
     
    #7
    mad_c
    Super Member
    • Total Posts : 1249
    • Reward points : 0
    • Joined: 2010/12/12 17:48:27
    • Location: Brisbane, Australia
    • Status: offline
    Re: Where can I find informatio on xc8 assembly interrupt handling? 2020/06/21 14:12:09 (permalink)
    +1 (1)
    CollieJim
    I have a small MPASM program for a PIC16F1827 that uses interrupts, and find that I need to migrate to xc8 assembly to update it.
     

    Hi,
     
    I will point out that there is a PIC Assembler examples guide. This was not ready in time to ship with the 2.20 XC8 compiler, but it is now available on Microchip's web site, here:      MPLAB XC8 PIC Assembler User Guide for Embedded Engineers   This has an example that specifies an interrupt routine.
     
    Jeff.
    #8
    ric
    Super Member
    • Total Posts : 28006
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Where can I find informatio on xc8 assembly interrupt handling? 2020/06/21 15:15:28 (permalink)
    +1 (1)
    mad_c
    ...
     This has an example that specifies an interrupt routine.

    Why does the example interrupt exit with "retfie", rather than "retfie f", when it corrupts W?
    (It does preserve BSR, so I guess it was supposed to do W and STATUS as well, but doesn't.)
     
    Edit: ok, I see the answer is on the next page. This highly contrived example does not use W or STATUS in the non-interrupt code. This almost certainly will not be true in a real world application, so I don't see the sense in doing that in the example here.
     
    post edited by ric - 2020/06/21 15:27:51

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #9
    dan1138
    Super Member
    • Total Posts : 3730
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: Where can I find informatio on xc8 assembly interrupt handling? 2020/06/21 15:40:06 (permalink)
    +4 (4)
    Jeff,
     
    If you actually try to build the example code in that PDF file this is what you see:
    make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
    make[1]: Entering directory 'C:/PIC_dev/MPLABXv540_pic-as/18F47K42_Interrupt_Example.X'
    make  -f nbproject/Makefile-default.mk dist/default/production/18F47K42_Interrupt_Example.X.production.hex
    make[2]: Entering directory 'C:/PIC_dev/MPLABXv540_pic-as/18F47K42_Interrupt_Example.X'
    "C:\PIC_dev\MPLABXC\xc8\v2.20\pic-as\bin\pic-as.exe" -mcpu=PIC18F47K42 -c \
    -o build/default/production/test.o \
    test.S \
     -misa=std -msummary=+mem,+psect,-class,-hex,-file,-sha1,-sha256,-xml,-xmlfull -fmax-errors=20 -mwarn=0 -xassembler-with-cpp -Wl,-presetVec=0h -Wl,-pintCodeLo=018h -Wa,-a -Wl,-Map=test.map
    test.S:75:: warning: (1522) RAM access bit operand not specified, assuming banked memory
    test.S:76:: warning: (1522) RAM access bit operand not specified, assuming banked memory
    test.S:78:: warning: (1522) RAM access bit operand not specified, assuming banked memory
    test.S:80:: warning: (1522) RAM access bit operand not specified, assuming access-bank
    test.S:84:: warning: (1522) RAM access bit operand not specified, assuming banked memory
    test.S:98:: error: (876) syntax error
    test.S:99:: warning: (1522) RAM access bit operand not specified, assuming banked memory
    test.S:103:: warning: (1522) RAM access bit operand not specified, assuming banked memory
    test.S:109:: warning: (1522) RAM access bit operand not specified, assuming banked memory
    test.S:111:: warning: (1522) RAM access bit operand not specified, assuming banked memory
    make[2]: *** [build/default/production/test.o] Error 1
    make[1]: *** [.build-conf] Error 2
    make: *** [.build-impl] Error 2
    (908) exit status = 1
    nbproject/Makefile-default.mk:107: recipe for target 'build/default/production/test.o' failed
    make[2]: Leaving directory 'C:/PIC_dev/MPLABXv540_pic-as/18F47K42_Interrupt_Example.X'
    nbproject/Makefile-default.mk:91: recipe for target '.build-conf' failed
    make[1]: Leaving directory 'C:/PIC_dev/MPLABXv540_pic-as/18F47K42_Interrupt_Example.X'
    nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed

    BUILD FAILED (exit value 2, total time: 899ms)

    Seem the MPLAB XC8 PIC Assembler User Guide for Embedded Engineers is not really ready for publication.
     
    Did anyone at Microchip even notice how many bugs are in this code?
     
    This code purports to handle interrupts that are asserted by TIMER0, but is is not initialized anywhere or started.
     
    The interrupt system is not initialized so when the GIE, and PEIE bits are set it's still configured at where the power on reset left it. For a PIC18F47K42 that is "Disable priority levels on interrupts; all interrupts are treated as high priority interrupts".
     
    There numerous syntax errors and typos. This is crap code being foisted on an audience ill prepared to deal with it.
     
    Microchip should be ashamed and embarrassed to post any document of such poor quality.
    post edited by dan1138 - 2020/06/21 16:24:46
    #10
    mad_c
    Super Member
    • Total Posts : 1249
    • Reward points : 0
    • Joined: 2010/12/12 17:48:27
    • Location: Brisbane, Australia
    • Status: offline
    Re: Where can I find informatio on xc8 assembly interrupt handling? 2020/06/21 16:43:06 (permalink)
    +2 (4)
    dan1138
    If you actually try to build the example code in that PDF file this is what you see:

    Hi,
     
    You might notice that something went amuck in the formatting of the "DS 1" directive. It got split over multiple lines, which is not permitted. Joining those lines will allow it to build.

    This code purports to handle interrupts that are asserted by TIMER0, but is is not initialized anywhere or started.

    Correct. If you read the introduction to that section, you will see it states that "the configuration bits and timer setup, for example, are not present in this example" The guide is meant to be teaching people how to use features in the assembler application, not how to program PIC devices. Having to include all the required code to make something run (and even them, on just one device family) distracts from the topic at hand.
     
    Jeff.
     
    #11
    dan1138
    Super Member
    • Total Posts : 3730
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: Where can I find informatio on xc8 assembly interrupt handling? 2020/06/21 17:09:46 (permalink)
    +4 (4)
    mad_c
    Correct. If you read the introduction to that section, you will see it states that "the configuration bits and timer setup, for example, are not present in this example" The guide is meant to be teaching people how to use features in the assembler application, not how to program PIC devices. Having to include all the required code to make something run (and even then, on just one device family) distracts from the topic at hand.

    The PDF say in the introduction; "In order to focus on certain aspects of the assembler, the configuration bits and timer setup, for example, are not present in this example."
     
    It should go on to state that anything that may help you understand how the interrupt system should be initialized or how to preserve the interrupted context have been removed as well. And further unique typographic errors have been introduced just to see if you are paying attention.
     
    This is supposed to be a document written for engineers so I expect the examples to be concise AND complete regardless of how complex they must be to hit that mark.
     
    If I wanted code this bad I'd write it myself.
     
    #12
    mad_c
    Super Member
    • Total Posts : 1249
    • Reward points : 0
    • Joined: 2010/12/12 17:48:27
    • Location: Brisbane, Australia
    • Status: offline
    Re: Where can I find informatio on xc8 assembly interrupt handling? 2020/06/21 17:50:38 (permalink)
    +3 (3)
    dan1138
    It should go on to state that anything that may help you understand how the interrupt system should be initialized or how to preserve the interrupted context have been removed as well. And further unique typographic errors have been introduced just to see if you are paying attention.

    I hope there will be more time to revise the docs than there was to prepare them and that a more functionally consistent example can be included. I have also made a note to correct the split line issue; the warnings might actually be tackled in the assembler itself. They did not show in the test code when using a pre-release assembler. It might be possible to include the access location bits in the header definitions themselves.
     
    Thanks for your comments. Feedback is always appreciated.
     
    Jeff.
     
    #13
    Ken_Pergola
    Super Member
    • Total Posts : 2239
    • Reward points : 0
    • Joined: 2003/11/07 12:48:48
    • Status: offline
    Re: Where can I find informatio on xc8 assembly interrupt handling? 2020/06/21 18:24:41 (permalink)
    +6 (6)
    mad_c
    ...Feedback is always appreciated...



    Hi Jeff,
     
    In my opinion it is best that there is a checklist item in the final public release process of the PDF document that all code snippets tested are the actual snippets copied from the PDF document itself.
     
    I remember there have been MCU Data Sheets in which the code snippets in the PDF file could not be copied at all, or could be copied but when pasted are totally mangled which is maddening for any customer.
     
    Best regards,
     
    Ken
    #14
    dan1138
    Super Member
    • Total Posts : 3730
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: Where can I find informatio on xc8 assembly interrupt handling? 2020/06/21 19:53:21 (permalink)
    +2 (2)
    This is a concise AND complete example of the code that could have been published in the PDF:
    ; File:     main.S
    ; Target:   PIC18F47K42
    ; Author:   dan1138
    ; Date:     2020-06-21
    ; Compiler: pic-as(v2.20)
    ; IDE:      MPLABX v5.40
    ;
    ; Description:
    ;
    ;   Make PORTA an 8-bit output port and write a binary
    ;   count incremented from a TIMER0 interrupt event.
    ;
    ; Add to the MPLABX project Additional options:
    ;   -Wa,-a -Wl,-presetVec=0h,-phi_int_vec=08h,-plo_int_vec=18h -Wl,-Map=main.map
    ;
        PROCESSOR   18F47K42
        PAGEWIDTH   132
        RADIX       dec
    ;
    #include <xc.inc>
    ;
     CONFIG FEXTOSC=XT, RSTOSC=EXTOSC, CLKOUTEN=OFF, PR1WAY=ON
     CONFIG CSWEN=ON, FCMEN=ON, MCLRE=EXTMCLR, PWRTS=PWRT_OFF
     CONFIG MVECEN=OFF, IVT1WAY=ON, LPBOREN=OFF, BOREN=SBORDIS
     CONFIG BORV=VBOR_2P45, ZCD=OFF, PPS1WAY=ON, STVREN=ON
     CONFIG XINST=OFF, WDTCPS=WDTCPS_31, WDTE=OFF, WDTCWS=WDTCWS_7
     CONFIG WDTCCS=SC, BBSIZE=BBSIZE_512, BBEN=OFF, SAFEN=OFF
     CONFIG WRTAPP=OFF, WRTB=OFF, WRTC=OFF, WRTD=OFF
     CONFIG WRTSAF=OFF, LVP=ON, CP=OFF
    ;
    ;   bits in bank 0 data memory
        PSECT   BitFlags,global,class=BANK0,space=1,bit,noexec
    ;
        GLOBAL  bTimerEvent
    bTimerEvent: DS  1
    ;
    ;   Reset vector
        PSECT   resetVec,global,reloc=2,class=CODE,delta=1
    ;
    resetVec:
        goto    Start
    ;
    ;   High priority interrupt vector
        PSECT   hi_int_vec,global,reloc=2,class=CODE,delta=1
    ;
        goto    HighIsrHandler
    ;
    ;   Data space use by low priority interrupt handler to save context
        PSECT   LowIsr_data,global,class=COMRAM,space=1,delta=1,lowdata,noexec
    ;
        GLOBAL  WREG_save,STATUS_save,BSR_save
    ;
    WREG_save:      DS  1
    STATUS_save:    DS  1
    BSR_save:       DS  1
    ;
    ;   Low priority interrupt vector and handler
        PSECT   lo_int_vec,global,reloc=2,class=CODE,delta=1
    ;
    LowIsrVec:
        movff   WREG,WREG_save
        movff   STATUS,STATUS_save
        movff   BSR,BSR_save
    ;
    LowIsrHandler:
        BANKSEL PIE0
        btfsc   TMR0IE,b        ;did the timer generate this interrupt?
        btfss   TMR0IF,b
        bra     LowIsrExit      ;no - ignore
        bcf     TMR0IF,b        ;yes - clear the interrupt flag

        ;set a flag to say that the port should be incremented
        BANKSEL (bTimerEvent/8)
        bsf     BANKMASK(bTimerEvent/8),bTimerEvent&7,b
    ;
    LowIsrExit:
        movff   BSR_save,BSR
        movff   STATUS_save,STATUS
        movff   WREG_save,WREG
        retfie  0   ; Return from interrupt
    ;
    ;   High priority interrupt handler
        PSECT   HighIsr_code,global,reloc=2,class=CODE,delta=1
    ;
    HighIsrHandler:
        retfie  1   ; Fast return from interrupt
    ;
    ;   Startup code used at power on reset
        PSECT   start_code,global,reloc=2,class=CODE,delta=1
    ;
    Start:
        bcf     INTCON0,INTCON0_GIEH_POSITION,c   ; Disable all interrupts
        bcf     INTCON0,INTCON0_GIEL_POSITION,c
        bsf     INTCON0,INTCON0_IPEN_POSITION,c   ; Enable interrupt priority
    ;
    ; Initialize TIMER0 in 8-bit mode to reload after 128 counts.
    ; Assign the ISR to the low priority handler.
    ;
        clrf    T0CON0,c        ; Stop TIMER0
        movlw   0b01000000      ; Clock source: FOSC/4, Prescale 1:1
        movwf   T0CON1,c
        clrf    TMR0L,c         ; Clear 8-bit timer count register
        movlw   128-1
        movwf   TMR0H,c         ; Set 8-bit timer reload count
        BANKSEL PIE0
        bcf     TMR0IP,b
        bcf     TMR0IF,b
        bsf     TMR0IE,b
        bsf     T0CON0,T0CON0_EN_POSITION,c ; Start timer
        bsf     INTCON0,INTCON0_GIEH_POSITION,c   ; Enable all interrupts
        bsf     INTCON0,INTCON0_GIEL_POSITION,c
        goto    main
    ;
    ;   Data used by main application
        PSECT   main_data,global,class=RAM,space=1,delta=1,noexec
    ;
        GLOBAL  count
    count:      DS  1
    ;
    ;   Main application code
        PSECT   main_code,global,reloc=2,class=CODE,delta=1
    ;
    main:
        clrf    TRISA,c
        clrf    LATA,c
        BANKSEL count
        clrf    BANKMASK(count),b
    AppLoop:
        BANKSEL (bTimerEvent/8)
        bcf     BANKMASK(bTimerEvent/8),bTimerEvent&7,b
    EventWait:
        ;do we need to increment yet?
        btfss   BANKMASK(bTimerEvent/8),bTimerEvent&7,b
        bra     EventWait   ;no - keep checking
    ;
        ;yes - increment the value on the port
        BANKSEL count
        incf    BANKMASK(count),f,b
        movff   count,LATA
        goto    AppLoop
    ;
        END     resetVec

    It's 70 lines longer that what appears in the current PDF.
     
    It does run in the simulator but MPLABX v5.40 does not offer symbolic debug with the pic-as(v2.20) tool chain so you are back to stone knives and bear skins for debugging.
    post edited by dan1138 - 2020/06/22 10:07:00
    #15
    ric
    Super Member
    • Total Posts : 28006
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Where can I find informatio on xc8 assembly interrupt handling? 2020/06/21 20:03:49 (permalink)
    +3 (3)
    "stone knives and bear skins for debugging." ?
    You lucky, lucky b@$t@rd.
    We used to dream of having stone knives and bear skins for debugging. :)
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #16
    dan1138
    Super Member
    • Total Posts : 3730
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: Where can I find informatio on xc8 assembly interrupt handling? 2020/06/21 20:15:56 (permalink)
    +1 (1)
    ric
    We used to dream of having stone knives and bear skins for debugging. :)

    Yorkshiremen can be found everywhere! :)
    #17
    mlp
    boots too small
    • Total Posts : 946
    • Reward points : 0
    • Joined: 2012/09/10 15:12:07
    • Location: previously Microchip XC8 team
    • Status: offline
    Re: Where can I find informatio on xc8 assembly interrupt handling? 2020/06/22 11:53:44 (permalink)
    +1 (1)
    dan1138
    ric
    We used to dream of having stone knives and bear skins for debugging. :)

    Yorkshiremen can be found everywhere! :)

    Tell that to the young people of today, and they won't believe you!

    Mark (this opinion available for hire)
    #18
    cea
    Senior Member
    • Total Posts : 99
    • Reward points : 0
    • Joined: 2006/02/17 00:01:25
    • Location: 0
    • Status: offline
    Re: Where can I find informatio on xc8 assembly interrupt handling? 2020/06/22 12:58:13 (permalink)
    +1 (1)
    mark.pappin
    dan1138
    ric
    We used to dream of having stone knives and bear skins for debugging. :)

    Yorkshiremen can be found everywhere! :)

    Tell that to the young people of today, and they won't believe you!

    Stone knives, we'd a killed for a stone knife. All we got was a rusty pin and beating from the boss. :)
    #19
    1and0
    Access is Denied
    • Total Posts : 10999
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Where can I find informatio on xc8 assembly interrupt handling? 2020/06/22 16:12:43 (permalink)
    +2 (2)
    stone knives and bearskins ;)
     
    https://www.youtube.com/watch?v=F226oWBHvvI
     
     
     
    #20
    Jump to:
    © 2020 APG vNext Commercial Version 4.5