working of External Interrupt0 of PIC18F4550

Status
Not open for further replies.

phoenix prasanna

Newbie level 6
Joined
Aug 19, 2013
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
81
Hello everyone,I am learning PIC uc interrupts in which LEDs should glow as output on reception of each falling edge signal on INT0(pin RB0 of PIC18F4550) but LEDs are not toggling when button is pressed.My code and sim is attached below hope you can help me out.
 

Attachments

  • Interrupts.rar
    54.2 KB · Views: 99

Code:
void interrupt()              // Interrupt ISR
{
   
    LATD=~LATD;               // Invert (Toggle) the value at PortD
    Delay_ms(500);           // Delay for 1 sec
    INTCON.INT0IF=0;          // Clear the interrupt 0 flag
}
 

ud23 : Thanks for your kind help,but still not working.
Algorithm which i used is mentioned in prog according to which PORTD o/p should toggle but not quite getting it but when i reset ckt it starts toggling in infinite loop.
 

Before while(1) loop set ADCONx register so that all pins are configured as digital IO.


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
//Program to depict the working of External Interrupt0 of PIC18F4550
 
void interrupt() {
 
    if(INTCON.INT0IF) {
        LATD = ~LATD;
        INT0IF_bit = 0;
    }
}
 
 
void main() {
 
    TRISB = 0x01;
    PORTB = 0x00;
    LATB = 0x00;
    
    TRISD = 0x00;
    PORTD = 0x00;
    LATD = 0x00;
    
    INTCON = 0x10;
    INTCON2 = 0;
    INTCON.GIE = 1;
    INTCON.PEIE = 1;
    
    LATD = 0xAA;
    
    while(1) {
 
    }
}

 

Configure ADCON1 register.
Thank you for your good suggestion.The prog needed to confg ADC and set RB0/AN12 inorder to take i/p but haven't used PORTx to store value still it worked.

Code:
ADCON1=0x03;                             // Make RB0/AN12 pin as analog pin (Other pins remain to be digital I/O)
    ADCON0=0x0C;                             // Select Channel0 & ADC off
    ADCON2=0x8A;                             // Left justified, 2TAD acquiciation time, Fosc/32 clock option
    ADCON0.ADON=1;                           //Enable ADC
 

INT0IE bit is set Enable(=1) by INTCON =0x10, as INT0IE bit is 00010000b which is equivalent to 10h.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…