
;                             FILE TIMER1.ASM
;
;              Sample Program Demonstrating Setup and Use of
;              Timers 0 and 1 Using MODES 1 and 2. This Program
;              switches Port 1.0 and 1.1 using Timers 0 and 1
;              Timer 0 is operated in Mode 1 and Timer 1 in Mode 2.
;
;         NOTE: Timer Mode 1 is a 16 bit mode and Mode 2 is 8 bit.
;
;                     Written By S.C.T.  1/20/2000


  $MOD52                        ; Include 8052 Definitions

  TimerLow     EQU     50h      ; Setup Timer Parameters
  TimerHigh    EQU     50h

  ORG  4000h                    ; Start Program at SDK Code Space Base

  CLR   EA                      ; Disable Global Interrupts
  MOV   TMOD, #21h              ; Set Timers 0 and 1 to Modes 1 and 2

  MOV   TL0, #TimerLow          ; Load Timers 0 and 1
  MOV   TH0, #TimerHigh
  MOV   TL1, #TimerLow
  MOV   TH1, #TimerHigh

  CLR   TF0                     ; Clear Timer 0 Overflow flag
  CLR   TF1                     ; Clear Timer 1 Overflow flag
  CLR   P1.0                    ; Clear Output Signal Ports
  CLR   P1.1                    

  SETB  TR0                     ; Start Timer 0
  SETB  TR1                     ; Start Timer 1

loop1:
  JB    TF0,restart0            ; Go to Timer 0 Restart Routine
  JB    TF1,restart1            ; Go to Timer 1 Restart Routine
  JMP   loop1                   ; repeat loop until bit set

restart0:
  CLR   TR0                     ; Stop Timer 0
  CPL   P1.0                    ; Complement Output Bit
  CLR   TF0                     ; Clear Timer 0 Overflow
  MOV   TL0, #TimerLow          ; Reload Timer 0 
  MOV   TH0, #TimerHigh
  SETB  TR0                     ; Restart Timer 0
  JMP   loop1                   ; Go back to main loop

restart1:
  CPL   P1.1                    ; Complement Output Bit
  JMP   loop1                   ; Go back to main loop

  END
