Tasks and State
programming
|
|
|
Last updated:
07-09-11 |
|
|
|
|
|
|
|
State
programming with:
switch( ) case
|
Count_ver1_case
This
type of programming also refered as
"run to complete" programming, even
the use of while( true) {
} loops |
|
|
|
|
State
programming with:
goto
|
Count_ver1_goto
|
|
|
|
|
State
programming with:
task ..
Exit_To
|
Count_ver1_task
|
|
|
|
|
1 System tick = 1 millisecond
|
The
Wait( time) call will leave the task
"sleeping" for the given time.
This will not be a good solution if
the task also should be able to
detect changes of input signals
during the wait time. |
|
The
CurrentTick( ) function returns the
actual millisecond counter of the
system.
This enable a task the calculate the
actual time passed. |
|
|
|
|
Count_ver2_case |
This counter version program will wait for a
button press (B==1) and increment Count1.
If the button keep being pressed will the counter be incremented
once each 1000 millisecond.
|
|
|
Count_ver2_goto
Even the
goto statement got "bad standing" among
professional programmers, could it be useful for
"state programming". |
|
|
|
|
|
|
The same code with
comments |
|
|
|
|
|
|
Count_ver2_task |
The task Counter1 will be called by the
Precedes( ..) statement and hence start the state-machine.
The ExitTo(
..) function works like the goto statement and
force a shift between tasks.
|
|
|