View previous topic :: View next topic |
Author |
Message |
irmanao
Joined: 08 Apr 2015 Posts: 77
|
button interrupt (solved) |
Posted: Mon Jul 13, 2015 1:04 pm |
|
|
dsPIC33EP512MU810 (dspic33e usb starter kit)
ccs version 5.008
I'm trying to write a simple program that flashes a LED everytime a button is pushed. The code compiles but when the button is pushed nothing happens.
From starter kit's users guide: Quote: | When idle, the switches are pulled high (+3.3V). When pressed, they are grounded. |
Code: | #include <33EP512MU810.h>
#fuses PR_PLL,NOWDT,NOPROTECT
#use delay(internal=80000000)
#pin_select INT1=PIN_D7
void init_all (void);
int16 dms=1000;
void main() {
while(TRUE){}
}
#INT_EXT1
void ext_int1(void)
{output_high(PIN_D2);
delay_ms(dms);
output_low(PIN_D2);
delay_ms(dms);
}
void init (void){
ext_int_edge(1, H_TO_L);
enable_interrupts(GLOBAL);
enable_interrupts(INT_EXT1);
}
|
Any ideas?
_thanks_
Last edited by irmanao on Mon Jul 13, 2015 1:48 pm; edited 1 time in total |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jul 13, 2015 1:14 pm |
|
|
Quote: | void main() {
while(TRUE){}
} |
Program control for user code starts at main(). But your main() never
does anything. It doesn't call any functions. It doesn't setup interrupts.
It just sits in a continuous loop. |
|
|
irmanao
Joined: 08 Apr 2015 Posts: 77
|
|
Posted: Mon Jul 13, 2015 1:32 pm |
|
|
Of course..
I added and changed:
Code: | ...
void init (void);
int16 dms=1000;
void main() {
init();
...
|
thanks a lot |
|
|
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Mon Jul 13, 2015 2:59 pm |
|
|
It is also a good idea to NOT have a delay inside an ISR. In this case, you are ok with nothing else going on, but a better way is when the interrupt goes off, set a counter to some value that gets decremented by a timer for example. Inside main() watch the counter - if non-zero, turn on the LED, if zero, then turn it off. That way, you can have a bunch of things running for different times and starting at different times for example that is still listening for other things (like serial or whatever else is needed for the circuit).
mikey _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
|
|