!"##$%&'(&)*+,+%-&.*$-*/01(&$%2$/*3&-.+$ !"#$%&'($)* +,! -&./01234/534$136/1)78&534$1/4'($4)1874176"734/19:;! <,! =4'&$131>47?43@1&23&1'6&$483%$)19:;! A,! B4351-&3&$1C436)'&'761B'3?43@ C2$1DEF+-GH1>47('/$)1316.@"$41781;I!1/$('%$)18741$3)01J$346'6?,1=$1%36154'&$1&2$ /4'($418741&2$)$1/$('%$)15'&213))$@"J01%7/$,1C2')1J$))761)275)12751&7154'&$1&2$1/4'($4 874176"734/19;:!,1=4'&'6?1&2$1;I!1/4'($4)K15$1@.)&1L6751/$&3'J)1781234/534$ "$874$236/, -.+$4 9;:!1)&36/)187419$6$43J1:.4>7)$1;6>.&1!.&>.&,1C2$1@7)&1%7@@761)>$%'8'%3&'761781).%2 9:;!1')1)'@>J$1/'?'&3J1'6>.&136/17.&>.&1>74&,1C2$1DEF+-GH123)1&571>74&)*1DM"'&1'6>.&1>74& 36/1DM"'&17.&>.&1>74&,1C2$1J7%3&'76)1781"7&21>74&)134$1@3>>$/1'6&71$N&$463J1/3&31@$@740 5'&213//4$))1"$J75* 9:;!+ 9:;!<
DM"'&1!OC:OC1:!PC DM"'&1;R:OC1:!PC
S$&1.)1)$$1&2$1234/534$187419:;!+,
+EEQ <EEQ
9:;!+1')1".'J&15'&21DM"'&1B1&0>$1TJ'>MTJ7>K1UVQHFUA,1C2$1'6>.&1)'?63J)134$1&'$/1&71DEF+W) /3&31".)K1BEMBU,1C2$1SXK1S3&%21X63"J$1)'?63J13%&'($)152$6154'&'6?1&71&2$1$N&$463J1/3&3 @$@74013&13//4$))1+EEQ,1C2$1DM"'&17.&>.&1)'?63J)134$1&$4@'63&$/13&1YV12$3/$4,
:'6+1781&2$12$3/$41YV123)1)Z.34$1>3/K15$1@301)$$1&2$1"7&&7@1>%"1&718'6/1'&, !"#$%&'( C7154'&$131"0&$1&719:;!+K15$1%361.)$1"$J751%7/$K mov a,#10101010b mov dptr,#100h movx @dptr,a =$1%361&$)&1&2$17.&>.&1J7?'%13>>$34$/13&1YV12$3/$41.)'6?1/7&1SXB1)$4'$)15'&21AAE!2@) %.44$6&1J'@'&'6?14$)')&$4,1T741)'6?J$1"'&K15$1%361.)$1J7?'%1>47"$1&71&$)&1'&13J)7,
"5"*6+#"&'74( +,!
=4'&$131>47?43@1&23&1)2'8&)131"'&1847@14'?2&M&7MJ$8&,1X3%21"'&15'JJ1"$1)2'8&$/1$($40 +EE@),
<,!
-'@'J34J018741+K16751)2'8&1'&1"3%L136/1874&21847@14'?2&M&7MJ$8&136/1J$8&M&7M4'?2&1&2$ )3@$1)>$$/,
Q'6&*1.)$1+E@)1&'@$"3)$136/1PP136/1PS1'6)&4.%&'76),
-.+$1 9:;!<1')1DM"'&1'6>.&1>74&K1".'J&15'&21AM)&3&$1DM"'&1".88$4K1UVQH
B;REMB;RU13%%$>&)1CCS1%7@>3&'"J$1J7?'%1)'?63J,1B;RE1&71B;RA134$1&'$/1&71B;:1)5'&%2K -=+18741)0)&$@1)$&&'6?,1=2$61$3%21)5'&%2153)1%J7)$/K1&2$1J7?'%1'6>.&15'JJ1"$1[EW,1C2$ DEF+-GH1.)$)1>7)'&'761+18741"77&1J73/$418$3&.4$,1:7)'&'76+123)131/7&1'6/'%3&74,
B;RV1&71B;RU134$1&'$/1&71.)$41L$0>3/K1-A1&71-\,1=$1%361$N>$4'@$6&15'&21&2$)$1>.)2 ".&&76),
S3
S4
S5
S6
INT0
RESET
]JJ1'6>.&1"'&)134$1>.JJM.>15'&21V,UL1&71@3L$1J7?'%1'6>.&18741H^!-1%'4%.'&1&71"$1[+W152$6 3JJ1)5'&%2$)134$1!:XR1%'4%.'&,
C2$1J7%3&'7617819:;!<1')13&13//4$))1<EEQ, !"#$%&'( C714$3/1DM"'&1/3&31847@19:;!
=4'&$131>47?43@1&23&14$3/)1DM"'&1/3&3136/1>4'6&)1'&1761)%4$$61'61"'63401874@3&, ++++1++++ =2$61>4$))131?'($61L$0176"734/K1&2$1(3J.$1)27.J/1)2751[EW,
"5"*6+#"&'78( +,!
]//1&3)L1"$J751&71&2$1@3'61J77>1781/'?'&3J1%J7%L1>47?43@1847@1S$))761\, ]))$@"J$1&2$1>47?43@136/1&$)&14.6,1=23&123>>$6152$615$1>4$))1-\1L$0_
;----------- read key S6 every 10ms ---------read_s6:
mov dptr,#gpio2 movx a,@dptr jb acc.7, exit_read_s6 setb flag1.7 ; to tell next task ; that S6 has been pressed ret
exit_read_s6: clr flag1.7 ret ;----------- service key S6 ----------------execute_s6: jnb flag1.7,exit_execute_s6 mov command,#'m' call adjust_min exit_execute_s6: ret
;-------- main loop running -------------main: call wait_tick call update_clock call LED_on call LED_off call print_time call get_command call adjust_min call adjust_hour ; read S6 push button call read_s6 call execute_s6 jmp main =$1)$$1&23&1-\1L$0153)14$3/1$($401+E@)1"01&3)L14$3/1-\,1]6/1'&15'JJ1@3L$1@'6.&$1&71"$ .>/3&$/1$($401+E@), Q751%3615$1)&7>14$3/'6?1-\136/14$>$3&1$N$%.&'6?1.>/3&$1@'6.&$152'J$1-\123)1"$$6 >4$))$/_
=$15'JJ16$$/1@74$1"'&1&71)&7>14$>$3&'6?1)$4('%$1L$01-\,1R751J$&1.)$1)$$1316$5 @7/'8'%3&'761%7/$, ;----------- read key S6 every 10ms ---------read_s6:
mov dptr,#gpio2 movx a,@dptr jb acc.7, exit_read_s6 setb flag1.7 ; to tell next task ; that S6 has been pressed ret
exit_read_s6: clr flag1.7 clr flag1.6 ret ;----------- service key S6 ----------------execute_s6: jnb flag1.7,exit_execute_s6 jnb flag1.6,just_pressed ret just_pressed: setb flag1.6 ;to tell execute_s6 has been executed mov command,#'m' call adjust_min exit_execute_s6: ret "5"*6+#"&'79( +,! ^7/'8013"7($1&3)L)15'&218J3?+,\13//'6?,1]))$@"J$1&2$1%7/$136/1&$)&14.6K16751J$& >4$))1-\13?3'6,1=23&1/7$)1@'6.&$1'6%4$@$6&'6?1J77L1J'L$_
clear bit flag1.7 clear bit flag1.6
S6 = 0
S6 = 1
Set bit flag1.7
Read S6 key
TF0 = 1 Execute S6 Flag1.7 = 1 and flag1.6 = 0 Adjust minute set bit flag1.6
Flag1.7=0
Flag1.7 = 1 and flag1.6 = 1
Wait tick
=$1%361J$3461@74$1$3)'J015'&213"7($1)&3&$1&436)'&'761/'3?43@,1C2$1&3)L)134$1)2756176J0 &24$$1&3)L),1C2$13%&.3J1@3'61J77>123)13"7.&1+E1&3)L), "5"*6+#"&'7:( +,! ]//1@74$1L$0)1874127.413/#.)&'6?15'&21-F1L$0, <,! B435131)&3&$1&436)'&'761/'3?43@,
#;<=>?&@AB?&CAD&"E?D@FG?&'74 $mod51 $include(mypaulm2.equ) gpio1 gpio2
equ 100h equ 200h
dseg at 20h flag1:
ds 1
dseg at 50h tick: ds 1 counter1: ds 1 timer3: ds 1 temp: ds 1 cseg at 8000h jmp start org 8100h ;---- initialization code ---------------start: orl tmod,#1 ; set timer0 to mode1 setb tr0 mov flag1,#1 mov counter1,#0 mov temp,#1 mov timer3,#0 ;-------- main loop running -------------main: call wait_tick call shift_left call shift_right jmp main ;------- subroutines ---------------------wait_tick: jnb tf0,$ clr tf0 orl th0,#0dch ret shift_left: jnb flag1.0,exit_left inc timer3 mov a,timer3 cjne a,#10,exit_left
mov timer3,#0 mov a,temp mov dptr,#100h movx @dptr,a rl a mov temp,a inc counter1 mov a,counter1 cjne a,#7,exit_left mov counter1,#0 setb flag1.1 clr flag1.0
exit_left: ret shift_right: jnb flag1.1,exit_right inc timer3 mov a,timer3 cjne a,#10,exit_right mov timer3,#0 mov a,temp mov dptr,#100h movx @dptr,a rr a mov temp,a inc counter1 mov a,counter1 cjne a,#7,exit_right mov counter1,#0 setb flag1.0 clr flag1.1 exit_right: ret end