• AVR Freaks

Hot!Interurrpt not responding, INT on PIC 16F1828, DIP Package, Pin RA2 (17)

Author
microchipprob
Senior Member
  • Total Posts : 140
  • Reward points : 0
  • Joined: 2008/07/01 00:51:30
  • Location: 0
  • Status: offline
2019/08/23 08:24:00 (permalink)
0

Interurrpt not responding, INT on PIC 16F1828, DIP Package, Pin RA2 (17)

Hi
With much difficulty i made this following program work but for the external interrupt, my PWM is responding well and also my A/D, i wanted to change the duty cycle with a press of INT key, interrupt is not responding, next i put in a LED in the  interrupt routine under vector 0004,to check for entering interrup subroutine, thats not happening, not able to understand as to why interrupt is not responding, my interrupt pin is RA2, Pin 17, MICON IS 16f1828 -20pIN dip, Help needed Thanks in advance  
;******************************************************************************
; This file is a basic code template for code generation on the *
; PIC16F1828. 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. *
; *
; Refer to the respective data sheet for additional *
; information on the instruction set. *
; *
;******************************************************************************
; *
; Filename: xxx.asm *
; Date: *
; File Version: *
; *
; Author: *
; Company: *
; *
; *
;******************************************************************************
; *
; Files Required: P16F1827.INC *
; *
;******************************************************************************
; *
; Notes: *
; *
;******************************************************************************
; *
; Revision History: *
; *
;******************************************************************************
list p=16f1828 ; list directive to define processor
#include <p16f1828.inc> ; processor specific variable definitions
;------------------------------------------------------------------------------
;
; CONFIGURATION WORD SETUP
;
; The 'CONFIG' directive is used to embed the configuration word within the
; .asm file. The lables following the directive are located in the respective
; .inc file. See the data sheet for additional information on configuration
; word settings.
;
;------------------------------------------------------------------------------
__CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_ON & _IESO_OFF & _FCMEN_OFF
__CONFIG _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_19 & _LVP_OFF
;------------------------------------------------------------------------------
; VARIABLE DEFINITIONS
;
; Available Data Memory divided into Bank 0-15. Each Bank may contain
; Special Function Registers, General Purpose Registers, and Access RAM
;;------------------------------------------------------------------------------
CBLOCK 0x20 ; Define GPR variable register locations
MYVAR1 ; User variables allocated contiguously
MYVAR2 ;
MYVAR3 ;
RESULTLO ;
RESULTHI ;
ANSEL
dc1
dc2
d1
d2
d3

dig4
dig3
dig2
dig1
dig0
Lbyte
Hbyte
L_byte
H_byte
dlyCnt

; UDATA
;dc1 res 1 ; delay loop counters
;dc2 res 1
ENDC
SAMPLE1 EQU 0x7D ; Sample user registers
SAMPLE2 EQU 0x7E ;
SAMPLE3 EQU 0x7F ;
;------------------------------------------------------------------------------
; EEPROM INITIALIZATION
;
; The 16F1828 has 256 bytes of non-volatile EEPROM, starting at address 0xF000
;
;------------------------------------------------------------------------------
DATAEE ORG 0xF000
DE "MCHP" ; Place 'M' 'C' 'H' 'P' at address 0,1,2,3
;------------------------------------------------------------------------------
; RESET VECTOR
;------------------------------------------------------------------------------
ORG 0x0000 ; processor reset vector
PAGESEL START
GOTO START ; When using debug header, first inst.
; may be passed over by ICD2.
;------------------------------------------------------------------------------
; INTERRUPT SERVICE ROUTINE
;------------------------------------------------------------------------------
ORG 0x0004

BANKSEL INTCON
BCF INTCON,GIE
MOVLW 0x05
BANKSEL CCPR4L
ADDWF CCPR4L
BANKSEL LATB
BCF LATB,6 ; pin 11
BANKSEL INTCON
BCF INTCON,INTF
BSF INTCON,GIE

