
;                             FILE TIMER2.ASM
;
;              Sample Program Demonstrating Setup and Use of
;              Timers 0 and 1 Using MODE 2. This Program
;              switches Port 1.0 and 1.1 using Timers 0 and 1
;              Timers 0 and 1 are operated in Mode 2.
;
;            NOTE: Mode 2 is an 8 Bit/Auto Reload Timer Mode.
;
;                     Written By S.C.T.  1/20/2000


  $MOD52                        ; Include 8052 Definitions

  Timer0Count   EQU     20h     ; Setup Timer Parameters
  Timer1Count   EQU     80h     

  ORG  4000h                    ; Start Program at SDK Code Space Base

  CLR   EA                      ; Disable Global Interrupts
  MOV   TMOD, #22h              ; Set Timers 0 and 1 to Mode 2

  MOV   TL0, #Timer0Count       ; Load Timers 0 and 1
  MOV   TH0, #Timer0Count
  MOV   TL1, #Timer1Count
  MOV   TH1, #Timer1Count

  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:
  CPL   P1.0                    ; Complement Output Bit
  CLR   TF0                     ; Clear Timer 0 Overflow
  JMP   loop1                   ; Go back to main loop

restart1:
  CPL   P1.1                    ; Complement Output Bit
  CLR   TF1                     ; Clear Timer 1 Overflow
  JMP   loop1                   ; Go back to main loop

  END
