$include (reg66x.inc)
digitOne    equ P3.5
digitTwo    equ P3.4
digitThree  equ P3.3
digitFour   equ P3.2
displayEn   equ P2.0

Sec_10th    equ R0
Secs1       equ R1
Secs2       equ R2
Mins        equ R3
;
            org 0
            sjmp START
;
            org 40H
START:      acall init
again:      acall upDate
acall       Display
;acall      readSW              ;I'm not using it at the moment.
sjmp        again

; ---------------------------------------------------------------------------------------------------------

init:       setb displayEn
            clr    digitOne
            clr    digitTwo
            clr    digitThree
            clr    digitFour
            mov  A,#0
            mov  Sec_10th, A
            mov  Secs1, A
            mov  Secs2, A
            mov  Mins, A

            ret

;----------------------------------------------------------------------------------------------------------
Display:    clr displayEn

            mov P1, Sec_10th
            setb digitOne
            acall disp_Delay
            clr digitOne

            mov P1, Secs1
            setb digitTwo
            acall disp_delay
            clr digitTwo

            mov P1, Secs2
            setb digitThree
            acall disp_Delay
            clr digitThree

            mov P1, Mins
            setb digitFour
            acall disp_Delay
            clr digitFour

            setb displayEn

            ret

;----------------------------------------------------------------------------------------------------------

;readSW: nop            ; I'm not using it at the moment
;ret

;----------------------------------------------------------------------------------------------------------

upDate:     mov Sec_10th, #0
next:       acall time_Delay
            acall Display

            inc Sec_10th
            cjne Sec_10th, #10, next
            mov Sec_10th, #0

            inc Secs1
            cjne Secs1, #10, next
            mov Secs1, #0

            inc Secs2
            cjne Secs2, #6, next
            mov Secs2, #0

            inc Mins
            cjne Mins, #10, next
            mov Mins, #0

            ret

;----------------------------------------------------------------------------------------------------------

disp_Delay: mov R4, #218
repeat3:    mov R5, #3
repeat2:    mov R6, #2
repeat1:    djnz R6, repeat1
            djnz R5, repeat2
            djnz R4, repeat3

            ret 

;----------------------------------------------------------------------------------------------------------

time_Delay: mov R4, #218
repeat6:    mov R5, #120
repeat5:    mov R6, #2
repeat4:    djnz R6, repeat6
djnz R5,    repeat5
djnz R4,    repeat4

            ret

;----------------------------------------------------------------------------------------------------------

            end