RETFIE
;------------------------------------------------------------------------------
; USER INTERRUPT SERVICE ROUTINE GOES HERE
;------------------------------------------------------------------------------
; Note the 16F1828 family automatically handles context restoration for
; W, STATUS, BSR, FSR, and PCLATH where previous templates for 16F families
; required manual restoration. Shadow registers store these SFR values, and
; shadow registers may be modified since they are readable and writable for
; modification to the context restoration.
;RETFIE ; return from interrupt
;------------------------------------------------------------------------------
; MAIN PROGRAM
;------------------------------------------------------------------------------
START
; LED Initialisation port pins as outputs
BANKSEL TRISC
BCF TRISC,3 ;clear RC3 LED4
BCF TRISC,4 ;clear RC4 LED3
BCF TRISC,6 ;clear RC6 LED2
BCF TRISC,7 ; led
BANKSEL TRISB
BCF TRISB,6
BANKSEL LATB
BSF LATB,6 ; no glow orange
;*******FOsc set for 8 Mhz***
BANKSEL OSCCON
MOVLW 0x72
MOVWF OSCCON
;****************************
BANKSEL LATC
BSF LATC,7 ; glow led
CALL delay_500ms
BCF LATC,7
call delay_500ms
BSF LATC,7
; Interupt Enabling**********************

BANKSEL INTCON
CLRF INTCON
BANKSEL PIE1
clrf PIE1
BANKSEL PIE2
CLRF PIE2
BANKSEL PIE3
CLRF PIE3
BANKSEL PIR1
CLRF PIR1
BANKSEL PIR2
CLRF PIR2
BANKSEL PIR3
CLRF PIR3
;BANKSEL TRISA ;
;BSF TRISA,2 ;
BANKSEL TRISB
BCF TRISB,6
BANKSEL INTCON
BCF INTCON,INTF
BSF INTCON,GIE
BSF INTCON,INTE ; Enable INT
;**************************************

;*******PWM Intialisation*****************
;*****************************************
; PWM INITIALISATION
;Pwm_Init

BANKSEL CCP4CON
clrf CCP4CON

BSF CCP4CON,3
BSF CCP4CON,2
BCF CCP4CON,5
BCF CCP4CON,4

BANKSEL TRISC ;TRISA
BCF TRISC,6 ; TRISA,2 ;clear RC5 pwm o/p
BANKSEL PIE1
clrf PIE1
BANKSEL TMR2
CLRF TMR2
MOVLW 0xFA
BANKSEL PIR2
MOVWF PR2 ; PR2 = 0x65,4.90 KHz,pwm frequency
MOVLW 0x70 ;7b ;3d, approc 0.50; duty cycle
BANKSEL CCPR4L
MOVWF CCPR4L
BANKSEL CCPTMRS0
clrf CCPTMRS0
BCF CCPTMRS0,4
BCF CCPTMRS0,5

BANKSEL INTCON
CLRF INTCON
BANKSEL CCP4CON
BCF CCP4CON,5
BCF CCP4CON,4

BANKSEL T2CON
MOVLW 0x01
MOVWF T2CON
BANKSEL T2CON
BSF T2CON,TMR2ON ; start timer2
;***************************************************
;***************************************************

;***UART configuration**********
Uart_Init
BANKSEL TRISB ;
BCF TRISB,7 ;clear RB7 as Tx
;****baud rate selection***9600**
BANKSEL BAUDCON
MOVLW 0x40
MOVWF BAUDCON

BANKSEL RCSTA
MOVLW 0x80
MOVWF RCSTA

BANKSEL SPBRGL ; //9600,8Mhz,BR=12
MOVLW 0x0c
MOVWF SPBRGL

BANKSEL SPBRGH
MOVLW 0x00
MOVWF SPBRGH

BANKSEL TXSTA
MOVLW 0x20 ;ok
MOVWF TXSTA
;***********************************
;*****Noritake display configuration****
BANKSEL TXREG
MOVLW 0x0E
MOVWF TXREG
wait
BANKSEL PIR1
btfss PIR1,TXIF
goto wait
;***************************************
call delay_500ms
BANKSEL TXREG
MOVLW 0x0C
MOVWF TXREG
wait1
BANKSEL PIR1
btfss PIR1,TXIF
goto wait1
;***sending data to chechk data digit 4 sent**
movlw 0x34
BANKSEL TXREG
movwf TXREG
wait2
BANKSEL PIR1
btfss PIR1,TXIF
goto wait2
call delay_500ms
;*******************************************
movlw 0x11 ; decimal = 4567
movwf Hbyte
movlw 0xd7
movwf Lbyte
call hex_bcd
call Write_disp
;Adc_Init
;*********ADC Configuration*****************
BANKSEL ADCON1
movlw 0x90; ;Right justied,Frc/8;clock,
MOVWF ADCON1 ;Vdd and Vss Vref
BANKSEL TRISB ;
BSF TRISB,4 ;Set RB4 to input
BANKSEL ANSELB ;
BSF ANSELB,4;Set RB4 to analog, Pin 13 DIP package
BANKSEL ADCON0 ;
movlw 0x28 ;B00101000 ;Select channel AN10
movwf ADCON0
BSF ADCON0,0; A/D switched on
call delayus ; Aquisition time

