Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

MPLAB X debugging and interrupts

Status
Not open for further replies.

ganesh7792

New Member
Hi,

I tried to debug the below code , it seems the Timer interrupt flag is set, however the debugger never seems to go to the interrupt service routine.

Can't MPLAB simulate interrupts?


Code:
    list p=12F675
    #include<p12f675.inc>

RCCAL CODE 0x03ff
    res 1

    CODE 0x0100
MAIN bsf STATUS,RP0
    movwf OSCCAL

    ;Enable the interrupt by timer
    bcf STATUS,RP0
    BCF INTCON,2
    BSF INTCON,7
    BSF INTCON,5




    ; Enable the timer
    bsf STATUS,RP0
    BCF OPTION_REG,5

    ; Set GPIO in output mode
    movlw 0x00
    movwf TRISIO

    goto loop

GRST CODE 0x0000
    goto MAIN

ISR  CODE 0x0004
    bcf STATUS,RP0
    ; Clear the overflow flag of the timer
    BCF INTCON,2

    ; toggle the 0 bit of GPIO
    BTFSS GPIO,0
    BSF GPIO,0
    BCF GPIO,0

    RETFIE

loop nop
    goto loop

    END

-Ganesh
 
MPLAB can perfectly simulate interrupts.

Though I cannot see where the problem might be in your code.

I'd suggest to test Interrupt Priority Demonstration for the 18CXXX from this page **broken link removed** and check at first if it works with MPLAB SIM debugger (it worked right for me) and later try to adapt it to your microcontroller.

Hope it helps.
 
Last edited:
Hi,

Try following the Microchip template example.

Code:
;**********************************************************************
;   This file is a basic code template for assembly code generation   *
;   on the PIC12F675. This file contains the basic code               *
;   building blocks to build upon.                                    *
;                                                                     *
;   Refer to the MPASM User's Guide for additional information on     *
;   features of the assembler (Document DS33014).                     *
;                                                                     *
;   Refer to the respective PIC data sheet for additional             *
;   information on the instruction set.                               *
;                                                                     *
;**********************************************************************
;                                                                     *
;    Filename:	    xxx.asm                                           *
;    Date:                                                            *
;    File Version:                                                    *
;                                                                     *
;    Author:                                                          *
;    Company:                                                         *
;                                                                     *
;                                                                     *
;**********************************************************************
;                                                                     *
;    Files Required: P12F675.INC                                      *
;                                                                     *
;**********************************************************************
;                                                                     *
;    Notes:                                                           *
;                                                                     *
;**********************************************************************

	list      p=12f675           ; list directive to define processor
	#include <p12f675.inc>        ; processor specific variable definitions

	errorlevel  -302              ; suppress message 302 from list file

	__CONFIG   _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT 

; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See data sheet for additional information on configuration word settings.




;***** VARIABLE DEFINITIONS
w_temp        EQU     0x20        ; variable used for context saving 
status_temp   EQU     0x21        ; variable used for context saving






;**********************************************************************
		ORG     0x000             ; processor reset vector
		goto    main              ; go to beginning of program
	

		ORG     0x004             ; interrupt vector location
		movwf   w_temp            ; save off current W register contents
		movf	STATUS,w          ; move status register into W register
		movwf	status_temp       ; save off contents of STATUS register


; isr code can go here or be located as a call subroutine elsewhere


		movf    status_temp,w     ; retrieve copy of STATUS register
		movwf	STATUS            ; restore pre-isr STATUS register contents
		swapf   w_temp,f
		swapf   w_temp,w          ; restore pre-isr W register contents
		retfie                    ; return from interrupt


; these first 4 instructions are not required if the internal oscillator is not used
main
		call    0x3FF             ; retrieve factory calibration value
		bsf     STATUS,RP0        ; set file register bank to 1 
		movwf   OSCCAL            ; update register with factory cal value 
		bcf     STATUS,RP0        ; set file register bank to 0


; remaining code goes here



; initialize eeprom locations

		ORG	0x2100
		DE	0x00, 0x01, 0x02, 0x03


		END                       ; directive 'end of program'
 
To simulate timer interrupts, you will need to set a break point in the interrupt handler, then select the "Run" command. The code will stop with the PC at the break point once it enters the interrupt handler.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top