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

newbie need interrupt help

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



Joined: 17 Oct 2005
Posts: 26

View user's profile Send private message

newbie need interrupt help
PostPosted: Mon Oct 17, 2005 8:04 am     Reply with quote

hi the problem that i have with my program is that i want to call a function from the main program and loop round this function until an interrupt is recived on port b this is were the problem comes when the interrupt has happened i do not want to return to the instruction that was going to be excuted next in the function i want to jump to the the start of my main progam again as shown in my code below but i can not get the following code to compile it comes up with the error undefined lable that was used in a goto. Any help with problem would be much apperictaed. here is the code i am trying to get working . This is not actual program i am wrirting but this is what i want to be able to do


#include <16F877A.H>
#device ICD=TRUE
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#include <Button.c>

#define
/**********************************isr*********************/
#int_Ext
void LIMIT_switch(void)
{
goto start; // go to start of main program
}

/****************************ledflash**********************/


void led_flash()
{
while (1)
{
output_low(PIN_C0); // loop until interrupt is recived
delay_ms(500);
output_high(PIN_C0);
delay_ms(500);
}
}

/***********************************************************/

void main()
{
int8 A0 = 0;
set_tris_c(0x00);
port_b_pullups(true);
ext_int_edge(0,H_TO_L);
enable_interrupts(INT_EXT);
enable_interrupts(global);



while (1)
{
start:
if(button(PIN_A0, 0, 50, 10, A0, 1)) //wait for button press on pin A0
led_flash();
}



}
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Mon Oct 17, 2005 8:35 am     Reply with quote

Good luck with stack management jumping out of your interrupt like that. Probably not restoring flags either. Look at your LST file to see what you have done.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
asmallri



Joined: 12 Aug 2004
Posts: 1636
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Mon Oct 17, 2005 9:19 am     Reply with quote

You may have a reason for restarting your code that is not obvious from the example and description you have given. If not then this is not the right way to approach the problem. One way (there are many) would be to set a global flag "found_it" in the interrupt handler. Then in led_flash() test the state of the flag to detemine if you should exit the function and clear the flag. If you need to exit immediately without completing any delay_ms(500) in progress then I suggest replacing the delay_ms function with your own timer driven code which supports continuous polling of the flag.

Another (cleaner?) approach is to use a timer interrupt to toggle the LEDS. Setup timer2 to interrupt every 10ms and a counter with a value of 50. Every time a timer interrupt occues decrement the counter. If the counter reaches zero then toggle the LED and reset the counter to 50. Then in the Ext_Int handler you stop timer 2. Your main loop could use the state of the timer 2 on/off condition to perform a conditional operation (like reinitialise)....
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!


Last edited by asmallri on Mon Oct 17, 2005 9:25 am; edited 1 time in total
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Oct 17, 2005 9:20 am     Reply with quote

Lookup reset_cpu()
asmallri



Joined: 12 Aug 2004
Posts: 1636
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Mon Oct 17, 2005 9:26 am     Reply with quote

Mark wrote:
Lookup reset_cpu()


Does that work on the 16F family?
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Oct 17, 2005 10:57 am     Reply with quote

Yes,

Quote:
Syntax:
reset_cpu()



Parameters:
None



Returns:
This function never returns



Function:
This is a general purpose device reset. It will jump to location 0 on PCB and PCM parts and also reset the registers to power-up state on the PIC18XXX.



Availability:
All devices



Requires
Nothing



Examples:
if(checksum!=0)

reset_cpu();



Example Files:
None



Also See:
None






PCB and PCM parts would be 10's, 12's, and 16's.
morebudwiser



Joined: 17 Oct 2005
Posts: 26

View user's profile Send private message

PostPosted: Mon Oct 17, 2005 12:52 pm     Reply with quote

hi thanks for the replys, the progam i am actual trying to write controls a stepper motor.the main progarm controls an lcd menu selection that allows me to set variables for controlling the speed and the amonut of times the motor rotates. The other function controls the motor what i am trying to do with the intrerrupt is stop the motor and return to the main lcd selection menu. could you please give me a short example of how i could do this using a global flag or is there any books that anyone could recommend that would give me some programming examples
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 17, 2005 1:11 pm     Reply with quote

Quote:
could you please give me a short example of how i could do this using a global flag

These two threads have examples of setting a global flag in an
interrupt service routine, and then polling the flag in loop in main().
http://www.ccsinfo.com/forum/viewtopic.php?t=24530
http://www.ccsinfo.com/forum/viewtopic.php?t=10032
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