;***start conversion and read data*******
BANKSEL ADCON0
BSF ADCON0,1 ;start conversion
retry
BTFSC ADCON0,1 ;Is conversion done
GOTO retry ;No, test again
BANKSEL ADRESH ;
MOVF ADRESH,w ;Read upper 2 bits
BANKSEL Hbyte ; important
MOVWF Hbyte
BANKSEL ADRESL
MOVF ADRESL,w ;Read lower 8 bits
BANKSEL Lbyte ; important ******************&&&&&&&&&&&
MOVWF Lbyte ;Store in GPR space
;*****end of A/D *************************
call hex_bcd
call Write_disp
goto $
;***** delay usec (380usec)
delayus
movlw 0x10
movwf dlyCnt
dlyRpt
decfsz dlyCnt,f
goto dlyRpt
return

;********************************
; Delay = 0.500 seconds
; Clock frequency = 8 MHz
delay_500ms ;corrected to 500msecs
movlw 0x08
movwf d1
movlw 0x2f
movwf d2
movlw 0x03
movwf d3
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto Delay_0
;6 cycles
goto $+1
goto $+1
goto $+1
return;
;------------------------------------------------------------------------------
; PLACE USER PROGRAM HERE
;------------------------------------------------------------------------------
hex_bcd
movlw 0x00
movwf dig0
movwf dig1
movwf dig2
movwf dig3
movwf dig4; highest
BANKSEL STATUS
again1 clrf STATUS

movfw Lbyte
movwf L_byte
movfw Hbyte
movwf H_byte

movlw 0x10
subwf Lbyte
movlw 0x27 ;2710h =10000
subwfb Hbyte
BANKSEL STATUS
btfsc STATUS,C ; if the result is negative C = 0
goto repet1
goto nex_1000 ; here the result is negative and you go to next step without adding back to H_Byte:L_Byte
repet1
incf dig4
goto again1
nex_1000
movfw L_byte
movwf Lbyte
movfw H_byte
movwf Hbyte ; full value moved to Lbyte & Hbyte restoredrestored

movlw 0xe8 ;03E8h =1000,LN HN
subwf L_byte ; and go on with 49663 in HN_Byte:LN_Byte
movlw 0x03
subwfb H_byte ; H_byte,L_byte are having full values
btfsc STATUS,C
goto repet2
goto nex_100 ; let them negative again and go to next step
repet2
incf dig3
goto nex_1000
nex_100
movfw Lbyte
movwf L_byte
movfw Hbyte
movwf H_byte ; H_byte,L_byte is having full value

movlw 0x64 ; 100
subwf Lbyte
movlw 0x00
subwfb Hbyte
btfsc STATUS,C
goto repet3
goto nex_10
repet3
incf dig2
goto nex_100
nex_10
movfw L_byte
movwf Lbyte

;movff LN_Byte,LByte
movlw 0x0a ;
subwf L_byte
btfsc STATUS,C ;next_units
goto repet4
goto next_units
repet4
incf dig1
goto nex_10
next_units
movfw Lbyte
movwf dig0
return

Write_disp
;==Write to display************************
MOVLW 0x30
addwf dig4
movfw dig4
BANKSEL TXREG
MOVWF TXREG
wait3
BANKSEL PIR1
btfss PIR1,TXIF
goto wait3

call delay_500ms

MOVLW 0x30
addwf dig3
movfw dig3
BANKSEL TXREG
MOVWF TXREG
wait4
BANKSEL PIR1
btfss PIR1,TXIF
goto wait4

call delay_500ms

MOVLW 0x30
addwf dig2
movfw dig2
BANKSEL TXREG
MOVWF TXREG
wait5
BANKSEL PIR1
btfss PIR1,TXIF
goto wait5

call delay_500ms

MOVLW 0x30
addwf dig1
movfw dig1
BANKSEL TXREG
MOVWF TXREG
wait6
BANKSEL PIR1
btfss PIR1,TXIF
goto wait6

call delay_500ms

MOVLW 0x30
addwf dig0
movfw dig0
BANKSEL TXREG
MOVWF TXREG

wait7
BANKSEL PIR1
btfss PIR1,TXIF
goto wait7

call delay_500ms

return

END
#1

