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.

[PIC] problem in rb4 interrupt

Status
Not open for further replies.

ahatmob

Newbie level 5
Newbie level 5
Joined
Sep 15, 2014
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Location
egypt- cairo
Visit site
Activity points
54
i am trying to make 2 push button interrupt and to calculate the time elapsed between them using counter t and make the result displayed on port c
the problem is that portb rb4 is interrupting automatically i donot why there is my code
Code:
int x=0;
int t=0;
void interrupt(){
  if(INTCON.F1){
   x = portb;
   INTCON.f0=0;
   INTCON.F1=0;
                }
                else if(intcon.f0){

    t++;
   portc=t; }             }

void main() {
trisc =0x00;
 trisb =0xff;
 portc =0;
 portb=0;
 option_reg =0x00;
INTCON =0x98;
/*for(;;){
portc = t;
delay_ms(1000);
        }*/
}
 

see that you probably use MikroC. Which PIC microcontroller do you use?
How does look your hardware? Do you have stable logic state on RB4 pin?
 

Also you should not comment out the for loop at the end. If that is not there, then the 'main' function will end and, if the C runtime is anything like the XC8/16 one, the device will reset and then the 'main' function is called again.
Without knowing the actual PIC, but going by the general way Microchip design their 'interrupt on change' capability, you can get an interrupt when any of the target pins change and part of the ISR is to read the port (which also clears the mismatch condition that triggered the interrupt in the first place - and I see you are doing) and then check that the pin(s) you are interested in have changed and in which direction. Remember that interrupt on change triggers on both edges.
Also, I hope you are debouncing the signals in hardware as there is no debouncing code. If not then you will be getting a number of spurious interrupts for each button press and release.
Susan
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top