Remote-processing CAMBASIC Manuel d'utilisateur Page 202

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 208
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 201
Event Multitasking - 13
MULTITASKING ON A CLOCK TICK
The three 200 Hz (100 Hz in 9 MHz systems) tick timers are used for a number of multitasking functions in CAMBASIC.
In multitasking, it is used as a periodic interrupt. The ON T ICK statement can call a subroutine as often as 200 (100 in 9
MHz systems) times per second, or once ever y 327.67 seconds. The syntax is:
ON TICK number, time GOSUB line/label
On every multiple of the specified time, program execution branches to the subroutine at the line/label. Program
execution resumes when the RETUR N statement is reached in the subroutine.
A simple exam ple would be as follows:
10 ON TICK 0,1 GOSUB 50
20 PRINT "foreground"
30 FOR C=0 TO 1000:NEXT
40 GOTO 20
50 INC A%
60 PRINT A
70 RETURN
Line 10 tells CAMBASIC to interrupt every 1.00 seconds and branch to line 50.
Lines 20 through 40 represent a foreground program. It prints, does a short delay and prints again.
Line 50 increm ents a variable and r epresents the num ber of seconds.
In some applications m ultiple interr upts are r equired. T his can be done with the TICK statem ent. The only lim itation is
that the interrupt times must be multiples of each other. For exam ple, 1. 0 and 3.0 seconds would be acceptable, but 1.0
and 2. 7 seconds w ould not.
Below is a program that demonstrates clock interrupts every 1 and 5 seconds.
10 ON TICK 0,1 GOSUB 50
20 PRINT "foreground"
30 DELAY .25
40 GOTO 20
50 PRINT TAB(20);"tick";
60 INC A%:IF A%=5 THEN A%=0:GOSUB 70 ELSE PRINT:RETURN
70 PRINT " tock"
80 RETURN
Line 10 sets up an interrupt every 1.00 seconds
Lines 20 through 40 simulate your foreground program, as in the first example.
Line 50 prints “tick” every second
Line 60 increments a second counter. When it reaches 5, the counter is reset and "tock" is printed at
line 70.
Vue de la page 201

Commentaires sur ces manuels

Pas de commentaire