Hi,
There are many different ways of doing it and the "right" one depends on what you'll actually intend to do with it - in the end.... It's not uncommon to post something that does what's currently 'at hand' only to get something like OK, that works, now I want it to do this and that which, if it had been known from the start might have warranted another solution.
Anyway, here's an example of what I was trying to explain earlier:
Code:
Pattern VAR BYTE
StepInPattern VAR BYTE
Main:
Select Case Pattern
Case 0 : Goto Pattern1
Case 1 : Goto Pattern2
Goto Main
' ------ Subroutine for pattern 1 ------
Pattern1:
Select Case StepInPattern
Case 0
High LED1
StepInPattern = 1 'Next time, next step
Case 1
LOW LED2
StepInPattern = 2
Case 2
HIGH LED2
StepInPattern = 3
Case 3
LOW LED 2
StepInPattern = 0 'Next time, start over
END SELECT
Pause 100
Goto Main
' ------ Subroutine for pattern 2 ------
Pattern2:
Select Case StepInPattern
Case 0
HIGH LED1
LOW LED2
StepInPattern = 1 'Next time, next step
Case 1
LOW LED1
HIGH LED2
StepInPattern = 0 'Next time, start over
END SELECT
Pause 50
Goto Main
Basically it's two statemachines "driven" by the Pattern and StepInPattern variables. In your interrupt routine you can simply reset the StepInPattern variable and set Pattern to what ever pattern you want and it will start that pattern from the beginning. There will be a delay up to the longest Pause time that you've got in there but it won't have to complete the full cycle.
This is not very code effective but it illustrates what I meant.
On a project of mine I have single LED indicating various states of the device. I have a set of patterns defined something like this:
Code:
Status_LED_Pattern_OK CON %0000000011111111
Status_LED_Pattern_Fault CON %1010101010101010
Status_LED_Pattern_Wait CON %1111000011110000
I can then select which pattern I want by doing:
Code:
Pattern = Status_LED_Pattern_OK
And in my main interrupt I have counter (PatternPointer) incrementing every 1/10th of a second which "points into" the pattern variable and sets the output driving the LED to the state of that bit, like:
Code:
PortB.0 = Pattern.0[PatternPointer]
Obviosuly the interrupt code needs to make sure that "pointer" only counts from 0-15 and then starts over or strange things WILL happen.
/Henrik.
Disclaimer: The above is from the top of my head to illustrate the tecnique, it may or may not work exactly as written.
Bookmarks