Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

endless loop interrupt

Status
Not open for further replies.

ibrahim_damt

Newbie level 4
Joined
Nov 28, 2006
Messages
7
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,330
i want to make a project by pic microcontroller if i press a switch i make an interrupt and enter endless loop ( in this loop i wait the user to adjust some values using different switches and when he save the value ,return to the main program )

can i make endless loop in inturrupt or there is another better way ? plz can any one help me ..........
 

The endless loop is good enough, but hard to make if using assembly. If you're using C you could use something like this:
Code:
short int SAVED=0;
while (!SAVED){
	//let the user make the changes
	//make sure you set SAVED to 1 when he ends
	SAVED = 1;
}
This code loops until SAVED becomes 1. Inside the loop you may let the user modify values in your program and do whatever you need.
Although, it's not a good practice to put a huge routine as a interrupt routine, most compilers will even produce a warning or an error. So you probably want to integrate the endless loop inside your main code.

There are other methods for changing values inside your program which do not involve using endless loops but only some interrupt code. But it depends on how your main program should behave; if it has to totally stop when modifying values then endless loop is the solution, if not then just use some code inside the interrupt routine.

If you give us a more precise idea of how the program should behave we could probably suggest better methods for achieving the result you want.
 

A program that tolerates "endless" loops in interrupt routines won't need interrupts at all. It apparently don't involve any high priority activities that are the usual purpose of interrupt functions. I presume that you don't plan nested interrupts.

Generally speaking, interrupt routines are not the appropriate place to process user activities.
 
The endless loop is good enough, but hard to make if using assembly.

You can use a label and goto statement to create an infinite loop.

Code:
SOMELABEL
;do stuff
;do some other stuff
;do other requied stuff
;just make sure SOMELABEL is added at the end of it all,
;      so that the infinite loop isn't exited
goto SOMELABEL

i want to make a project by pic microcontroller if i press a switch i make an interrupt and enter endless loop ( in this loop i wait the user to adjust some values using different switches and when he save the value ,return to the main program )

can i make endless loop in inturrupt or there is another better way ? plz can any one help me ..........

If you'll be using an endless loop in the interrupt, it means that once the interrupt is activated, the interrupt is never left. So, this means that nothing else is needed to be done. So, there is no reason to use the interrupt. Not that this is an error. But since this is the only thing that'll be done, why not just do it in the main code. Instead of interrupt, you can use polling. Once the condition is met, the code can enter the endless loop in the main code.

Hope this helps.
Tahmid.
 

i cannot do endlessloop in inturrupt or calling function or use goto statment . the program cannot accept that

i cannot use polling because i use delay bt every calculatoin about 5 sec , and the program is long so the program cannot sensing press of button

i use another method :

void interrupt() {
if (INTF_bit) {

INTF_bit = 0;

pressbutton = 1 ;

}

in the main () :

if (pressbutton==1)
{
Lcd_Cmd(_LCD_CLEAR) ;
pressbutton = 0 ;
setmodeselect() ; // the funcion used to adjust values

}

it works but it takes delay time to execute ,since it depends on interrupt + if statement , i think in another method , i need to jump directly from interrupt to line :function setmodeselect()
 
Last edited:

You can use a label and goto statement to create an infinite loop.
Yes, obviously! Just it's a bit tricky managing lots of jumps in an assemlby program, that's what I really meant ;)
 

it works but it takes delay time to execute ,since it depends on interrupt + if statement

Is this delay problematic? Probably isn't. It's such a tiny delay.

You showed one correct way of doing it.

The other way is by polling. So, try it:

Code:
//In main code wherever you need it
   while (INTF_bit == 0);
   INTF_bit = 0;
   //Rest of the stuff:
   LCD_Cmd(_LCD_CLEAR);
   setmodeselect();
   //Anything else you want to do
   //.....
   //.....

i cannot do endlessloop in inturrupt or calling function or use goto statment . the program cannot accept that
The program doesn't accept it because, as far as I remember, mikroC doesn't let you call other functions/procedures. You probably called the function setmodeselect() and mikroC didn't allow that.


Hope this helps.
Tahmid.
 

thank you for replay

while statment; means that at this line the program will stop untile this line execute ,i dont need that i need the program to continue execute(the program measure temperature) until user need to adjust some values like alaram for high temperature`
 

Most embedded microcontroller systems are designed to allow user input while the system is performing other activities. You can describe this feature as multitasking, although it's usually achieved by simple application design arrangements rather than dedicated multitasking software or even an operation system. Interrupts may be used to provide a timer tick or possibly to scan a keyboard. An essential point is that time time consuming procedures make periodical calls to a system() function that schedules concurrent activities if necessary.

I'm sure, that similar methods can also work in your application.
 
Hi Ibrahim,

You can make the interrupt
while(1)
{
if(SwitchPressed && !Savebit)
{
PressButton = 1;
}
if(PressButton)
{
Ask the user to set the value
if(SavePressed)
{
SaveBit=1;
PressButton = 0;
}
}
}

regads
Sreekanth
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top