' StopMultiTasking.bas ' A tutorial on how to halt a task ' by C.D.Odom on 5-20-06 ' www.basicxandrobotics.com ' chris_odom@georgeschool.org ' NB: this work was heavily influenced by Don Kinzer's ' postings on Yahoo's BasicX discussion group. Specifically: ' http://groups.yahoo.com/group/basicx/message/18507 ' and ' http://groups.yahoo.com/group/basicx/message/18510 ' NB: There's a typo on message 18510. It should read taskStack(1) = bxTaskExit ' NOT taskStack(1) = bxExitTask. Option Explicit ' Set aside memory space for each task: Dim RedLEDStack(1 to 50) as Byte ' Here, I set aside 50 bytes of space. ' To determine the exact stack space required, ' use Don Kinzer and Mike Perk's bxDism program found at: ' http://home.austin.rr.com/perks/micros/bxDism/ Dim GreenLEDStack(1 to 75) as Byte ' Just to show some variety, I set aside 75 bytes of space. ' To determine the exact stack space required, ' use Don Kinzer and Mike Perk's bxDism program found at: ' http://home.austin.rr.com/perks/micros/bxDism/ Public Sub Main() Dim i as Integer CallTask "RedLEDTask", RedLEDStack ' The RedLEDTask will run independently from Main CallTask "GreenLEDTask", GreenLEDStack ' The GreenLEDTask will run independently from Main ' While it counts to 500, watch the onboard LEDs. You should notice that ' RedLEDTask and GreenLEDTask do not interrupt the Main program For i = 1 to 500 Debug.Print "i = " & CStr(i) Next ' Stop the GreenLEDTask by setting the first byte of the stack equal to the built-in constant bxTaskExit GreenLEDStack(1) = bxTaskExit Call Delay(10.0) ' Pause for 10 seconds CallTask "GreenLEDTask", GreenLEDStack ' Start GreenLEDTask again End Sub ' ////////////////////// RedLEDTask /////////////////////// Sub RedLEDTask() Do Call PutPin(25,1) ' Turn Red LED off Call Delay(0.2) Call PutPin(25,0) ' Turn Red LED on Call Delay(0.2) Loop End Sub ' ////////////////////// GreenLEDTask /////////////////////// Sub GreenLEDTask() Do Call PutPin(26,0) ' Turn Green LED on Call Delay(0.2) Call PutPin(26,1) ' Turn Green LED off Call Delay(0.2) Loop End Sub