Delay time is blocking a CPU for 5 seconds.Typically each UART would generate an interrupt and set a bit in an interrupt register. When any interrupt bit is set, the ISR would process it and upon returning from the ISR it would immediately interrupt again because another bit was still set and that in turn would be processed. Remember that interrupts are a hardware feature so they can be requested simultaneously, the ISR program can then process them sequentially.
Brian
void main()
{
}
ISR ()
{
}
* setup:
define RED_LED = 0 as global integer variable
define RED_GREEN = 0 as global integer variable
*.. called every 100ms:
if (RED_LED > 0)
{
if (--RED_LED == 0)
{
turn off red LED;
}
else
{
turn on red LED;
}
}
if (GREEN_LED > 0)
{
if (--GREEN_LED == 0)
{
turn off green LED;
}
else
{
turn on green LED;
}
}
and so on.
* somewhere in code:
if (button green is pressed) GREEN_LED = 50 ; to make it ON for 5s
* somewhere else in code:
if (red LED on via UART is received ) RED_LED = 30 ; to make it ON for 3s
.. and so on.
Delay time is blocking a CPU for 5 seconds.
void Setup(void) {
SetLEDPort(PortA.1); // Configures the LED
SetButtonInterrupt(PortA.0); // Configure the button
SetTimerInterrupt(5); // Configure your timeout.
}
void main() {
Setup();
EnableInterrupts();
}
void ButtonInterrupt(void) {
PortA.1 = 1; // LED on
StartTimer();
}
void TimerInterrupt(void) {
PortA.1 = 0; // LED off
}
The program does nothing... but usually still the processor is running (doing a loop).Advantage: your program does nothing when there is no event.
Hi,
The program does nothing... but usually still the processor is running (doing a loop).
But especially for low power applications (battery powered) ... you may indeed use power saving modes (depends on microcontroller) that switch off the core clock. No code is executed then, just the counter for the interrupt is running, and wakes up the processor after the desired time.
Klaus
why did you choose only 100 milliseconds why can't it be 50 milliseconds, 200 milliseconds or any other value. Is there any specific reason for 100 millisecond ?Hi,
On the other hand:
I´d never do a "wait 5 seconds" in a real ime system.
Better run a task every 100ms.
Klaus
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?