Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

Interrupt handling RB0/INT

Status
Not open for further replies.

myj

Newbie level 2
Joined
Oct 12, 2009
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Philippines
Activity points
1,294
Hi all,

Im having problem with my code. i am using mikroC compiler and PIC16F877A Microcontroller.
I incorporate external interrupt RB0/INT as input as i simulated thru the use of PROTEUS the interrupt does not occur. See please my code and have a solution for my problem.

main(){
unsigned int gCOUNT;
TRISB = 0x01;
TRISA = 0x00;

INTCON.GIE = 1; //Enable Global Interrupt
INTCON.INTE = 1; //Enable RB0/INT external Interrupt
INTCON.PEIE = 0; //Disable all unmasked peripheral interrupt
OPTION_REG.INTEDG = 1; //Interrupt on rising edge

if(INTCON.INTF == 1){++gCOUNT;}

}

Thanks,
joenil
 

m_saeed_soliman

Newbie level 3
Joined
Nov 6, 2009
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Cairo, Egypt
Activity points
1,313
please take a look at the MikroC for PIc help manual.
Search for "Interrupt" and youi will find information on how to handle inteeupt.
Regards,
 

Tahmid

Advanced Member level 5
Joined
Jun 17, 2008
Messages
4,758
Helped
1,791
Reputation
3,574
Reaction score
1,650
Trophy points
1,393
Location
Silicon Valley, California, USA (from Dhaka, Bangl
Activity points
30,545
Hi,
This is the fixed code:
Code:
unsigned int gCOUNT;

void interrupt(void){ //Interrupts must be handled through subroutine like this
     ++gCOUNT;
     INTCON.INTF = 0; //You HAVE to clear interrupt flag
}

void main(void){
    TRISB = 0x01;
    TRISA = 0x00;

    INTCON.GIE = 1; //Enable Global Interrupt
    INTCON.INTE = 1; //Enable RB0/INT external Interrupt
    INTCON.PEIE = 0; //Disable all unmasked peripheral interrupt
    OPTION_REG.INTEDG = 1; //Interrupt on rising edge

    do{ //Repeat endlesssly
    }while(1);
}
Interrupt has to be handled through subroutine as shown. Remember you HAVE to clear interrupt flag in the ISR - Interrupt Service Routine, or that will continue going on. Hope you can understand the code and the mistakes you made.

Hope this helps.
Tahmid.
 
  • Like
Reactions: Taswar

    Taswar

    points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top