External interrupt

 #include <reg51.h>

sbit LED = P1^0;  // LED connected to Port 1, Pin 0

void External_Int0_Init() {
    IT0 = 1;   // Edge triggered (falling edge)
    EX0 = 1;   // Enable External Interrupt 0
    EA = 1;    // Enable global interrupt
}

// Interrupt Service Routine for INT0
void External0_ISR(void) interrupt 0 {
    LED = ~LED;  // Toggle the LED
}

void main() {
    LED = 0;               // Initialize LED off
    External_Int0_Init();  // Initialize INT0

    while(1) {
        // Main loop does nothing; LED toggles in ISR
    }
}

Post a Comment

Post a Comment (0)

Previous Post Next Post

ads

ads

Update cookies preferences