Discussion in "PIC Microcontroller Discussion" started by    kingrosekhan123    Mar 22, 2013.
Fri Mar 22 2013, 09:49 pm
#1
hello...
i write this code for external interrupt..

unsigned int flag = 0;

void interrupt() {
if (INTCON.INT0IF==1)
{
INTCON.INT0IF = 0;
flag = 1;
}
}

void main()
{
TRISA=0x00;
TRISB.F0=0x01;
ADCON1 = 0b10000111;
CMCON = 0x07;
CVRCON.CVROE = 0;
INTCON = 0b11010000;
INTCON2 = 0b11100001;
INTCON3 = 0b00000000;

while(1){
if(flag == 1){
flag = 0;


PORTA = ~PORTA;



}
}
}



its working as when int0 goes high INT comes ,led glows on portA and when again int0 goes high ,it turn off the PORTA..
but i want that LED's goes high only if int0 is 1,when int0 becomes low led should off.

simply ,when then push button is pushed LED's should on
when push button release LED's should off.
Mon Mar 25 2013, 10:13 am
#2
You have to then wait for INT to go low in your while loop.

if(flag == 1){
    flag = 0;
    PORTA = ~PORTA;
    // wait for int pin to go low..
    while(PORTB.PB0 == 1); //pseudo code.. replace with exact port pin and nomenclature
    PORTA = ~PORTA; // turn off port again
 kingrosekhan123 like this.
Mon Mar 25 2013, 08:54 pm
#3
what is the difference ,when i use INT0 or only if statement..
can you give me example..???
Tue Mar 26 2013, 06:27 pm
#4
I do not understand what exactly you are trying to ask.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

RandyBence
Wed May 15 2024, 02:00 pm
JordanDic
Wed May 15 2024, 01:55 pm
DavidDeelf
Wed May 15 2024, 11:16 am
ytaletjkca
Wed May 15 2024, 09:45 am
MildredWoumb
Wed May 15 2024, 04:07 am
NaKrutkADamb
Wed May 15 2024, 12:03 am
MichaelGot
Tue May 14 2024, 04:08 pm
FrankTrelm
Tue May 14 2024, 10:39 am