/ tests / timer0.asm
timer0.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 = $83
 7  ; Test output: R1 = $17
 8  ; Test output: R2 = $81
 9  ; Test output: R3 = $02
10  ; Test output: TIMER0 = $7103
11  ; Test output: TIMER1 = $8005
12  ; Test output: TCON = $A0
13  ; Test output: TMOD = $00
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,#00h       ; Init timers 0 and 1 as:
22                                  ;   8-bit timer "TH" with "TL" as 5-bit prescaler
23                                  ; incremented by the internal clock
24  
25          ;;  First test: no overflow
26  	MOV	TH0,#2
27  	MOV	TL0,#55h        ; Set initial value of timer0 to $0255
28          LCALL   DELAY
29  
30          MOV     00h, TH0         ; Save value of timer 0
31          MOV     01h, TL0
32          MOV     02h, TH1         ; Save value of timer 1
33          MOV     03h, TL1
34          MOV     04h, TCON
35  
36          ;;  Second test: overflow
37  	MOV	TH0,#0F0h
38  	MOV	TL0,#01h        ; Set initial value of timer0 to $F001
39  	MOV	Th1,#0FFh
40  	MOV	TL1,#03h        ; Set initial value of timer1 to $FF03
41          LCALL   DELAY
42  
43          LJMP    0FFF0h
44  
45          ;; Loop of $1020 cycles
46  DELAY:
47  	MOV	A,#08h
48         	ORL     TCON,#50h	; Timer 0 and timer 1 ON.
49  B2:
50  	MOV	B,#0
51  B1:
52  	DJNZ	B,B1
53  	DJNZ	ACC,B2
54          ANL     TCON,#0AFh      ; Stop both timers
55          RET
56  
57          END