/ tests / timer2.asm
timer2.asm
 1  ; Test program to verify correct emu8051 operation
 2  ;
 3  ; Test desc: timers
 4  ; Test output: PC = $FFF0
 5  ; Test output: SP = $60
 6  ; Test output: R0 = $80
 7  ; Test output: R1 = $16
 8  ; Test output: R2 = $F4
 9  ; Test output: R3 = $3E
10  ; Test output: TIMER0 = $8086
11  ; Test output: TIMER1 = $F4F9
12  ; Test output: TCON = $A0
13  ; Test output: TMOD = $22
14  ; Test output: PSW = $00
15  
16  TOS     EQU     60h     ; Adresse du dessus de la pile.
17  
18          ORG     0000h           ; Reset vector
19          MOV     SP,#TOS         ; Init stack pointer
20  
21          MOV     TMOD,#00100010B ; Init timers 0 and 1 as 8-bit timers (TL),
22                                  ; reloaded with TH when overflow occurs.
23  
24          ;;  First test: no overflow
25  	MOV	TH0,#080h       ; Reload value
26  	MOV	TH1,#0F4h       ; Reload value
27  	MOV	TL0,#00h        ; Set initial value of timer0
28         	MOV	TL1,#28h        ; Set initial value of timer1
29          LCALL   DELAY
30  
31          MOV     00h, TH0         ; Save value of timer 0
32          MOV     01h, TL0
33          MOV     02h, TH1         ; Save value of timer 1
34          MOV     03h, TL1
35          MOV     04h, TCON
36  
37          ;;  Second test: overflow
38  	MOV	TL0,#0F0h        ; Set initial value of timer0
39  	MOV	TL1,#0EFh        ; Set initial value of timer1
40          LCALL   DELAY
41  
42          LJMP    0FFF0h
43  
44          ;; Loop of ~25 cycles
45  DELAY:
46  	MOV	B,#10
47         	ORL     TCON,#50h	; Timer 0 and timer 1 ON.
48  B1:
49  	DJNZ	B,B1
50          ANL     TCON,#0AFh      ; Stop both timers
51          RET
52  
53          END