#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;
}
}
I write this code to Control the Led with Switch using external Interrupt , the code compiled and have no error but led is not controlled with Pushbutton , dont know whats the Problem is
He's not using a MicroChip device, he's using a 8051 type processor.
But while I'm not familiar with his device, I don't see where he's enabling interrupts?, nor is he checking what caused the interrupt in his ISR (I won't even mention de-bouncing!).
Firstly your interrupt has to point to one of the interrupt vectors
Secondly in your forever loop you keep setting interrupts place these before the while loop
Im trying to remember what IT0 is... if its Timer 1 then that is incorrect.
The interrupt should be like this
void int_ISR(void) __interrupt (0) // I think your compiler will accept the vector pointer.
Register defs attached....page 87 C example for timer you could examine for rough applicable code to do pin based ISR....might be of help. Then look at pin based reg set for clues....
What IDE are you using, I saw a reference for an IDE for this series part that had example code.....