creating INT0 in PIC18f458
Discussion in "PIC Microcontroller Discussion" started by kingrosekhan123 Mar 22, 2013.
Fri Mar 22 2013, 09:49 pm
hello...
i write this code for external interrupt..
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.
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
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
what is the difference ,when i use INT0 or only if statement..
can you give me example..???
can you give me example..???
Powered by e107 Forum System