;====================================================================
;
; Author        : ADI - Apps
;
; Date          : December 1999
;
; File          : Tim2_AR.asm
;
; Hardware      : ADuC816
;
; Description   : Flashes light every 256*128 machine cycles (@ 4Hz
;                 for core freq = 1.573MHz) using timer 2 in Auto 
;                 Reload Mode. 
;____________________________________________________________________
$MOD52                                   ;Use 8052 predefined Symbols

LED	EQU	P3.4

;____________________________________________________________________
                                                  ; BEGINNING OF CODE
CSEG
ORG 0000H

	JMP MAIN
;____________________________________________________________________
                                          ; TIMER 2 INTERRUPT ROUTINE
ORG 002Bh

        CPL     LED        ; Flash the light
        CLR     TF2        ; The TF2 flag must be cleared in software
        RETI


;____________________________________________________________________
                                                       ; MAIN PROGRAM
ORG 0060h                    ; Start code at address above interrupts			

MAIN:                        ; Main program

        SETB     ET2         ; Enable timer2 interrupt

        MOV      TL2, #00h    ; Initialise timer 2 registers & Reload 
        MOV      TH2, #80h    ; values to rollover every 128*256
        MOV      RCAP2L, #00h ; machine cycles (7.63us)
        MOV      RCAP2H, #80h

        SETB     EA          ; Enable interrupts

        SETB     TR2         ; Start timer 2 in 16-bit reload mode

        JMP      $           ; Wait here for timer Interrupts

END
