137
µ
PD17062
12.3.1 Example of Using the Timer Based on the BTM0CY Flag
An example of a program follows.
Example INITFLG NOT BTM0ZX, NOT BTM0CK2, NOT BTM0CK1, NOT BTM0CK0
; Built-in macro
; Specifies that the timer carry FF be set at intervals of 100 ms.
LOOP1:
MOV M1, #0110B
LOOP2:
SKT1 BTM0CY ; Built-in macro
; Tests the BTM0CY flag. Branches to NEXT if the flag is 0.
BR NEXT
ADD M1, #0100B ; Adds 4 to data memory M1.
SKT1 CY ; Built-in macro
; Tests the CY flag.
BR NEXT ; Branches to NEXT if the flag is 0.
Process A ; Performs process A if the flag is 1.
MOV M1, #0110B
NEXT:
Process B ; Performs process B and branches to LOOP.
BR LOOP
This program performs process A at intervals of one second.
Note the following point (1) when creating this program.
(1) The time interval at which the BTM0CY flag is checked must be less than the time interval at which the
timer carry FF is set to 1.
This is because if it takes 100 ms or longer to perform process B, it is impossible to detect when the timer
carry FF is set, as shown in Fig. 12-3.
Fig. 12-3 BTM0CY Flag Check and Timer Carry FF
SKT1
BTM0CY
SKT1
BTM0CY
SKT1
BTM0CY
Timer carry FF set pulse
BTM0CY flag
Process B
Process B'
Because it takes long to perform process B' after it is detected that the
BTM0CY flag is set at , it is impossible to detect when the BTM0CY
flag is set at .