CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

button interrupt (solved)

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
irmanao



Joined: 08 Apr 2015
Posts: 77

View user's profile Send private message

button interrupt (solved)
PostPosted: Mon Jul 13, 2015 1:04 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jul 13, 2015 1:14 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jul 13, 2015 1:32 pm     Reply with quote

Of course..

I added and changed:
Code:
...
void init (void);
int16 dms=1000;
             
void main() {
init();
...


thanks a lot Shocked
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Mon Jul 13, 2015 2:59 pm     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group