5 Replies Related Threads

    ric
    Super Member
    • Total Posts : 23545
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Interurrpt not responding, INT on PIC 16F1828, DIP Package, Pin RA2 (17) 2019/08/23 14:51:47 (permalink)
    +1 (1)
    Stop your ISR code twiddling the GIE bit right now.
    That is WRONG and will come back to bite you later

    ;------------------------------------------------------------------------------
    ; INTERRUPT SERVICE ROUTINE
    ;------------------------------------------------------------------------------
    ORG 0x0004

    BANKSEL INTCON
    BCF INTCON,GIE
    MOVLW 0x05
    BANKSEL CCPR4L
    ADDWF CCPR4L
    BANKSEL LATB
    BCF LATB,6 ; pin 11
    BANKSEL INTCON
    BCF INTCON,INTF
    BSF INTCON,GIE

    RETFIE

     
    Your actual mistake is not realising that ALL analog capable pins power up in analog mode, and you need to switch any used as digital inputs into digital mode.
    You are switching RB4 to analog mode, but it would have been anyway.
    You are not switching RA2 into digital mode, so it will always be reading zero.
     

    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
    microchipprob
    Senior Member
    • Total Posts : 140
    • Reward points : 0
    • Joined: 2008/07/01 00:51:30
    • Location: 0
    • Status: offline
    Re: Interurrpt not responding, INT on PIC 16F1828, DIP Package, Pin RA2 (17) 2019/08/23 22:48:03 (permalink)
    0
    Dear Friend RIC,
                          I have modified INT Pin RA2 digital input as suggested by you, still my program is not entering into interrupt 0X0004, enclosing part  asm file. I am not polling peripheral int flags as I am only restricted to INT (external interrupt) , no other peripheral interrupt is used, Micon 16F1828 20 Pin DIP
    Unable to trap the mistake help needed 
     
    ;******************************************************************************
    ; This file is a basic code template for code generation on the *
    ; PIC16F1828. 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. *
    ; *
    ; Refer to the respective data sheet for additional *
    ; information on the instruction set. *
    ; *
    ;******************************************************************************
    ; *
    ; Filename: xxx.asm *
    ; Date: *
    ; File Version: *
    ; *
    ; Author: *
    ; Company: *
    ; *
    ; *
    ;******************************************************************************
    ; *
    ; Files Required: P16F1827.INC *
    ; *
    ;******************************************************************************
    ; *
    ; Notes: *
    ; *
    ;******************************************************************************
    ; *
    ; Revision History: *
    ; *
    ;******************************************************************************
    list p=16f1828 ; list directive to define processor
    #include <p16f1828.inc> ; processor specific variable definitions
    ;------------------------------------------------------------------------------
    ;
    ; CONFIGURATION WORD SETUP
    ;
    ; The 'CONFIG' directive is used to embed the configuration word within the
    ; .asm file. The lables following the directive are located in the respective
    ; .inc file. See the data sheet for additional information on configuration
    ; word settings.
    ;
    ;------------------------------------------------------------------------------
    __CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_ON & _IESO_OFF & _FCMEN_OFF
    __CONFIG _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_19 & _LVP_OFF
    ;------------------------------------------------------------------------------
    ; VARIABLE DEFINITIONS
    ;
    ; Available Data Memory divided into Bank 0-15. Each Bank may contain
    ; Special Function Registers, General Purpose Registers, and Access RAM
    ;;------------------------------------------------------------------------------
    CBLOCK 0x20 ; Define GPR variable register locations
    MYVAR1 ; User variables allocated contiguously
    MYVAR2 ;
    MYVAR3 ;
    RESULTLO ;
    RESULTHI ;
    ANSEL
    dc1
    dc2
    d1
    d2
    d3

    dig4
    dig3
    dig2
    dig1
    dig0
    Lbyte
    Hbyte
    L_byte
    H_byte
    dlyCnt

    ; UDATA
    ;dc1 res 1 ; delay loop counters
    ;dc2 res 1
    ENDC
    SAMPLE1 EQU 0x7D ; Sample user registers
    SAMPLE2 EQU 0x7E ;
    SAMPLE3 EQU 0x7F ;
    ;------------------------------------------------------------------------------
    ; EEPROM INITIALIZATION
    ;
    ; The 16F1828 has 256 bytes of non-volatile EEPROM, starting at address 0xF000
    ;
    ;------------------------------------------------------------------------------
    DATAEE ORG 0xF000
    DE "MCHP" ; Place 'M' 'C' 'H' 'P' at address 0,1,2,3
    ;------------------------------------------------------------------------------
    ; RESET VECTOR
    ;------------------------------------------------------------------------------
    ORG 0x0000 ; processor reset vector
    PAGESEL START
    GOTO START ; When using debug header, first inst.
    ; may be passed over by ICD2.
    ;------------------------------------------------------------------------------
    ; INTERRUPT SERVICE ROUTINE
    ;------------------------------------------------------------------------------
    ORG 0x0004

    MOVLW 0x05
    BANKSEL CCPR4L
    ADDWF CCPR4L
    BANKSEL LATB
    BSF LATB,6 ; pin 11,put off orange led, when entering interrupt routine
    BANKSEL INTCON
    BCF INTCON,INTF
    RETFIE
    ;------------------------------------------------------------------------------
    ; USER INTERRUPT SERVICE ROUTINE GOES HERE
    ;------------------------------------------------------------------------------
    ; Note the 16F1828 family automatically handles context restoration for
    ; W, STATUS, BSR, FSR, and PCLATH where previous templates for 16F families
    ; required manual restoration. Shadow registers store these SFR values, and
    ; shadow registers may be modified since they are readable and writable for
    ; modification to the context restoration.
    ;RETFIE ; return from interrupt
    ;------------------------------------------------------------------------------
    ; MAIN PROGRAM
    ;------------------------------------------------------------------------------
    START
    ; LED Initialisation port pins as outputs
    BANKSEL TRISC
    BCF TRISC,7 ; led pin9 red led
    BANKSEL TRISB
    BCF TRISB,6 ; pin 11 orange led


    ;*******FOsc set for 8 Mhz***
    BANKSEL OSCCON
    MOVLW 0x72
    MOVWF OSCCON
    ;****************************
    BANKSEL LATC
    BSF LATC,7 ; glow led
    CALL delay_500ms
    BCF LATC,7
    call delay_500ms
    BSF LATC,7
    ; Interupt Enabling**********************

    BANKSEL INTCON
    CLRF INTCON
    BANKSEL PIE1
    clrf PIE1
    CLRF PIE2
    CLRF PIE3

    BANKSEL PIR1
    CLRF PIR1
    CLRF PIR2
    CLRF PIR3

    BANKSEL PORTA
    CLRF PORTA
    BANKSEL LATA
    clrf LATA
    BANKSEL ANSELA
    BCF ANSELA,2 ; RA2 assigned digital
    BANKSEL TRISA
    BCF TRISA,2 ; int pin RA2 as digital input
    BANKSEL TRISB
    BCF TRISB,6 ;
    BANKSEL INTCON
    BCF INTCON,INTF
    BSF INTCON,GIE ; Enable global interupt
    BSF INTCON,INTE ; Enable INT
    BANKSEL LATB
    BCF LATB,6 ; glow orange led
    ;**************************************
    --
    #3
    ric
    Super Member
    • Total Posts : 23545
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Interurrpt not responding, INT on PIC 16F1828, DIP Package, Pin RA2 (17) 2019/08/23 23:31:36 (permalink)
    +1 (1)
    This line is making pin RA2 into an OUTPUT, not an INPUT.
    BCF TRISA,2 ; int pin RA2 as digital input

     
    Please put "code" tags around any code you post.
    That is [CODE] before the code, and [/CODE] after it, but use lower case instead.
    (I used upper case so you could see them)
     
     
     

    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
    ric
    Super Member
    • Total Posts : 23545
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Interurrpt not responding, INT on PIC 16F1828, DIP Package, Pin RA2 (17) 2019/08/24 04:32:42 (permalink)
    +1 (1)
    The code in your first post set GIE long before you had finished initialising your peripherals, which is a bad idea.
    Get all your peripherals initialised, THEN set GIE.
     
    Plus, in the middle of your PWM initialisation, you clear INTCON.
    Why?
    Naturally, that clears GIE, and you never set it again.
     
     

    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!
    #5
    microchipprob
    Senior Member
    • Total Posts : 140
    • Reward points : 0
    • Joined: 2008/07/01 00:51:30
    • Location: 0
    • Status: offline
    Re: Interurrpt not responding, INT on PIC 16F1828, DIP Package, Pin RA2 (17) 2019/08/24 20:58:14 (permalink)
    +1 (1)
    Thanks a lot RIC, I inadvertently made the mistake, my INT is working nowSmile: Smile
    #6
    Jump to:
    © 2019 APG vNext Commercial Version 4.5