Try clearing INTEDG bit of OPTION_REG register. From the datasheet page 30(32):
INTEDG: Interrupt Edge Select bit
1 = Interrupt on rising edge of INT pin
0 = Interrupt on falling edge of INT pin
When PORTD is high, does the LED turn ON or OFF?
Also check out switch contact bounce. Here is a link on it and how to debounce. To check it is the contact bounce causing the thing that is seen as a "problem", add a delay of 500msec or 1 sec after PORTD=0xff;
in the interrupt routine. If the port is high, your problem is contact bounce if the above suggested solution doesn't solve your problem -that is clearing INTEDG bit.
You don't need that GIE=1;
in the last line of the interrupt block.
I have no experience with Hi-Tech C compiler. Chances are low but try doing INTE=1;
before GIE=1;
in the main function.
Edit
Try changing void intMain()
to void interrupt intMain()
. According to
HI-TECH C® for PIC10/12/16 User’s Guide 3.8 INTERRUPT HANDLING IN C (Page 86) Link
Edit After Second Question
According to the same manual mentioned above page(299):
To produce an infinite loop, use for(;;).
You are trying to assign an 'integer' value to a 'character' variable as I quoted below. Define variable i as unsigned char. Compiler should take care of this, but it is worth trying.
...
int i,k;
...
PORTD=i;
...
Best Answer
You do not specify what is meant by "not working", so I'll just point out a few things.
The interrupt service routine posted does not seem to address the program function described. This routine toggles a port, waits a second, then goes back to whatever was running before the interrupt was triggered. Instead you say you want the program to wait for a button press, then do something, then wait for another button press.
If the program is doing nothing but waiting for an input, you don't really need an interrupt, just a polling loop. Interrupts should be used when you need to quickly respond to an event, or do something at a precise time. ISRs should finish quickly; never should one include a one second delay.
Another thing to consider: There is more to using an interrupt than writing an ISR. I'm not familiar with mikroC, but in general you will need to at least set up an interrupt vector, configure the I/O or peripheral to generate an interrupt, and enable interrupts. Have you done all this necessary initialization?
Also, upon entry to an interrupt routine, the CPU context, its status and registers, must be saved, and restored upon return. Typically the compiler is alerted to this by using a keyword, often interrupt, in the function definition. Does the compiler understand that this is an ISR?
Finally, make sure your watchdog doesn't timeout while you are waiting for input.
Oh, and don't forget: you may have to debounce the pushbutton.