!"##$%&'(&)*+,+%-&.*$-*/01(&2!$23&.*$-*/0 !"#$%&'($)* +,! -.'&'/012'0'&341%45%617.50.38, 9,! 1:&;2<1'/&$./341&'8$., =>$14$))5/1?'441)>5?1>5?1&51?.'&$1&>$17.50.381&>3&12')743<)1&'8$15/1&$.8'/341)%.$$/,1=>$ '/&$./341&'8$.1?'441"$1;)$21&517.52;%$1+@8)1&'%6,1=>$1%5;/&'/01A5.1)$%5/2B18'/;&$13/2 >5;.1?'441&>$/1"$1318;4&'74$15A1+@8), C$&1;)1A5.8;43&$1?>3&1')1&>$1'2$315A1>5?1&51836$12'0'&341%45%61;)'/01D@E+:FG13/2 &$.8'/34, +,! -$1?'441>3($1D@E+:FG1)$/2)1&'8$1&51&$.8'/341$($.<1)$%5/2, 2.!=>$12')743<1)>5;421)>5?B117:55:59 H,! I.$))'/016$<1J8K1?'441'/%.$8$/&18'/;&$13/216$<1J>K1?'441'/%.$8$/&1>5;., L,! !/"53.21CMN1)>5;421"4'/61$($.<1)$%5/2, "4"*2+#"&'51( +,
M2'&13/213))$8"4$17.50.381"$45?B1.;/1?'&>1%5883/21#;87,
$mod51 $include(mypaulm2.equ) led cr
equ P1.7 equ 13 dseg at 20h
flag1:
ds 1
dseg at 50h tick: ds 1 sec100: ds 1 sec: ds 1 min: ds 1 hour: ds 1 timer3: ds 1 cseg at 8000h jmp start org 8100h
;---- initialization code ---------------start: orl tmod,#1 ; set timer0 to mode1 setb tr0 mov flag1,#0 mov sec,#0 mov min,#59h mov hour,#17h ;-------- main loop running -------------main: call wait_tick call update_clock call LED_on call LED_off call print_time jmp main ;------- subroutines ---------------------wait_tick: jnb tf0,$ clr tf0 orl th0,#0dch ret ; blink LED every second blink_led: inc tick mov a,tick cjne a,#50,exit1 mov tick,#0 cpl led exit1: ret update_clock: inc sec100 mov a,sec100 cjne a,#100,exit2 mov sec100,#0 setb flag1.0 setb flag1.1 mov a,sec add a,#1 da a mov sec,a
cjne a,#60h,exit2 mov sec,#0 mov a,min add a,#1 da a mov min,a cjne a,#60h,exit2 mov min,#0 mov a,hour add a,#1 da a mov hour,a cjne a,#24h,exit2 mov hour,#0 exit2: ret print_time: jnb flag1.0,exit_print_time clr flag1.0 print_time1: mov a,#cr call cout mov a,hour call phex mov a,#':' call cout mov a,min call phex mov a,#':' call cout mov a,sec call phex exit_print_time: ret LED_on: jnb flag1.1,exit_LED_on clr flag1.1 setb flag1.2 clr LED
exit_LED_on: ret LED_off: jnb flag1.2,exit_LED_off inc timer3 mov a,timer3 cjne a,#5,exit_LED_off mov timer3,#0 clr flag1.2 setb LED exit_LED_off: ret
end O5?1?$1?'441)$$1&>$1A;/%&'5/1A5.1$3%>175.&'5/15A1&>$17.50.38,1P'.)&1)$73.3&$1&>$1?>54$ 7.50.381'/&51A5;.1"45%6), Variable and constant declaration Initialization Main body Subroutines
67897:;<&7=>&?@=AB7=B&>;787B9@= C$&1;)1455613&1(3.'3"4$)13/21%5/)&3/&)12$%43.3&'5/ led cr
equ P1.7 equ 13 dseg at 20h
flag1:
ds 1
dseg at 50h tick: ds 1 sec100: ds 1 sec: ds 1 min: ds 1
hour: ds 1 timer3: ds 1
CMN1.$7.$)$/&)175.&1I+,Q13/21GR1.$7.$)$/&)1S:GTT1%52$1+H15.1@NU, P430+1')12$%43.$213&1"'&1322.$))3"4$145%3&'5/19@U,1-$1%3/13%%$))1&>$1"'&145%3&'5/1"< A430+,@B1A430+,+B1A430+,9B1)3<,1-$1;)$1310'($/1"'&1'/1A4301A5.1)'0/34'/01385/01&3)6), =>$1.$)&1(3.'3"4$)1&'%6B1)$%+@@B1)$%B18'/B1>5;.B13/21&'8$.H13.$12$%43.$213)1&>$1"<&$ (3.'3"4$145%3&$21A.581322.$))1E@U, !"#$%&'( +,
-.'&$125?/1&>$1322.$))1A5.1$3%>1(3.'3"4$,
+=9B97;9C7B9@= S&1)&3.&1%52$B1&>')175.&'5/1?'441.;/15/4<15/$1&'8$13A&$.1?$1#;871A.58185/'&5.17.50.38, =>$1%52$1?'441)$&13/2145321&>$1'/'&'341(34;$1&51&>$1(3.'3"4$13/21>3.2?3.$1.$0')&$.), ;---- initialization code ---------------start: orl tmod,#1 ; set timer0 to mode1 setb tr0 mov flag1,#0 mov sec,#0 mov min,#59h mov hour,#17h !"#$%&'( +,!
->3&13.$1=V!N13/21=R@W
079=&D@>E =>$183'/1"52<15A1&>$17.50.381')1)'874$1.$7$3&1.;//'/01&3)6)1'/1A5.$($.14557, ;-------- main loop running -------------main: call wait_tick call update_clock call LED_on call LED_off call print_time jmp main
=>$1%5/%$7&1')1&>$1)38$13)12$)%.'"$21'/14$))5/1E,1-$1;)$1&'8$.1&51A5.%$1$3%>1&3)61&5 $X$%;&$1$($.<1+@8)1&'%6,1U5?$($.1?$1%3/1/5&1>3($13441&3)6)1)&3.&1.;//'/013&1&>$1)38$ &'8$B1)'/%$1?$1>3($15/4<15/$1GIY,1-$1&>$/10'($131)>5.&17$.'5215A1&'8$1A5.1$3%>1&3)6 $X$%;&'5/,1R$%3441&>$1&3)61.;//'/012'30.381303'/B1?$1)$$1/5?1?$1>3($1A'($1&3)6)1'/1&>$ +@8)14557, TF0=1
TF0=1
10ms
TF0=1
10ms
TF0=1
10ms
TASK1 TASK2
-$1%3/1)3<1&>3&1$3%>1&3)61?'441.$7$3&1$X$%;&'5/1$($.<1+@8),1:51&>$1A;/%&'5/1&>3&1.$Z;'.$) &'8$1%5/&.541%3/1;)$1+@8)1&'%61&51%5;/&,1-$1)$$1&>3&1&>$1+@8)1&'%61')131%.'&'%341&'8$1$($/&B )51?$1%3/1/5&1>3($1&3)61&>3&1.;/)1A5.$($.14557,1=>$1)54;&'5/1&514$&1&3)61)&3.&1$X$%;&'5/1') &51;)$1A4301)'0/34'/0,1-$1?'441)$$1>5?1&51;)$1A4301&51A5.%$1310'($/1&3)61&51)&3.&1$X$%;&'5/ 5/143&$., O5?14$&1;)1)&;2<1&>$12$&3'4)15A1&>$1);".5;&'/$), wait_tick wait_tick: jnb tf0,$ clr tf0 orl th0,#0dch ret ='8$@1')1)$&1&51+[\"'&1%5;/&$.,1=>$1.$4532$21%5;/&1NG@@U1?'441)$&1&'8$.1A430B1=P@1$($.< +@8),1->$/1)$&B1&>$1%52$1%4$3.)1'&13/21.$4532)1NG@@1&51='8$.@,1=>')1)7$%'341&3)61?'44 $X'&1?>$/1=P@1')1)$&17.5('2'/01"$0'/15A1$X$%;&'5/1&>$1A5445?'/01&3)6), Update_clock update_clock: inc sec100 mov a,sec100 cjne a,#100,exit2 mov sec100,#0 setb flag1.0 setb flag1.1
mov a,sec add a,#1 da a mov sec,a cjne a,#60h,exit2 mov sec,#0 mov a,min add a,#1 da a mov min,a cjne a,#60h,exit2 mov min,#0 mov a,hour add a,#1 da a mov hour,a cjne a,#24h,exit2 mov hour,#0 exit2: ret =>')1&3)61;723&$)1%;..$/&1&'8$1"<1>3('/01)$%+@@1&51%5;/&1+@@1&'8$)1A5.1+@@X+@8)15.15/$ )$%5/2, ->$/1)$%+@@1')1$Z;341+@@B1&>$1)$%1(3.'3"4$1?'441'/%.$8$/&1"<1322'/01&51+,1=>$1)$% (3.'3"4$1')1FGN1/;8"$.,1->$/1)$%1(3.'3"4$1')1$Z;341[@UB1'&1?3)1%4$3.$21&51@13/218'/;&$ ?3)1'/%.$8$/&$2, mov a,sec add a,#1 da a mov sec,a cjne a,#60h,exit2 mov sec,#0 P430+,@13/21P430+,+13.$1)$&1$($.<15/$\)$%5/2,1P430+,@1)'0/34)17.'/&]&'8$,1P430+,+1)'0/34) CMN]5/, setb flag1.0 setb flag1.1
LED_on LED_on: jnb flag1.1,exit_LED_on clr flag1.1 setb flag1.2 clr LED exit_LED_on: ret =>$1A;/%&'5/1CMN]5/1?'441$X$%;&$15/4<1'A1P430+,+1')1)$&,1TA1P430+,+1')1^$.5B1'&1?'441$X'&, TA1P430+,+1)$&)B1'&1?'441"$1%4$3.$2,1P430+,91?'441"$1)$&1A5.1CMN]5AA1A;/%&'5/B13/21&>$1CMN ?'441&;./15/, LED_off LED_off: jnb flag1.2,exit_LED_off inc timer3 mov a,timer3 cjne a,#5,exit_LED_off mov timer3,#0 clr flag1.2 setb LED exit_LED_off: ret =>$1A;/%&'5/1CMN]5AA1?'441.;/15/4<1'A1P430+,91')1)$&,1->$/1P430+,91)$&B1&'8$.H1') '/%.$8$/&$21;/&'41E1&'%6)B1'&1?'441"$1%4$3.$213/215/"53.21CMN1?'441&;./15AA, :51?'&>1&>')18$&>52B1&>$1CMN1?'441A43)>1$($.<1)$%5/21?'&>1&'8$15/17$.'521$Z;341E@8)_ print_time print_time: jnb flag1.0,exit_print_time clr flag1.0 mov a,#cr call cout mov a,hour call phex
mov a,#':' call cout mov a,min call phex mov a,#':' call cout mov a,sec call phex exit_print_time: ret =>')1A;/%&'5/17.'/&)1%;..$/&1&'8$1&51&$.8'/341$($.<15/$1)$%5/2,1=>$17.'/&'/01?3)1)'0/34$2 "<1P430+,@, "4"*2+#"&'5F( +,!
V52'A<1&>$1%52$1&517.'/&1NS=M\V!O=U\`MSR,
O5?1);775)$1?$1?3/&1&51;)$1IG16$<"53.21&5132#;)&1&'8$,1C$&13221&>$1A;/%&'5/1&>3&1.$32) %>3.3%&$.1A.581)$.'34175.&1?'&>5;&1A5.$($.145571'/)'2$,1R$8$8"$.1'A1?$1;)$1%'/1A;/%&'5/B '&1?'441?3'&1;/&'41:FYP1>3)1.$%$'($21S:GTT1%>3.3%&$., cin: jnb ri,$ ; this line will wait until RI = 1 clr ri mov a,sbuf ret "4"*2+#"&'5G( +,
S221"$45?1);".5;&'/$)1&51&>$183'/17.50.38,
get_command: jnb ri,exit_get_command clr ri mov a,sbuf mov command,a ret exit_get_command: mov command,#-1 ret adjust_min: mov a,command cjne a,#'m',exit_adjust_min mov a,min add a,#1
adjust1:
da a mov min,a cjne a,#60h,adjust1 mov min,#0 call print_time1 ret
exit_adjust_min: ret adjust_hour: mov a,command cjne a,#'h',exit_adjust_hour mov a,hour add a,#1 da a mov hour,a cjne a,#24h,adjust2 mov hour,#0 adjust2: call print_time1 ret exit_adjust_hour: ret
9,
S221&>$1%3441'/)&.;%&'5/1&51&>$)$1&3)6)134)5,
;-------- 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 jmp main H, S))$8"4$13/21&$)&1.;/1&>$17.50.38B1IRM::16$<1a8b13/21a>bB1)$$1?>3&1>377$/15/ )%.$$/, L,
V52'A<1&>$1%52$1&51;)$16$<1:ISGMFSR1&51.$)$&1)$%5/21&51^$.5,