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.

[SOLVED] Interrupt On Change and Delay Loop problem

Status
Not open for further replies.

speedEC

Full Member level 6
Full Member level 6
Joined
Apr 1, 2011
Messages
337
Helped
23
Reputation
46
Reaction score
21
Trophy points
1,298
Activity points
4,324
Dear All,

I have a problem to read Interrupt On Change while the device in software delay loop (using "for loop"). First, if I found any change in RB4-RB7 (IOC) pins, GREEN LED will be ON. if interrupt RB0 (INT0) occurred While GREEN LED is in ON Status, then ON another RED LED for 5 minutes and OFF the RED LED after 5 minutes. I have used "for loop" for 5 minutes delay. If any change in RB0 -RB7 found, while RED LED is in ON Status (in for loop), I have to come out from the "for loop" and OFF the Red LED. How can do that? I have tried but failed. I could not able to OFF the RED LED. Should I use tiimer instead of "for loop"?

thanks
pmk
 

good problem.... don't worry I'll give you a great trick..

>> first define a global variable..

ex : int n =0;

>> Then add a if statementin the for loop in the RB0 interrupt..
ex:
if(INTF==1){ //RB0 interrupt occurred
for(i = 0; i < max;i++){
if(n==1) i=max; //when n=1 loop will be stop
//rest
}
}

>> Then upadate variable n to 1 when RB4-RB7 was occurred..

ex:

if(RBIF==1){ //if RB4-7 interrupt was occurred, n will change to 1
n=1;
}

Result:

when RB4-7 interrupt was occurred n will be 1 and then for loop in RB0 interrupt will be end.

that's all... :grin:
 
Last edited:
Thanks smeety. I have tried. But didn't work. Because, if INT0 occurred then goes into loop (for 5 min). So, while in loop, it didn't respond to Int on change interrupt.

thanks
pmk
 

I'll add some changes to Smeety's reply, It'll solve your problem..

don't use a variable to control the loop, just check RB4-7 value in the loop..

if(INTF==1){ //RB0 interrupt occurred

x = <RB4-7 value>

for(i = 0; i < max;i++){
y= <RB4-7 value>
if(x!=y) i=max; //when <RB4-7 value> changed, loop will be stop
//rest
}
}

this will be work..! good luck.. :razz:
 
Thanks ajex. Actually, I want to lights-up RED LED continuously only for 5 minutes. In between the 5 minutes delay, If interrupt occurred on RB0-RB7, then RED LED should be OFF. In your reference code, the RED LED lights-up continuously until interrupt occurred on RB0-RB7. Am I right? If I wrong pl update me.

Thanks
pmk
 

Thanks smeety and ajax,

As you told, I have modified code as follows. Now its work fine as that I was expected. Great Thanks to both of you for help you provided.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
void ALARM_ON(void){
    T1CON=0b00000001;
    count = mSecDelay;  // Reset Counter
    while (1){
        while (! TMR1IF);
        TMR1IF = 0;
        if (RBIF){
            RBIF = 0;
            n = 1;
            count = mSecDelay;  // Reset Counter
            ALARM = 0;  // OFF the Alarm
            TMR1IF = 0; // Clear Timer Flag
            TMR1IE = 0; //disable timer1
          break;
        }
        count--;
        if (count == 0){
            count = mSecDelay;  // Reset Counter
            ALARM = 0;  // OFF the Alarm
            TMR1IF = 0; // Clear Timer Flag
            TMR1IE = 0; //disable timer1
          break;
        }
    }
}
main(){
while(1){
        if (RBIE && RBIF){   // If IOC (RB4-RB7) occurred or Timer1
            delay_ms(10);   // To find Switch Debounce
            if(RB4 == 1){
                if (n == 1){
                    n = 0;
                    mismatch_Clr = PORTB;
                    RBIF = 0;
                    RBIE = 1;
                  break;
                }
                if(LED == 1){
                   LED = 0;
                   beep_Off();
                }
                else{
                    LED = 1;
                    beep_On();
                    delay_ms(300);
                    
                    beep_On();
                }
            }
        mismatch_Clr = PORTB;
        RBIF = 0;
        RBIE = 1;
        }
        
        if (INTE && INTF) { // If interrupt INT0 occurred
            delay_ms(10);
            if(RB0 == 0){
                if (LED == 1){
                    LED = 0;    // GREEN LED OFF
                    ALARM = 1;  // ON ALARM
                    ALARM_ON();
                }
            }
        INTF = 0;
        INTE = 1;
        }
    }
}



thanks
pmk
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top