Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics 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.

interrupt not working

Status
Not open for further replies.

bbgil

Full Member level 2
Joined
Mar 11, 2006
Messages
135
Helped
13
Reputation
26
Reaction score
9
Trophy points
1,298
Activity points
2,321
interrupt pic mikroc rbie

hi. i'm practicing mikroC but i cannot make the interrup work. its a very simple program, switch at RB0 as interrupt and count the number of time switch is on and off. put into port A the final count. its compilling but the output seems to be fix at output 9 when i run the PIC in the breadboard. Can someone point out what i'm doing wrong here. here is the code. thanks in advance.
unsigned cnt;
unsigned pc;

void interrupt() {
cnt++;
pc=0x0A;
cnt = cnt-pc;
if (cnt!=0) { PORTA =cnt;}
else { cnt =0;PORTA=cnt;}
INTCON = 0x02 ; }


void main() {

TRISB = 0xFF; // PORTB is input
PORTB = 0xFF; // Initialize PORTB
TRISA=0;
PORTA=0;
INTCON = 0x98; // Enable RB0 interrupt
cnt = 0; // Initialize cnt

while (1) {
PORTA = cnt;
}

}//~!
 

i'm not an expert in PICs but the interruption i think isn't ok.

Code:
void interrupt() { 
...

i've studied C51 and i write this:

Code:
void int_name() interrupt #{
...
}

the # is the interruption number.

for example:

extern interruption 0 -> #=1
Code:
void int_rutine() interrupt 1{
...
}
 

hi,

please remove the line INTCON = 0x02 ; from ur interrupt function and test it
 

fixed the problem! its the INTCON setting on the interrupt. Should be

unsigned cnt;
unsigned pc;

void interrupt() {
cnt++;

if (cnt > 0x09) { cnt =0;PORTA=cnt;}
else { PORTA =cnt;}
INTCON = 0x10 ; }// set INTE and clear the flag


void main() {

TRISB = 0xFF; // PORTB is input
PORTB = 0xFF; // Initialize PORTB
TRISA=0;
PORTA=0;
INTCON = 0x90; // Enable RB0 interrupt, GIE and RBIE
cnt = 0; // Initialize cnt

while (1) {
PORTA = cnt;
}

}//~!

I failed to set the interrupt the first time. Must set it up and cleari the flag at the same time after the interrupt.

thanx for all the help.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top