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.

Problem with PORTB port change interrupt

Status
Not open for further replies.

zhaniko93

New Member
Code:
   LIST P=16F628A, R=DEC    ; Use the PIC16F628 and decimal system

   #include "P16F628A.INC"  ; Include header file
   __config  _INTRC_OSC_NOCLKOUT & _LVP_OFF & _WDT_OFF & _PWRTE_ON & _BODEN_ON & _MCLRE_OFF 
   errorlevel -302



   goto Start
   org 0x4
   bcf INTCON, RBIF
   retfie


 
Start  movlw 7 
   movwf CMCON        

   
   bsf INTCON, RBIE
   bsf INTCON, GIE

   clrf PORTA
   clrf PORTB


  banksel TRISA

   movlw b'11110000'       ; RB3(PWM)=0 
   movwf TRISB
   

  banksel PORTA

   

nop
goto $-1


        END

when simulating in osohsoft Pic simulator IDE,everything goes fine untill I put PORTB, 7 port on 1, interrupt happens and then after retfie, interrupt happens again! and again, and again in spite of I change from 1 to 0 or not, why?
 
Last edited:
missing portb read

Replace your interrupt handler code with:
Code:
goto Start
   org 0x4
   movf PORTB,w ; you must read PORTB upon Int-on-chg
   bcf INTCON, RBIF
   retfie

Quote from section 5.2 of the datasheet:

Clear the
interrupt in the following manner:
a) Any read or write of PORTB. This will end the
mismatch condition.
b) Clear flag bit RBIF.
A mismatch condition will continue to set flag bit RBIF.
Reading PORTB will end the mismatch condition and
allow flag bit RBIF to be cleared
 
I forgot that:
a) Any read or write of PORTB. This will end the
mismatch condition.

Thanks Mosaic!
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top