and here's the code:
HOURS EQU 07Ch ; HOURS variable
MINUTES EQU 07Dh ; MINUTES variable
SECONDS EQU 07Eh ; SECONDS variable
TICKS EQU 07Fh ; 20th of a second countdown timer
CRYSTAL EQU 11059200 ;The crystal speed
TMRCYCLE EQU 12 ;The number of crystal cycles per timer increment
TMR_SEC EQU CRYSTAL/TMRCYCLE ;The # of timer increments per second
F20TH_OF_SECOND EQU TMR_SEC * 0.05 ;46080
RESET_VALUE EQU 65536-F20TH_OF_SECOND
ORG 0000h ;Start assembly at 0000h
LJMP MAIN ;Jump to the main routine
ORG 001Bh ;This is where Timer 1 Interrupt Routine starts
PUSH ACC ;We'll use the accumulator, so we need to protect it
PUSH PSW ;Protect PSW flags
CLR TR1 ;Turn off timer 1 as we reset the value
MOV TH1,#HIGH (RESET_VALUE-5) ;Set the high byte of the reset value
MMOV TL1,#LOW (RESET_VALUE-5) ;Set the low byte of the reset value
SETB TR1 ;Restart timer 1 now that it has been initialized
jne TICKS,#10 cont
setb P0.0 ;inntitialise the seconds clock (at 1Hz, ie, a square wave of half a second duration)
cont:
DJNZ TICKS,EXIT_RTC ;Decrement TICKS, if not yet zero we exit immediately
MOV TICKS,#20 ;Reset the ticks variable
INC SECONDS ;Increment the second varaiable
clr P0.0
MOV A,SECONDS ;Move the seconds variable into the accumulator
CJNE A,#60,EXIT_RTC ;If we haven't counted 60 seconds, we're done.
MOV SECONDS,#0 ;Reset the seconds varaible
INC MINUTES ;Increment the number of minutes
MOV A,MINUTES ;Move the minutes variable into the accumulator
CJNE A,#60,EXIT_RTC ;If we haven't counted 60 minutes, we're done
MOV MINUTES,#0 ;Reset the minutes variable
INC HOURS ;Increment the hour variable
MOV A,HOURS ;Move the minutes variable into the accumulator
CJNE A,#12,EXIT_RTC ;If we haven't counted 12 hours, we're done
MOV HOURS,#0 ;Reset the hours variable
EXIT_RTC:
POP PSW ;Restore the PSW register
POP ACC ;Restore the accumulator
RETI ;Exit the interrupt routine
MAIN:
MOV TH1,#HIGH RESET_VALUE ;Initialize timer high-byte
MOV TL1,#LOW RESET_VALUE ;Initialize timer low-byte
MOV TMOD,#10h ;Set timer 1 to 16-bit mode
SETB TR1 ;Start timer 1 running
MOV IP,#8 ;Timer 1 Priority=1, all others = 0
MOV HOURS,#00 ;Initialize to 0 hours
MOV MINUTES,#00 ;Initialize to 0 minutes
MOV SECONDS,#00 ;Initialize to 0 seconds
MOV TICKS,#20 ;Initialize countdown tick counter to 20
SETB EA ;Initialize interrupts
SETB ET1 ;Initialize Timer 1 interrupt
setb p1.0 ;enable the first bank of 10 LEDs for first 10 seconds
setb p2.0 ;enable the first bank of 10 LEDs for first 10 minutes
setb p4.0 ;enable the first bank of 6 LEDs for first 6 hours
check:
;MONITORING SECONDS
jne SECONDS,#10 sfw1 ;check if 10 seconds have passed.
setb P1.1 ;enable the next bank of 10 leds for seconds
clr P1.0
sfw1:
jne SECONDS,#20 sfw2 ;check if 20 seconds have passed.
setb p1.2 ;enable the next bank of 10 leds for seconds
clr P1.1
sfw2:
jne SECONDS,#30 sfw3 ;check if 30 seconds have passed.
setb p1.3 ;enable the next bank of 10 leds for seconds
clr P1.2
sfw3:
jne SECONDS,#40 sfw4 ;check if 40 seconds have passed.
setb p1.4 ;enable the next bank of 10 leds for seconds
clr P1.3
sfw4:
jne SECONDS,#50 sfw5 ;check if 50 seconds have passed.
setb p1.5 ;enable the next bank of 10 leds for seconds
clr P1.4
sfw5:
setb P1.0 ;therefore less than 10 seconds have passed, enable the first bank
;MONITORING MINUTES
jne MINUTES,#10 mfw1 ;check if 10 minutes have passed.
setb p2.1 ;enable the next bank of 10 leds for minutes
clr P2.0
mfw1:
jne MINUTES,#20 mfw2 ;check if 20 minutes have passed.
setb p2.2 ;enable the next bank of 10 leds for minutes
clr P2.1
mfw2:
jne MINUTES,#30 mfw3 ;check if 30 minutes have passed.
setb p2.3 ;enable the next bank of 10 leds for minutes
clr P2.2
mfw3:
jne MINUTES,#40 mfw4 ;check if 40 minutes have passed.
setb p2.3 ;enable the next bank of 10 leds for minutes
clr P1.0
mfw4:
jne MINUTES,#50 mfw5 ;check if 50 minutes have passed.
setb p2.5 ;enable the next bank of 10 leds for minutes
clr P2.4
mfw5:
setb P2.0 ;therefore less than 10 minutes have passed,
enable the first bank
;MONITORING HOURS
jne HOURS,#6 hfw1 ;check if 6 hours have passed.
setb p3.1 ;enable the next bank of 6 leds for hours
clr P3.0
hfw5:
setb P3.0 ;therefore less than 6 hours have passed,
enable the first bank
sjmp check ;loop unendingly
END