AN #131 - Pseudo Multitasking in Real Time |
|
Pseudo Multitasking in Real Time
This application note was submitted by Andrzej
Sablik
' Andrzej Sablik e-mail: sablik@poczta.onet.pl
' This program implements the pseudo multitaslking in
BASCOM ( Real-time )
' This example is offered on an "AS IS"
,but it is rather then the example of solution.
' You have alone to account for every task time.
$sim
$regfile = "8535DEF.DAT"
$crystal = 8000000
Config Timer0 = Timer , Prescale = 64
On Ovf0 Scheduler
Load Timer0 = 6 ' 2 ms sample
Enable Timer0
Start Timer0
Enable Interrupts
Dim T As Byte
Dim Flaga1 As Bit
Dim Flaga2 As Bit
Dim Flaga3 As Bit
'-------------------------------------------------------------------------------
Config Adc = Single , Prescaler = Auto
Start Adc
Dim A As Word
Dim B As Word
Dim C As Word
Dim Pos As Word
'-------------------------------------------------------------------------------
Task1:
Incr A '*
Print " a= " ; A '* Sample 1 program
If A > 1000 Then A = 0 '*
'
'------------------------
If Flaga1 = 1 Then
Goto Task1
Elseif Flaga2 = 1 Then
Goto Task2
Else
Goto Task3
End If
'-------------------------------------------------------------------------------
Task2:
Incr B '*
Print " b= " ; B '* Sample 2 program
If B > 1000 Then B = 0 '*
'------------------------
If Flaga1 = 1 Then
Goto Task1
Elseif Flaga2 = 1 Then
Goto Task2
Else
Goto Task3
End If
'-------------------------------------------------------------------------------
Task3:
Incr C '*
Print " c= " ; C '* Sample 3 program
If C > 1000 Then C = 0 '*
'------------------------
If Flaga1 = 1 Then
Goto Task1
Elseif Flaga2 = 1 Then
Goto Task2
Else
Goto Task3
End If
'-------------------------------------------------------------------------------
Scheduler:
Incr T
Reset Flaga1 : Reset Flaga2 : Reset Flaga3
If T = 2 Then Flaga1 = 1'for example task 1 starts if t=2 and ended if t=4
If T = 5 Then Flaga2 = 1
If T = 9 Then
Flaga3 = 1 : T = 0
End If
Return
|