I have a question to ask regarding about external interrupt program. If i'm using INT1(External Interrupt 1 set to Falling Edge) of DS89C450 and my program of the external interrupt is very long, will it function properly? or will there be any problem with it? I'm using Keil embedded C.
Another way to do this without an RTOS is to use event flags and state machines. Your program can be diagrammed into discrete states that transition when a particular event is called. For example, in this diagram I found using google:
A button click is an event; something that can be triggered from your INT1 interrupt for example. You would then put the following loop in the foreground:
#define STATE_POWER_OFF 1
#define STATE_POWER_ON 2
#define EVENT_BUTTON_CLICK 0x01
volatile unsigned char bEventFlags = 0;
unsigned char bState = STATE_POWER_OFF;
unsigned char getEventFlags( void ) ;
int main(void)
{
for(;;)
{
unsigned char flags = getEventflags() ;
if (flags != 0)
{
switch (bState)
{
case STATE_POWER_OFF:
if (flags & EVENT_BUTTON_CLICK)
{
// Do something
bState = STATE_POWER_ON;
}
break;
case STATE_POWER_ON:
if (flags & EVENT_BUTTON_CLICK)
{
// Do something
bState = STATE_POWER_OFF;
}
break;
}
}
}
}
unsigned char getEventFlags( void )
{
unsigned char flags = 0 ;
// Get copy of flags in critical section and clear down
_disable_interrupts() ;
flags = bEventFlags ;
bEventFlags = 0 ;
_enable_interrupts ;
return flags ;
}
And your ISR would then be very short:
void INT1_ISR(void)
{
bEventFlags |= EVENT_BUTTON_CLICK;
}