bbgil
Full Member level 2
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;
}
}//~!
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;
}
}//~!