ahmar123
Newbie level 5

I write this code to Control the Led with Switch using external Interrupt INT0 , the code compiled and have no error but led is not controlled with Pushbutton , dont know whats the Problem is...
if this code is not
then this one is also not working
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 #include<reg51.h> sbit LED = P2^0; // LED at P2.0 sbit Switch = P3^2; // Switch at External Interrupt Pin P3.2 void interrpt () { if (Switch == 1) { // If switch is HIGH LED = 1; // LED ON } else { // If switch is LOW LED = 0; // LED OFF } } void main() { LED = 0; // Initial LED OFF Switch = 1; while (1) { EA = 1; EX0 = 1; IT0 = 0; } }
if this code is not
then this one is also not working
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 #include<reg51.h> sbit LED = P2^0; // LED at P2.0 sbit Switch = P3^2; // Switch at External Interrupt Pin P3.2 void external_ISR(void) interrupt 0 { // ISR for External Interrupt 0 if (Switch == 1) { // If switch is HIGH LED = 1; // LED ON } else { // If switch is LOW LED = 0; // LED OFF } } void main() { EA = 1; // Enable Global Interrupts EX0 = 1; // Enable External Interrupt 0 IT0 = 1; // Interrupt on Falling Edge LED = 0; // Initial LED OFF while (1) { // Infinite Loop - Waiting for Interrupt } }
Last edited by a moderator: