Bài giảng Giao tiếp ứng dụng vi điều khiển

GIAO TIẾP ỨNG DỤNG VI ĐIỀU KHIỂN                                      ! "# $%&'()* * * *  +    ,-  -  -  -   &#.(,/*  *  *  *  ! "# $% &#.(,/*   *   *   *   &#).(,/*   *   *   *  ( " #

pdf68 trang | Chia sẻ: huongnhu95 | Lượt xem: 435 | Lượt tải: 0download
Tóm tắt tài liệu Bài giảng Giao tiếp ứng dụng vi điều khiển, để xem tài liệu hoàn chỉnh bạn click vào nút DOWNLOAD ở trên
$%&'()* &#0.(,/**   **   **   *             12"+ 131   2  2  2  +   345 163  5  5  5            "7078     +   ",78     9   "7070                4 :     +   5" ;< "  5   5   5          1 5=" 5 5 5  + > ????"1@"=A"@ A@ A@ A  9 > ?3-"1   ?=B1 C "? - ? C ? - ? C ? - ? C   D "" 51 ?=B1 C" 5 ? C 5 ? C 5 ? C  E <=? ?=B1 C"? ? C? ? C? ? C  F "1< 4G1 ?=B1 C"=H ? C H? C H? C H  ?=B1 C? C? C? C            1 5= 345 5 5 5 5 5 5  + " =- H 1<  1  ?=B1 C 345 - H  ? C 5 - H  ? C 5 - H  ? C 5  "# , ()* &/)IJ  *  J  *  J  *  J   > B +D0  KL.ML L L  9 "1< 4G1 ?=B1 C 345? C 5? C 5? C 5          1 5=4 3  5 5 5  + ""1@> "=A4 3  @ A @ A @ A >+00, 9 > ?"1@ H"1+00,@ A@ A@ A  D 1-5"=A4 3 B13 =? HB1"  5- 5 A ? H 5- 5 A ? H 5- 5 A ? H 5  E 1-5"=A""111 ?=B1 C- 5 A  ? C- 5 A  ? C- 5 A  ? C  F 3-"1   ?=B1 C 4 - ? C - ? C - ? C  O3  , "1< 4G1B1 A-4 3 A -A -A -                !"#$%& '()*'+,-.'/'+012"'+3!.45'6+7/4!& !"#$8& '()*'+,-.'/'+012"'+3!.45'986+7/4!& !"#$9& '()*'+,-*:;<=*'+,-.'/'+012"'+3!.45'%6+7/)(<!& !"#$>& '()*'+,-?'(5!*'+,-.'/'+012"'+3!.45'6+7/4!& !"#$@& '()*'+,-.'/'+012"'+3!.45'A6+7#/)(<!& !"#$B& '()*'+,-.'/'+012"'+3!.45'A6+7#/)(<!="C71D!?%-):*A/;4D!?& !"#$#& '()*'+,-.'/'+012"'+3!.45'8!15*!"(,!& !"#$A&;1/)0/'+012"'+3!& !"#$E& '()*'+,-.'/'+012"'+3!.45'F(*:(G!-"HF>I>& !"#$%J&;1/)0K1+5*F(*:(G!-"HF>I>& !"#$%%&;1/)0="),!?7)G'L(12"'K1+5*-"HF& !"#$%8&M4/)0="(N! JAJE& !"#$%9&M4/)02"),'O+N!*:)!? JAJE& !"#$%>& '()*'+,-.'/'+012"'+3!.45' JAJE& !"#$%@& '(P!/)0*"4D'?'(!=1P( JAJE& !"#$%B&;1/)0/'+012"'+3! JAJE& !"#$%#&M4/)0="(N! #%JE& !"#$%A& '()*'+,-.'/'+012"'+3! AEM@8.45' #%JE& !"#$%E&;1/)0/'+012"'+3! #%JE& !"#$8J&M4/)0="(N! JAJA& !"#$8%&M4/)0?'()*'+,-.'/'+012"'+3!.45' JAJA& !"#$88&M4/)0?'()*'+,-.'/'+012"'+3!.45':+6(Q& !"#$89&M4/)0?'()*'+,-.'/'+012"'+3!.45'>:+6(QK1(?'()*'+,- 8AJ9& !"#$8>& !"/)G!?=4O;45=6)(<'!")P& !"#$8@&(5==1)G!7(NQO+N!*:)!?/)G!?=4O;45=& !"#$8B&(5==1)G!7(NQO+N!*:)!?/)G!?=4O;45=& !"#$8#&'+012"'+3!2H="%=1)G!7(NQ& !"#$8A&'+012"'+3!2H="8=1)G!7(NQ& !"#$8E&'+012"'+3!-"),'"4<-=(P"('& !"#$9J&M4/)0?'()*'+,-.'/'+012"'+3!.45'/)G!?=4O;45=K1( 8AJ9& !"#$9%& !"=1P( !"#$98& '()*'+,-.'/'+012"'+3!A##@%.45'& !"#$99& '()*'+,-.'/'+012"'+3! AEM@8.45'& "# , ()* &/)IJ  *  J  *  J  *  J   > B KL.ML L L    !"#$9>&(<!?L)5!?/'+012"'+3!=1P(& !"#$9@&;1/)0/'+012"'+3!& !"#$9B&;1/)0I1(,*6+G!"")(R=7;S6'+G1:(& !"#$9#&+7F(*:(G!@T#& !"#$9A&M(5!?=";S & !"#$9E&M4/)0F(<="/'+012"'+3!& !"#$>J&M4/)0="(N!=1P(:+(6$*'F+M%8AA#& !"#$>%&)3=";5=O)G!"45O+N!*:)!?=1P(+(6$*'F+M%8AA#& !"#$>8& '()*'+,-.'/'+012"'+3!.45'+(6$*'F+&           (P!?#$%&(SK1+5*/'+012"'+3!6+7& (P!?#$8&(S#/)(<!=1P(=(5=L),& (P!?#$9&(SK1+5*I1(,*:(=)G*.(DF(S"(D!?/;4<=/)<=.+0& (P!?#$>&(P!?*:(<!?*"(5'=")<!2+N!" & (P!?#$B&(5=="(N!=1P( (P!?#$#&(5=6+G!"=1P( (P!?#$A&(S=";S & (P!?#$E&U1+5**"+)=(5="8& (P!?#$%J&(5=*")N!?L),*H!"'+G1!?)S:(MUV& (P!?#$%%&(5=/W!"7(<!?=1P(=(5=*")N!?L),*"4D'?'(!&    "# , ()* &/)IJ  *  J  *  J  *  J   > B +E7  KL.ML L L   &     X      P       P                     !"#    $ $% & $' (  %       $)  *&$)   +  ,- .  +   /0%0*1'    % *&$)   *2$ ! &$$+$"+$ ! * 3      4 5   $  %+   /061%7061%$& $/--8&  +   9061 % 90061%$ & $ 0':$  !   * ;      &  4$+5 +  /<*1%$ & $  /--84/<*1=/5&  +  0*1%$& $040*1=05' :$ $ $%& $"!  +$ $ $% ">?/' LED Y1 74ABT245 2 3 4 5 6 7 8 9 19 1 18 17 16 15 14 13 12 11 A0 A1 A2 A3 A4 A5 A6 A7 G DIR B0 B1 B2 B3 B4 B5 B6 B7 C1 C 330 R1 R C1 C AT89S52 21 22 23 24 25 26 27 28 17 16 29 30 11 10 31 19 18 9 39 38 37 36 35 34 33 32 1 2 3 4 5 6 7 8 12 13 14 15 P2.0 P2.1 P2.2 P2.3 P2.4 P2.5 P2.6 P2.7 RD WR PSEN ALE/P TXD RXD EA/VP X1 X2 RST P0.0 P0.1 P0.2 P0.3 P0.4 P0.5 P0.6 P0.7 P1.0/T2 P1.1/T2X P1.2 P1.3 P1.4 P1.5 P1.6 P1.7 INT0 INT1 T0 T1 R1 R VCC LED AT89S52 21 22 23 24 25 26 27 28 17 16 29 30 11 10 31 19 18 9 39 38 37 36 35 34 33 32 1 2 3 4 5 6 7 8 12 13 14 15 P2.0 P2.1 P2.2 P2.3 P2.4 P2.5 P2.6 P2.7 RD WR PSEN ALE/P TXD RXD EA/VP X1 X2 RST P0.0 P0.1 P0.2 P0.3 P0.4 P0.5 P0.6 P0.7 P1.0/T2 P1.1/T2X P1.2 P1.3 P1.4 P1.5 P1.6 P1.7 INT0 INT1 T0 T1 Y1 RESET VCC 330 VCC RESET   Y(Z YOZ !"#$%& '()*'+,-.'/'+012"'+3!.45'6+7/4!& ? 3">?/ +%%$  $% !   & $"* /    +      %     *-%*%  !" $ *@( )* A  $+%  $'3">?/# @()*><$+$' ? 3">?+%%$  $% !   & $"* 0  &     %     !+  @()*' "# , ()* &/)IJ  *  J  *  J  *  J   > B KL.ML L L   </ 470 AT89S52 21 22 23 24 25 26 27 28 17 16 29 30 11 10 31 19 18 9 39 38 37 36 35 34 33 32 1 2 3 4 5 6 7 8 12 13 14 15 P2.0 P2.1 P2.2 P2.3 P2.4 P2.5 P2.6 P2.7 RD WR PSEN ALE/P TXD RXD EA/VP X1 X2 RST P0.0 P0.1 P0.2 P0.3 P0.4 P0.5 P0.6 P0.7 P1.0/T2 P1.1/T2X P1.2 P1.3 P1.4 P1.5 P1.6 P1.7 INT0 INT1 T0 T1 VCC 470 470 470 LED LED 470 LED LED 470 Y1 470 LED 470 LED LED 470 LED 470 LED LED LED 470 R1 10k 470 LED LED VCC LED 470 470 470 470 470 LED 470 LED LED LED LED 470 VCC 470 VCC LED 470 470 LED LED C1 10 470 LED 470 RESET LED LED 470 LED LED 470 470 470 LED 470 470 LED LED 470 470 LED LED  !"#$8& '()*'+,-.'/'+012"'+3!.45'986+7/4!& B$)     C  D Ω= −− = −− = 491 6.5 45.08.15 mA VVV I VVV R LED OLLEDCC  E  $;FG  !-  *&$) + $)  +  >0'   +$  &$$+$ ) & +%%$     A +  $) +     $ " %   $)+ -% +  "#  "#  $ *   +%%$' ! "# $%&'()*P * * *    , $   ">?- ! &$%   "$+$8   HD ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;chuong trinh dieu khien 32 led chop tat ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx org 0000h ;khai bao dia chi bat dau cua chuong trinh lb: mov p0,#00h ;sang 8 led cua p0 mov p1,#00h ;sang 8 led cua p1 mov p2,#00h ;sang 8 led cua p2 mov p3,#00h ;sang 8 led cua p3 lcall delay ;goi chuong trinh con delay mov p0,#0ffh ;tat 8 led cua p0 mov p1,#0ffh ;tat 8 led cua p1 mov p2,#0ffh ;tat 8 led cua p2 mov p3,#0ffh ;tat 8 led cua p3 lcall delay ;goi chuong trinh con delay sjmp lb ;lam lai tu dau ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;chuong trinh con ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx delay: mov r6,#0ffh ;nap hang so delay FFH vao thanh ghi r6 de : mov r7,#0ffh ;nap hang so delay FFH vao thanh ghi r7 djnz r7,$ ;giam thanh ghi r7 di 1 va nhay khi r7 khac 00 "# , ()* &/)IJ  *  J  *  J  *  J   > B +E+  KL.ML L L  djnz r6,de ;giam thanh ghi r6 di 1 va nhay khi r6 khac 00 ret ;thoat khoi chuong trinh con end    , $">?- ! &$%   "$+$8   &  H D ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;chuong trinh dieu khien 32 led sang dan len va tat dan ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx org 0000h mov p0,#0ffh ;tat port 0 mov p1,#0ffh ;tat port 1 mov p2,#0ffh ;tat port 2 mov p3,#0ffh ;tat port 3 ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;dieu khien sang dan len ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx lb: lcall delay ;goi chuong trinh con delay clr c ;lam cho bit C = 0 mov a,p0 ;chuyen noi dung port0 vao thanh ghi A rlc a ;xoay noi dung thanh ghi A sang trai mov p0,a ;chuyen noi dung port0 vao thanh ghi A mov a,p1 ;xoay noi dung p1 rlc a mov p1,a mov a,p2 ;xoay noi dung p2 rlc a mov p2,a mov a,p3 ;xoay noi dung p3 rlc a mov p3,a jc lb ;thuc hien tiep khi C=1 ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;dieu khien tat dan ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx lb1: lcall delay ;goi chuong trinh con delay setb c ;lam cho bit C = 1 mov a,p0 ;chuyen noi dung port0 vao thanh ghi A rlc a ;xoay noi dung thanh ghi A sang trai mov p0,a ;chuyen noi dung port0 vao thanh ghi A mov a,p1 ;xoay noi dung p1 rlc a mov p1,a mov a,p2 ;xoay noi dung p2 rlc a mov p2,a mov a,p3 ;xoay noi dung p3 rlc a mov p3,a jnc lb1 ;thuc hien tiep khi C=0 sjmp lb ;sau khi 8 led sang het thi quay lai tu dau ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;chuong trinh con delay ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx delay: mov r6,#0ffh de : mov r7,#0ffh djnz r7,$ djnz r6,de ret end "# , ()* &/)IJ  *  J  *  J  *  J   > B KL.ML L L   <8  (D'*(G-%X3 ! &$%   "$+$8   H    $   $-  $    $-   $& &   $ !  ' (D'*(G-8X3 ! &$%   " $%  # $/  *2$+$      $)< ' +    ,-P  -  -  -    &#.(,/* * * * P        /> "  $  $ $%&$$+$& $D ? I$ $%    $%D+$  ! /  &$$+$+%%$& $ >   $1   ">?8':$   9  @J' ? I$ $% $ $%D+$      +%%$& $@( $ $* !>   ">?':$     @J' Y1 VCC R2330 C 10 R4330 RESET R8330 R5330 LED1 4 5 9 7 6 2 1 10 3 8 a b c d e f g dp A1 A2 VCC R6330 R1330 AT89S52 21 22 23 24 25 26 27 28 17 16 29 30 11 10 31 19 18 9 39 38 37 36 35 34 33 32 1 2 3 4 5 6 7 8 12 13 14 15 P2.0 P2.1 P2.2 P2.3 P2.4 P2.5 P2.6 P2.7 RD WR PSEN ALE/P TXD RXD EA/VP X1 X2 RST P0.0 P0.1 P0.2 P0.3 P0.4 P0.5 P0.6 P0.7 P1.0/T2 P1.1/T2X P1.2 P1.3 P1.4 P1.5 P1.6 P1.7 INT0 INT1 T0 T1 R3330 R 10k R7330  !"#$9& '()*'+,-*:;<=*'+,-.'/'+012"'+3!.45'%6+7/)(<!& B$)     C  D Ω= −− = −− = 491 6.5 45.08.15 mA VVV I VVV R LED OLLEDCC  E $)+  >0' (N1")P'%X (SQ=")O'+,*;12"1Q+,*/'+3F=1P(8=(5="?'()*'+,-.'/'+012"'+3!.45'%6+7#/)(<! 4P8" !"*:+N!&  "# , ()* &/)IJ  *  J  *  J  *  J   > B +ED  KL.ML L L  R2330 Y1 VCC R 10k R3330 R7330 C 10 AT89S52 21 22 23 24 25 26 27 28 17 16 29 30 11 10 31 19 18 9 39 38 37 36 35 34 33 32 1 2 3 4 5 6 7 8 12 13 14 15 P2.0 P2.1 P2.2 P2.3 P2.4 P2.5 P2.6 P2.7 RD WR PSEN ALE/P TXD RXD EA/VP X1 X2 RST P0.0 P0.1 P0.2 P0.3 P0.4 P0.5 P0.6 P0.7 P1.0/T2 P1.1/T2X P1.2 P1.3 P1.4 P1.5 P1.6 P1.7 INT0 INT1 T0 T1 VCC VCC R6330 VCC LED1 4 5 9 7 6 2 1 10 3 8 a b c d e f g dp A1 A2 74247 7 1 2 6 4 5 3 13 12 11 10 9 15 14 D0 D1 D2 D3 BI/RBO RBI LT A B C D E F G R5330 R4330 RESET VCC R1330  !"#$>& '()*'+,-?'(5!*'+,-.'/'+012"'+3!.45'6+7/4!& ! "# $% &#.(,/*   *   *   * D ,C8D3 !  ">?8-&$%   "$+$/> %* 0%' ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;chuong trinh dem len tu 0 den 9 hien thi tren 1 led ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx dem equ r2 led equ p1 org 0000h ;bat dau chuong trinh mov dptr,#ma7doan ; main0: mov dem,#00h ;dem=00 main1 mov a,dem movc a,@a+dptr ;lay ma 7 doan mov led,a ;goi ra led hien thi lcall delay inc dem ;tang gia tri dem cjne dem,#10,main1 ;ss dem voi 10 ljmp main0 ;lam lai tu dau ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;chuong trinh con delay ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx delay: mov r5,##0ffh loop1: mov r6,#0ffh djnz r6,$ djnz r5,loop1 ret ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;khai bao ma 7 doan tu so '0' den so '9' ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ma7doan: db 0C0h,0F9h,0A4h,0B0h,99h,92h,82h,0F8h,80h,90h end "# , ()* &/)IJ  *  J  *  J  *  J   > B KL.ML L L   <<  &C8     .  *%#$%   K*L& $ $  #  # M 00-    $ $* !   * !> &  $   $ - $%      $)    "   / $  -   N  $ %*/&& +$* O*%  # M /0". & $ $* !& $%* $-%# M /0"O &00& # H  $ + * $' ,CD3 !  ">?-&$%   "$+$/> %* 0%' ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;chuong trinh dem len tu 0 den 9 hien thi tren 1 led ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx dem equ r2 led equ p1 org 0000h ;bat dau chuong trinh main0: mov dem,#00h ;dem=00 main1 mov a,dem mov led,a ;goi ra led hien thi lcall delay inc dem ;tang gia tri dem cjne dem,#10,main1 ;ss dem voi 10 ljmp main0 ;lam lai tu dau ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;chuong trinh con delay ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx delay: mov r5,##0ffh loop1: mov r6,#0ffh djnz r6,$ djnz r5,loop1 ret end  &C"   $% &C8   *  $) ! @( $ $* !>      "+   $$%  $ $* !-   $* !P(G '   &#).(,/*  *  *  * P B *.& $   $ $%$+$$> "+%%$    . 'Q     > ">?<'  $*2$*)$$*   / $ 2& > $  $ H- !$) $ !       & $ $ 2'Q   / $+  2&  $ !$)$  -. "$+$  $2    %+$%9' , $% ) $ !$) & * H      " % 9    / ' R !. D*  $ 0" $ 2-*  $ /" $ H  "#  #   >?/'   [ \ (SK1+5*/'+012"'+3!=(5=*:(!L'L*): ] % % % % % % % J :(!L'L*):%  ] % % % % % % J % :(!L'L*):8  ] % % % % % J % % :(!L'L*):9  ]# % % % % J % % % :(!L'L*):>  "# , ()* &/)IJ  *  J  *  J  *  J   > B +EF  KL.ML L L  ] % % % J % % % % :(!L'L*):@  ] % % J % % % % % :(!L'L*):B  ] % J % % % % % % :(!L'L*):#  #] J % % % % % % % :(!L'L*):A  (P!?#$%&(SK1+5*/'+012"'+3!6+7& R !> D )%   >  $1  *  $ 0"   & *  $ /" H'( * !>    % )  0%&  %O 1%S   "#  #  >?D    M),"+I 7- ? ^ + 7 = O ( (SL),"+I J % % J J J J J J J % % % % % % J J % ]E 8 % J % J J % J J > 9 % J % % J J J J J > % J J % % J J % EE @ % J J % J J % J E8 B % J J J J J % J A8 # % % % % % J J J ]% A % J J J J J J J AJ E % J J % J J J J EJ  % J J J % J J J AA  % J J J J J % % A9  % % J J J J % J 8  % J % J J J J % %  % J J J J % % J AB ] % J J J % % % J A (P!?#$8&(S#/)(<!=1P(=(5=L),& ( * !+    $% )' "# , ()* &/)IJ  *  J  *  J  *  J   > B KL.ML L L    VCC b R10 10k LED5 4 5 9 7 6 2 1 10 3 8 a b c d e f g dp A1 A2 fa LED2 4 5 9 7 6 2 1 10 3 8 a b c d e f g dp A1 A2 LED0 4 5 9 7 6 2 1 10 3 8 a b c d e f g dp A1 A2 c LED3 4 5 9 7 6 2 1 10 3 8 a b c d e f g dp A1 A2 LED6 4 5 9 7 6 2 1 10 3 8 a b c d e f g dp A1 A2 d Q2A564 g Q5A564 g f p27 p24 d p b e R13 10k p b R8330 p P23 VCC p pc c f c b c d a g LED1 4 5 9 7 6 2 1 10 3 8 a b c d e f g dp A1 A2 p p22 VCC c P24 p26 g p d b p25 C 10 R6330 g VCC c a d R16 10k d R5330 e R15 10k Q7A564 d a P25 p21 RESET VCC g Q3A564 b f g R1330 e LED7 4 5 9 7 6 2 1 10 3 8 a b c d e f g dp A1 A2 e P20 p23 R 10k VCC f AT89S52 21 22 23 24 25 26 27 28 17 16 29 30 11 10 31 19 18 9 39 38 37 36 35 34 33 32 1 2 3 4 5 6 7 8 12 13 14 15 P2.0 P2.1 P2.2 P2.3 P2.4 P2.5 P2.6 P2.7 RD WR PSEN ALE/P TXD RXD EA/VP X1 X2 RST P0.0 P0.1 P0.2 P0.3 P0.4 P0.5 P0.6 P0.7 P1.0/T2 P1.1/T2X P1.2 P1.3 P1.4 P1.5 P1.6 P1.7 INT0 INT1 T0 T1 R2330 R14 10k d Q4A564 p d LED4 4 5 9 7 6 2 1 10 3 8 a b c d e f g dp A1 A2 b VCC P26 R11 10k R7330 b R17 10k Q1A564 a c e Y1 p R12 10k f P21 p20 f R4330 a Q6A564 e a g f e VCCVCC b e P27 c R3330 VCC e a f Q0A564 a g P22  !"#$@& '()*'+,-.'/'+012"'+3!.45'A6+7#/)(<!&  ">?<    $ *# %    $+$# M   *@( %  & $. &  $ $* ! ">?7'  R13 10k c a Q3A564 R10 10k U57447 7 1 2 6 4 5 3 13 12 11 10 9 15 14 D0 D1 D2 D3 BI/RBO RBI LT A B C D E F G R 10k P10 f f P13 Y7 f a LED1 4 5 9 7 6 2 1 10 3 8 a b c d e f g dp A1 A2 VCC e p g Q7A564 VCC e f P11 c d b a P11 f VCC P15 LED0 4 5 9 7 6 2 1 10 3 8 a b c d e f g dp A1 A2 VCC c a R15 10k e P16 Y0 b LED2 4 5 9 7 6 2 1 10 3 8 a b c d e f g dp A1 A2 b VCC Q0A564 b R14 10k LED4 4 5 9 7 6 2 1 10 3 8 a b c d e f g dp A1 A2 VCC g VCC e R7330 VCC a p P12 R3330 a e g RESET P12 b R2330 LED5 4 5 9 7 6 2 1 10 3 8 a b c d e f g dp A1 A2 dR6330 e Y1 b b c VCC LED7 4 5 9 7 6 2 1 10 3 8 a b c d e f g dp A1 A2 d Y4 U474S138 1 2 3 15 14 13 12 11 10 9 7 6 4 5 A B C Y0 Y1 Y2 Y3 Y4 Y5 Y6 Y7 G1 G2A G2B f P16 g e P17 b p P13 d p d AT89S52 21 22 23 24 25 26 27 28 17 16 29 30 11 10 31 19 18 9 39 38 37 36 35 34 33 32 1 2 3 4 5 6 7 8 12 13 14 15 P2.0 P2.1 P2.2 P2.3 P2.4 P2.5 P2.6 P2.7 RD WR PSEN ALE/P TXD RXD EA/VP X1 X2 RST P0.0 P0.1 P0.2 P0.3 P0.4 P0.5 P0.6 P0.7 P1.0/T2 P1.1/T2X P1.2 P1.3 P1.4 P1.5 P1.6 P1.7 INT0 INT1 T0 T1 g a R5330 R11 10k Q1A564 d Y2 g f R4330 R16 10k pP10 VCC e e Y5 C 10 VCC d f R12 10k p a g c Q2A564 g c VCC Q4A564 d P14 p LED3 4 5 9 7 6 2 1 10 3 8 a b c d e f g dp A1 A2 a Y3 g Y1 b P15 P17 f P14 Y6 R17 10k Q5A564 R1330 LED6 4 5 9 7 6 2 1 10 3 8 a b c d e f g dp A1 A2 c p d Q6A564 c c  !"#$B& '()*'+,-.'/'+012"'+3!.45'A6+7#/)(<!="C71D!?%-):*A/;4D!?& "# , ()* &/)IJ  *  J  *  J  *  J   > B +E0  KL.ML L L   ">?7  @(>>  & $ $ $* !%P(G  * !> -@(>/89     N  $ $* !8    9  $+$9  $'Q%     $+$   >  '  >  $+$  /"&$$+$! #$ % $* !P(G @( $ $* !$+$> -8#$$% $+$@( $ $* !  / $  2'B  C$)T/'>$+$      @(>/89D+$*%  $" T/'> $* 0-+$ %*"T/'> $* 3'     .   9"$ $        /# M /=9  + . -$ $  H# M >=9 + . 'G$ $  H+  $& $$ $     $.  " * $" %  %    ' , $  U + &  HU + " %* H " %   $  4  * H  5     % $V03W' , $9>     . " %.      % $   V703W'    D& $  *&$) #"  4+ . 5   mAI LED 5= -   *&$) *  VV LED 8.1= ':$ $)  *2$ D Ω= −− = −− = 550 5 45.08.15 mA VVV I VVV R LED OLLEDCC BT      D"  $ $# M 0*1X %9 'B N  "   D  N   A  $ *$) 'B& $$)   *&$)      $)  $ *$)& $)  C $  D Ω= −− = −− = 75,68 40 45.08.15 _ mA VVV I VVV R QUETLED OLLEDCC Quet  , ) $)   $ *&       M*  *&$ 79%0 M*  N *  )  & # &).  ' (N1")P'8X (SQ=")O'+,*;12"1Q+,*/'+3F=1P(8=(5="?'()*'+,-.'/'+012"'+3!.45'A6+7#/)(<! 4P8" !"*:+N!& ( "# $%&'()* * * * &#0.(,/*  *  *  * P ,C      . ' ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;chuong trinh dem len tu 00 den 59 hien thi tren 2 led ;su dung ngat timer t0 de dem chinh xac ve thoi gian ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx giay equ r2 ;gan bien dem giay la R2 bdn equ r1 ;gan bien dem ngat quet equ p2 led7 equ p0 ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ; chuong trinh chinh ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx org 0000h ;bat dau chuong trinh ljmp main ;nhay den chtr chinh "# , ()* &/)IJ  *  J  *  J  *  J   > B KL.ML L L   < org 000bh ljmp int_t0 ;nhay den chtr con ngat timer0 main: mov tmod,#01h ;timer0: mod 1 - dem 16 bit mov dptr,#ma7doan ;dptr quan ly vung ma 7 doan clr tf0 ;xoa co tran mov IE,#10000010B ;cho phep timer0 ngat mov TH0,#high(-50000) ;khoi tao timer delay 50ms mov TL0,#low(-50000) setb tr0 ;cho phep timer bat dau dem main0: mov giay,#00h ;giay=00 main1: mov bdn,#00 ;nap bien den so lan ngat lcall gma main2: lcall hthi ;goi chtr con hien thi cjne bdn,#20,main2 ;chua dung 20 lan [tuc 1 giay] mov a,giay ;chuyen giay sang A add a,#1 ;tang giay len 1 da a ;hieu chinh so BCD trong A mov giay,a ;tra lai cho giay cjne giay,#60h,main1 ;ss giay voi 60h ljmp main0 ;lam lai tu dau ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ; chuong trinh con giai ma ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx gma: mov a,giay anl a,#0fh ;xoa 4 bit cao hang chuc giay movc a,@a+dptr ;lay ma 7 doan mov 27h,a ;cat ma vao o nho 20h mov a,giay anl a,#0f0h ;xoa 4 bit thap hang dvi swap a ;chuyen 4 bit cao xuong vi tri thap movc a,@a+dptr ;lay ma 7 doan hang chuc mov 26h,a ret ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;CHUONG TRINH CON NGAT TIMER0 SAU KHOANG THOI GIAN 50MS ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx int_t0: inc bdn ;tang bien dem giay len 1 mov TH0,#high(-50000) ;khoi tao timer delay 50ms mov TL0,#low(-50000) clr TF0 reti ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;chuong trinh con hien thi ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx hthi: mov a,#01111111b ;ma quet mov r0,#27h ht1: mov led7,@r0 mov quet,a lcall delay1 mov quet,#0ffh dec r0 rr a ;chuyen sang led ke cjne r0,#25h,ht1 ret ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;chuong trinh con delay1 "# , ()* &/)IJ  *  J  *  J  *  J   > B +F7  KL.ML L L  ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx delay1: mov r7,#0fh djnz r7,$ ret ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;khai bao ma 7 doan tu so '0' den so '9' ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ma7doan: db 0C0h,0F9h,0A4h,0B0h,99h,92h,82h,0F8h,80h,90h end  (D'*(G-9X3 ! &$%   "%* $   ">?7' (D'*(G->X3 ! &$%   "%*  $    *  ' (D'*(G-@X3 ! &$%   "%* $  $    *  '  &        X    12"+=1 P 2   2   2    *)%)% $+$    % C* % Y$   $  $% $ !   $&  $%#$+$&C * &$ C-*  C $  # C*...")<!F)G*/(017(NQ.(D!),'/(017(NQ/)5I1),!?F(LL .(D?'(PL;P/(017(NQ/)5 6(D7(NQ *";5>`"(SQ I+F" !"O+N! -"(P'*;4!?;5!?&  ';S!?1Q+N!O;45=*:+N! '+,-*"+)=")<!%/(017(NQ*:)!?9/(01=)D!6(<'.(D!),' .45' F(LL ` K1(! L(5* *"(,Q :)*): K1(Q !"+< % O;45= *"+) ="'+012'F/)0!?")0*" /)56(D=1)G!7(NQ*";59&  "(5)=1)G!7(NQ*";59:(2")P'F(LL '+,-*"+)=")<!%/(017(NQ*:)!?8/(01=)D!6(<'.(D!),' .45' F(LL ` K1(! L(5* *"(,Q :)*): K1(Q !"+< % O;45= !?;4<= ="'+012'F/)0!?")0*" /)56(D=1)G!7(NQ*";5%&  "# , ()* &/)IJ  *  J  *  J  *  J   > B +07  KL.ML L L  1)G!7(NQ=)D! 6(<' 6(D=1)G!7(NQ*";58!";!?*(=1S!? =)5 *"+3 2'+3F *:( O(a!? =(5=" !),' !)5 .45'  F(LL ` K1(! L(5* *"(,Q:)*):2")N!?K1(Q&  ( O  )   **# M   /      *   **-$) & $     $D% $ $)# M  "    !    **- %+ # M "    + &   $) $!"*       **' " $+$)  #   *  8+$D+$+C / )  -+$+C  )   &  $+$ ! #  ' ' :$$+$+C / )   ">?>D  !"#$8#&'+012"'+3!2H="%=1)G!7(NQ&  ""*2$/$$*   / )     $KL'B)  !. *2$ #  +$ $   $$+$' R%.   $"" $+$$%  $   $' #' :$$+$+C  )   ">?9D "# , ()* &/)IJ  *  J  *  J  *  J   > B KL.ML L L   9/  !"#$8A&'+012"'+3!2H="8=1)G!7(NQ& ' T%$ $+$$+$ ! #   ">?D "# , ()* &/)IJ  *  J  *  J  *  J   > B +0+  KL.ML L L    !"#$8E&'+012"'+3!-"),'"4<-=(P"('&   $+$ ! #     % 9   $+  ' "# , ()* &/)IJ  *  J  *  J  *  J   > B KL.ML L L   98 Q*   $ $%&$$+$& $)  #   ">?80D RN2 10k 1 2 3 4 5 6 7 8 9 VCC IC2 ULN2803 10 1 2 3 4 5 6 7 8 18 17 16 15 14 13 12 11 9 COM IN1 IN2 IN3 IN4 IN5 IN6 IN7 IN8 OUT1 OUT2 OUT3 OUT4 OUT5 OUT6 OUT7 OUT8 GND Coil4 Coil1 Y1 Coil3 +12V RESET Coil2 DONG CO BUOC AT89S52 21 22 23 24 25 26 27 28 17 16 29 30 11 10 31 19 18 9 39 38 37 36 35 34 33 32 1 2 3 4 5 6 7 8 12 13 14 15 P2.0 P2.1 P2.2 P2.3 P2.4 P2.5 P2.6 P2.7 RD WR PSEN ALE/P TXD RXD EA/VP X1 X2 RST P0.0 P0.1 P0.2 P0.3 P0.4 P0.5 P0.6 P0.7 P1.0/T2 P1.1/T2X P1.2 P1.3 P1.4 P1.5 P1.6 P1.7 INT0 INT1 T0 T1 R 10k C 10 VCC  !"#$9J&M4/)0?'()*'+,-.'/'+012"'+3!.45'/)G!?=4O;45=K1( 8AJ9& (  **  )  #   $%$& $ * )   *&$) 'E%)      % & $  *&$)     @(b;E908"  $'   (  "$+$)  #  . $ / $D +$$+$ +C / )  D ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;chtr dieu khien step motor quay lien tuc theo 1 chieu, thoi gian delay dai thi dong co quay cham ;thoi gain nho thi dong co quay nhanh, thoi gian qua nho thi dong co khong dap ung duoc se dung yen ;dung 1 port de dieu khien motor qua ic giao tiep 2803 - dung 4 bit thap hoac 4 bit cao ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx outstep equ p1 org 0000h main: mov outstep,#10001000b lcall delay mov outstep,#01000100b lcall delay mov outstep,#00100010b lcall delay mov outstep,#00010001b lcall delay sjmp main ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;chuong trinh con delay ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx delay: mov r6,#0 del: mov r7,#0 djnz r7,$ djnz r6,del ret end   (  "$+$)  #  . /& $  D ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx "# , ()* &/)IJ  *  J  *  J  *  J   > B +0D  KL.ML L L  ;chtr dieu khien step motor quay 1 vong roi ngung luon ;dung 1 port de dieu khien motor qua ic giao tiep 2803 ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx outstep equ p1 sobuoc equ 50 ;loai dco: 50x4=200 buoc org 0000h mov dptr,#datastep ;nap dia chi quan ly ma mov r0,#0 mov r2,#sobuoc ;50 chu ky la vong main2: mov r1,#4 ;1 chu ky 8 buoc main1: mov a,r0 movc a,@a+dptr mov outstep,a lcall delay inc r0 anl 00h,#03h ;anl r0 voi 00000011b djnz r1,main1 djnz r2,main2 sjmp $ ;dung lai ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;chtr con delay ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx delay: mov r6,#10h del: mov r7,#0 djnz r7,$ djnz r6,del ret ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;khai du lieu dieu khien dong co buoc ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx datastep: db 10001000b db 01000100b db 00100010b db 00010001b end B)     # $&C     % /& 00#  ' (D'*(G-%JX3 ! $%+%*  $+$/)  #  & $   % Q -Q-@& &  $ $%& $> ',$%   "$+$)  #  & $    D+$  % Q ")     & $%#  > -+$ % ")     -+$ %   $")    $' &     X   1 5="P 5 5 5  ef   $ $%& $>     %&" $   % 0% A % O 0%SX+  $    $+C + -     !  $   ;(G' "# , ()* &/)IJ  *  J  *  J  *  J   > B KL.ML L L   9< ;(G   %$   #$)+C    & $+C %    +C - /   %& $    ',C;(G/7[   d      -*2$    /7+C ';(G0[    d      -*2$    0+C ' ;(G/7[ ">?8/D  !"#$9%& !"=1P( + > ?"1@"=A"P? @ A? @ A? @ A  ;(G  $ $& %        ! +       $#$%  $/  &  $/7  - +          %-    $+$"+   $-+$    $;(G  " $         #$% !   'Q    ;(G #   D  (P!?#$B&(5=="(N!=1P(  /    ;(G   $   *8  C$)  D          ( %/   %$* 40,5-    ,%$& $ g<,' (  8      %$& $#$%'          ( %   `Q $+$     $'( `=h  $+$. " &  $'( F       O  %'          ( %>%  %/ 9    $ !$) $ !  $%#$+$& ;(G' 9 > ?3-"1   ?=B1 C "P? - ? C ? - ? C ? - ? C       ! "#    $ $%&$$+$& $;(G'3">?8! "#   +%%$ &$$+$9>(></     K31E`JE@iL  $$)@'  "# , ()* &/)IJ  *  J  *  J  *  J   > B +0F  KL.ML L L    !"#$98& '()*'+,-.'/'+012"'+3!A##@%.45'& (  &$$+$19Q?88D Y1 D6 VCC VCC VO D2 RESET D4 D7 R3 10K RS LCD VDD VCC E C1 C D0 D3 R/W AT89S52 21 22 23 24 25 26 27 28 17 16 29 30 11 10 31 19 18 9 39 38 37 36 35 34 33 32 1 2 3 4 5 6 7 8 12 13 14 15 P2.0 P2.1 P2.2 P2.3 P2.4 P2.5 P2.6 P2.7 RD WR PSEN ALE/P TXD RXD EA/VP X1 X2 RST P0.0 P0.1 P0.2 P0.3 P0.4 P0.5 P0.6 P0.7 P1.0/T2 P1.1/T2X P1.2 P1.3 P1.4 P1.5 P1.6 P1.7 INT0 INT1 T0 T1 D5 R1 R VSS D1  !"#$99& '()*'+,-.'/'+012"'+3! AEM@8.45'&   +$    ;(G" $ #$%   +C $;(G "   $' D "" 51 ?=B1 C"P 5 ? C 5 ? C 5 ? C  "# , ()* &/)IJ  *  J  *  J  *  J   > B KL.ML L L   9> B$+$;(G"   @(     C #  $;(G  * !%>90/ % @(>90' @(    #) `1R   ! !$) $&   $) &$) $+$;(G$' ( $+$#  * )  $)+#   D  (P!?#$#&(5=6+G!"=1P(   !"#$% &'  !  !  ! D+$  $))  ";(G!#O & #)%*    O &0'   & ($ )*  !" )   ! )   ! )   ! # $% $+ 'D+$  $))  "#)%*    O &0- $&&C %  !#    'E)$ #) `1R$ GG`1R+ # $'  ( (  *!   !  !  ! #,($& %('D)   $% )%$&   +C $ -#$@G^/"  )  N /*2$+$  /#  !$) $& #)$-+$@G^ 0" !+  N D !$)* $! $ !$) !'P$Q^/"       !$)*2$+$ )/# $'        ($ ))))(- #% & ($ 'D)   $+$ 4  $"#$G^/- H$"#$G^05- H* 4* "#$(^/- H  "#$(^05-&  %  4  % "#$P^/- H"#$P^05'   & ($ ) ) ) ) # $% $.% &/0('D )   $+$$    $   4Q(^/     -Q(^0"+   5-      4`;^/"  $-`;^0"  $5'E)$ #) GG`1R& 2+ $'  ( ( -1 2 3456 (7(8     8     8     8 #/(94565$'D)   $%  )   #) `1R +C '  ( (   -1 2 3456(-          #/(4565$'D )    $%  )   #) `1R  !  !$)$' 3 $) %$   ) & ) $ !$);(G' G     C$)+$  $) $ !$)& ;(G ">?8D "# , ()* &/)IJ  *  J  *  J  *  J   > B +00  KL.ML L L   !"#$9>&(<!?L)5!?/'+012"'+3!=1P(& E"&         %   " $+$  D ? B$+$C$)`Q' ? B$+$C$)`=hO% *  %' ? B$+$C$)F*    ' ? i % !$)G>cG0' ? B$+$C$)F&*  %' ? B$+$C$)`=h*   $' E <=? ?=B1 C"P? ? C? ? C? ? C  B$+$;(G" $#$%" $+$  O       " >?8<D "# , ()* &/)IJ  *  J  *  J  *  J   > B KL.ML L L   9   4 5 4#5 !"#$9@&;1/)0/'+012"'+3!&   "4 5     C#  *. "+$ ;(G-$%  )    &  `1R&   $). " $ !$) ;(G$   /& $%     ' ; " 4#5     #$% "     $).  "+$  ;(G#  *  #  D $* !$+$893 ;(G&   $) C % '/*'$%   $)   & $$ $  /006'(%$   $$  * !$+$893-0(3-& 0/3 $% ) %" )  ;(G' ;   $) $ $+$  $ !$) ;(G$ " D "# , ()* &/)IJ  *  J  *  J  *  J   > B +87  KL.ML L L   !"#$9B&;1/)0I1(,*6+G!"")(R=7;S6'+G1:(&      & D &   %% $ $+$%;(G- &     $ !$) $%;(GX +    $). C$)$+$`Q' ( #    $" $%  &  +$$%  $O  $+$= !$)"   $   $+$= ! $) +$*  #$GP> O*  $+$= ! $) !    )O   %  " $ -% ! )O " &  j   ) $+$= !$) $%' F "1E+P? C H ? C? C H ? C? C H ? C  (  " !$+$;(G$   & $)$     %$    "D  !  ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;chuong trinh dieu khien LCD 16X2 tren kit vi dieu khien ;DUNG PORT 0 KET DOI VOI CAC DUONG DU LIEU CUA LCD P0-7 ->D0-7 ;DUNG 3 BIT CUA PORT2: P20,P21,P22 DIEU KHIEN E,R/W,RS ;tren man hinh LCD se hien thi noi dung moi ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx E BIT P2.0 rw BIT P2.1 rs BIT P2.2 byteout equ p0 "# , ()* &/)IJ  *  J  *  J  *  J   > B KL.ML L L   / ORG 0000H mov 0a2h,#0 LCALL khtaolcd ;khoi tao lcd LCALL first_line ;goi chtr con hien thi hang thu nhat LCALL scond_line ;goi chtr con hien thi hang thu hai SJMP $ ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;chtr con khoi tao LCD ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx khtaolcd: setb e ;Enable clr rs ;RS low clr rw ;RW low MOV a,#38h ;tu dieu khien LCD LCALL KTAO LCALL ddelay41 ;delay 4.1 mSec MOV A,#38h ;function set LCALL KTAO LCALL ddelay100 ;delay MOV A,#38h ;function LCALL KTAO MOV A,#0ch ;tu dieu khien display on LCALL KTAO MOV A,#01h ;tu dieu khien Clear display LCALL KTAO MOV A,#06h ;tu dieu khien entry mode set LCALL KTAO MOV A,#80h ;thiet lap dia chi LCD (set DD RAM) LCALL KTAO MOV A,#0fh ;enable display cursor LCALL KTAO RET ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;chuong trinh con delay 4.1 ms ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ddelay41: mov r6,#90h del412: mov r7,#200 djnz r7,$ djnz r6,del412 ret ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;chuong trinh con delay 255 microgiay ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ddelay100: mov r7,#00 djnz r7,$ ret ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;Feed command/data to the LCD module ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx command_byte: clr rs ;RS low for a command byte ljmp bdelay "# , ()* &/)IJ  *  J  *  J  *  J   > B +8+  KL.ML L L  data_byte: setb rs ;RS high for a data byte bdelay: clr rw ;R/W low for a write mode clr e nop setb e ;Enable pulse nop nop mov byteout,#0ffh ;configure port1 to input mode setb rw ;set RW to read clr rs ;set RS to command clr e ;generate enable pulse nop nop setb e lcall ddelay100 ret ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;Chuong trinh con hien thi noi dung hang thu 1 tren LCD ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx first_line: MOV A,#080h ;set DDRAM LCALL KTAO MOV DPTR,#FLINE_DATA lcall Write ret ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;Chuong trinh con hien thi noi dung hang thu 2 tren LCD ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx scond_line: mov a,#0c0h ;set DDRAM LCALL KTAO mov dptr,#sline_data lcall write ret ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;chuong trinh con khoi tao LCD ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx KTAO: mov byteout,a lcall command_byte RET ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;chtr con goi data hien thi ra LCD ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx write: MOV A,#0 MOVC A,@a+dptr CJNE A,#99h,Writea RET Writea: mov byteout,a acall data_byte inc dptr SJMP Write ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ; Data bytes ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx FLINE_DATA: DB 'NGUYEN DINH PHU ',099h SLINE_DATA: DB 'DAI HOC SPKT HCM',099h END "# , ()* &/)IJ  *  J  *  J  *  J   > B KL.ML L L   8 (D'*(G-%%X3 ! $%+%*  $+$/;(G $%  & /# C**  )[ & &$%   "  +$ %C*%  " * "$ %   $& C  )  # $- %      $' (D'*(G-%8X3 ! $%+%*  $+$/;(G $%  & /# C**  )[ & &$%   " $ $  $  -     N*'  &        X   1 5= 345P 5 5 5 5 5 5   .   $   )     *  )-    ! $ $$) & "#    $ $%&$$+$& $*  )&  **$+$*  )' ;*  ) / )   #%C  *  )  $   +C  # %+ '(   %  !C    *  )C4< )& >  5  A 9[949  & 9 )5&  C+C   &  #$) *    - %$     #$)        4$5       $ $ 45';       " +      $$&"   * A$ $%&  *    + " % !-   * $ % !-& d$!   $   ' 3">?8> $ $$)*  )& $* +  D   !"#$9#&+7F(*:(G!@T#& + " =- H 1<  1  ?=B1 C 345 - H  ? C 5 - H  ? C 5 - H  ? C 5 P ;*  ) *) ) & $ +%%$  D  "  %$  - )"  %$  -& $*  )"  >  & < )' "# , ()* &/)IJ  *  J  *  J  *  J   > B +8D  KL.ML L L  1%$& $* 3&  %$* ;"  -     $" H' 3 ! .  ">?89*  )9[9  $  !1-   $  !1D "P(Q.R) #L$S  Q R L S Q R L S Q R L S TUQV) #L$RPQ  L RQ  L RQ  L R  R2$+C   <# * !D ? P * !  % $ 9  4   "#$    # M /-  H" #$    # M 05&   )  %O% * ;-  )  $* 3' ? P * !  $ $ 9  - )  $O% * ;' ? P * ! #  $ 9  - ) # O% * ;' ? P * !   $ 9  - )  O% * ;' ? P * !  N* $ 9  - )  N*O% * ;' G% )  $)     !" %    !1  '  !"#$9A&M(5!?=";S & E%     30&     $   3>"* !    !1& * !.    *  H #   D  [       [U    # B @ > 9 8 % J M),"+I J % 8 9 >  % % % % % J J J ]A J % % % % )G**";5%L(5!? J J % J J % J J 8> % J % % % )G**";58L(5!? J J % J J J % J 88 % % J % % )G**";59L(5!? J J % J J % J J 8> % % % J % )G**";5>L(5!? % % % % % J J J ]A % % % % J )G**";5@L(5!?                (P!?#$A&(S=";S   "# , ()* &/)IJ  *  J  *  J  *  J   > B KL.ML L L   < B   $).  )& 2   &$) * )  )+$+%%$$ *  )& $  "  $       ' , $*  )9[9"$ $     / ) /=9 + . -$ $  H >=9- C&" %!  + !% *&$) & $ &  * 'B N   )  " $  N  &  'P"   *&$) & $  /0*1%0*1&   ,-  & $    .  /9[9"  $ N +  9  90*1%/70*1    '    & $  *&$) #"  4+ . 5  0*1-  * &$) * ,':$ $)  *2$ D Ω=== 100 20 2 mA V I U R LED      "  $ $# M /70*1-+$   #"D mA mA I TBLED 20 8 160 _ ==  Q  $)    % D VmAV LEDLED 16100160 _ =Ω×=    "   %    %! %X+   ,%/,' Q*  $+$*  ) ">?8D "# , ()* &/)IJ  *  J  *  J  *  J   > B +8F  KL.ML L L   !"#$9E&M4/)0F(<="/'+012"'+3!& " #$%  ? :$* )  *  "  +%%$  9  &  )    $   % $ %    $+$C' ? R2$*)$$*   / )   $ %' ? R  $) $ '  &#$%  ? P $ $ % )&"+$*)   $ )"$ $  H   N *   N  .     $*  &     +  ! $  $)     ) 'I$    /00 )" .   .   )*"$ $     *2$ )& 2+ $# M /=/00-$ $  H# M =/00' " +P(Q.R) #L$Q R LQ R LQ R L RTRRR UQV) #L$Q  LQ  LQ  L S SSS P R2$+C   <# * ! $%   /-  "   $)  D  "# , ()* &/)IJ  *  J  *  J  *  J   > B KL.ML L L   >  [       [U    # B @ > 9 8 % J M),"+I J % 8 9 >  J J J J J J J %  % % % % % (D!?*";5JL(5!? J J J J J J % J  % % J % % (D!?*";5%L(5!? J J J J J % J J  % J % J % (D!?*";58L(5!? J J J J % J J J  J % % % J (D!?*";59L(5!? J J J % J J J J  J % % % J (D!?*";5>L(5!? J J % J J J J J  J J J J J (D!?*";5@L(5!? J % J J J J J J  J % % % J (D!?*";5BL(5!? % J J J J J J J  J % % % J (D!?*";5#L(5!?         \ J#    J#  (P!?#$E&U1+5**"+)=(5="8& ? (<#$ 0  <# * !  !1      )-   30 2X+$    30   ) &  !$)' ? (<#$ /  <# * !  !1      )-   3/ 2X+$    3/   ) &  !$)' ? (<#$   <# * !  !1      )-   3 2X+$    3   ) &  !$)' ? Z ? (  <# * !  !1      )-   3> 2X+$    3/   ) &  !$)' , $ .   "$ $      /=9$ $  H >=9' :$  N  *  % )  N   " $ $   &   H  *2$ & 2+ $' E   + .  !  N &" $ % * $ $  $ ! $)    )-  $ ) "  %$ $  $ !$)' B     % ). +$#  .  #   $" $   @(  %  ) *&$)  +  & $  R3W (T;G   &$)   ' 9 "1< 4G1 ?=B1 C 345P? C 5? C 5? C 5  (    "&C     ">?8& $+$ /'   (  "$+$$  !1D ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;chuong trinh hien thi ki tu chu A tren ma tran led dung yen ;ma chu A = 007H,0DBH,0DDH,0DBH,007H ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx hang equ p3 ;dieu khien hang cotx equ p0 ;dieu khien cot mau xanh cotd equ p2 ;dieu khien cot mau do org 0000h mov cotx,#0 ;tat quet neu co ket noi mov cotd,#0 ;tat quet neu co ket noi "# , ()* &/)IJ  *  J  *  J  *  J   > B +80  KL.ML L L  main: mov hang,#007h ;goi du lieu ra hang 1 mov cotx,#00000001b ;goi ma quet cho 1 transistor dan lcall delay mov cotx,#00h ;chong lem mov hang,#0DBh ;goi du lieu ra hang 2 mov cotx,#00000010b ;cot thu 2 dan lcall delay mov cotx,#00h ;chong lem mov hang,#0ddh ;goi du lieu re hang 3 mov cotx,#00000100b lcall delay mov cotx,#00h mov hang,#0DBh ;goi du lieu ra hang 4 mov cotx,#00001000b lcall delay mov cotx,#00h mov hang,#007h ;goi du lieu ra hang 5 mov cotx,#00010000b lcall delay mov cotx,#00h sjmp main ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;chuong trinh con delay nho ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx delay: mov r5,#10 de: mov r6,#20 djnz r6,$ djnz r5,de ret end (D'*(G-%9X3 ! $%+%*  $+$*  )9[9   $ 7P<< .  )',$%   "$/ 2$+C   '  &      %8AA#X   1 5=4 3 P 5 5 5  ` ?$* #)%*$ $              $+$ $ $ -&C* C  /#)%*$ $   &  N & $ $   #$%   %&$ $   / )$   $    - )% & )         $  O    $O $ $ -  ) %   $     $ $   .   # & $ $  $- $$* $   C$  )  $-*$ )        #)$ $   -.  !  ""#    %     *.    #)%*$ $       "#    $ $%& $@( $ $    GQ/(99> ! G   O %' + ""1@>  @  @  @ "=AAAA 4 3 >+00,P ( %   ` ?$*#  *D "# , ()* &/)IJ  *  J  *  J  *  J   > B KL.ML L L    ? ( @(  C & $R(/79/9P& GQ/9>' ? G !$)+ #* % +  /0 N*+      % @(' ? C #  $&   ) ' ? P)%* $  - - $-    -  -  - N*   $ %/00' ? (  %$ $   "  P(G A  ' ? ( * ) D*/ $& * $' ? (    +%%$+$R & @' ? B #  & # !$)$%+$)*  @(' ? (  /9 #     `1RD     / #         &    $ $ +$-//#   $  *#) `1R...  !"  ( RJ        N     $ !  $ $#' • :$  %$,((-#$R      ' • :$  %$O% IEG A #% "#$@     ' (   $)+ O% #    $ & +  0:' "#$"% $& ( Qlh    O %   / C$)  /8  $ C $)      %#$ #) $ /< %#   ` $*( +'  %    Qlh   $# M   )"   $1  !"#   #  >?/0' C$)Qlh  * A  H  #$QlhF ` $P'C$)Qlh+  O %$)+$,  %'<&' "# , ()* &/)IJ  *  J  *  J  *  J   > B KL.ML L L   80/   (P!?#$%J&(5=*")N!?L),*H!"'+G1!?)S:(MUV& "" '(  !&  )O  %  'Q O%   1Q=1;F *   # % $#   GQ/(99>'Q $%+$O %$)#1Q! O   # %  %  (Q      + ' " " ')( ( GQ=`G  +$     ) & *     RJ' :$  RJ  +%%$, -#$R      ' +$   GQ O    +  $ $   $   + #&    $ G  Q#'   +  -C$)GQO $ $ GQ/(99>O % !$)'   +  $-O  GQ!$+$GQ/(99> % !$) $& # ' :$  RJ  %$O% IEG-#$@     ' +$  -   GQ   $  ` 4RD 5' RD O  + +$GQ/(99>$+$#  ! $)'C $)RD !   O* C$)JF #4OE 5   %   #) ' WR / )$ ( (  WR / !     ) ' :$  RJ   +%%$ ,   %) $R - "* $)      WR /  O  + $) $  +   A  $' (+  $$   WR /  $*  +$  GQ*  ' (+  $$$   WR /  $*  % %. " %C$)  GQ' :$  RJ  %$IEG  %)$@-C$) WR /  C$) )  C   *  %    $ WR '  %)  -   WR /    d  C$) h$F #4WR 5    #) `1R' CS  *  "   (  C $)     C    *   %       O % GQ/(99>'CS  $   $C    +  $ $ GQ& 1Q   %)$ R  &    % RD  & WR    % )  $ @'(  + P O    *  CS  +    $C   "+     O %' :$$)     %,  %'!+     O % !$)# M  +   $+$  CS  M*# &) !$)   $ $   #  !   !$)`1R %. " +    * % ' "# , ()* &/)IJ  *  J  *  J  *  J   > B 97+  KL.ML L L  ()# (  )%   (  IRQ     !   C   *   %  GQ/(99>  #  H  $#)O   'E !  IRQ *   %+$#$    $$  HO %$)  & $#$   H    * /'BO    IRQ "&$O   $$%     $( A  ) %RESET ' :$+ $  H" IRQ    $  XO* *  'E$$%#  H  %$ $*) IRQ #'C$) IRQ & $ !    $ /$) + #  $' RESET ) ( (  RESET +    % - - A  `1R'ef %) % -   RESET    #+ O%  $ $       %'$ $ *    RESET #+ O% *  %) &    ' $ %  RESET      %) % -$ $  RESET *  %  & .  00*  H   H#)$# GQ/(99> %)Y? !%':$ RESET  *  %&     %,(('<&- ! $ $2 D ' P$   H+ 44T$$ @F #4TF@55   A* 0' #' P$   H  41 *@F #41@F55   A* 0' ' P$    H +%   ) ) 44b F @S  4bS55   O &0W' ' P$    $   H4@`.Q S 4@`lS55   A*  0' ' P$    H+ 4T$$ @S 4TS55   A* 0' m' $%#+       $+$  RESET  $*  $ /' ' P$    H  41 *@S 41S55   A* 0' ' (  IRQ     $  ' $' P$  O %  & 4Q. h &JF #4QlhF55   A* 0' n' P$   H+%   ) )4b F@F #4b@F55#O  &* 0'            RESET     %$,((':%%$ & ) !  GQ/(99> ) & +$* % !+  *   %# %+    $ $+$ ' D 1-5"=A4 - 5 A- 5 A- 5 A O3 ""BB1" =?12"B13  5P ? 2 5 ? 2 5 ? 2 5  (  N    $ $   !$%  ) &  % `1R-$ $ - &  $ $ #  $&  ! &  !+ * % !$)# %  %$)  !& ,((' :$$) ,((     % GQ/(99>&   $$)  '<&-$%#       00*- )      %-   #) )  ) &  . " ) +    #$   RESET '$%)%  !$&   +$      %' :$,(( O%   $'<&- !&    CS ## H#)        $ +  ) # %  % $  $ !&   CS ?+$ GQ/(99>   )  %) %  $':$GQ/(99>     $ %  $-*$ !& ##.    !     $  ' "# , ()* &/)IJ  *  J  *  J  *  J   > B KL.ML L L   808 :$,(( O% $) +  8&-$) ,((   %#  $   H$&   $ $$$* #  GQ/(99>!   %  ` $*( +& #)  `1R' P     GQ/(99>  "#  ">?/'   !"#$>%&)3=";5=O)G!"45O+N!*:)!?=1P(+(6$*'F+M%8AA#& P   #  *//# `1R  -/# `1R#  *  $ $   - - !$)#  $&   $     &$) $+$&  # "   ' % /9#      $ A    $%  !    D    $( G  $  $  '  P$ >    $1 #$  '  P$   #   #$  ' (  %&$ $ &      # M    #     '$ $ -  & #  $   $ A A +$ # M   $ $ # `1RC ' E)$   /0#   $ $ - & #  $    /     4P$  5 A P(G4P$  (G $* 5'   +$ $  !$)&   $ $ - -&    $#  $# " #$QF  $P $  $% )*  $ / N  A&$)  ) )  O     . " O %' E  $  $/0  $ $ $ - -&   $#  $*)   !    4P(G  5 "#$ +$ ! $)4G  *XGR5     $P $    A*  $ C '  % /0# $ $ - & #  $ $    +$ !$)'T $O #$QF    $P +$  $)O &$)  ) )$ $   - &  $' "# , ()* &/)IJ  *  J  *  J  *  J   > B 97D  KL.ML L L  R2$  +$) -  $ $     ) )  %    $*)+$ !    'G !$)!+  $%+ +$)  $/0#  !$)' P  >?//"#     & P(G   $ $ - -& #  $'  (SQ6;<(=")<!W(="C ";5=!(b!? '(5*:W *"(G--"(N! "W-"(N!  J '(NQ J$@E JJ$9 JJ$@E % '(NQ"+<! J$@E JJ$9 JJ$@E 8 "15* J$@E JJ$9 JJ$@E 9 "15*"+<! J$@E JJ$9 JJ$@E '4DXF)7+%8?'4D %$%8 J%$J A%$A J%$%8 A%$E8> '4DXF)7+8>?'4D J$89 JJ$%# JJ$89 '4D"+<!X%8?'4D %$%8 J%$J A%$A J%$%8 A%$E8@ '4D"+?'4D J$89 JJ$%# JJ$89 B ?(DQ=1P(*1(0!="1P!"(G*c% %$# J%$J# J%$J# # ?(DQ=1P(*"(5!? %$9% J%$%] J%$9% A "(5!? %$%8 J%$J J%$%8 E (bF J$EE JJ$B9 JJ$EE  (P!?#$%%&(5=/W!"7(<!?=1P(=(5=*")N!?L),*"4D'?'(!& P$   +$=/+  $%+ +$)  $  $ $':$   / $     -#$   #  $O TR+$    A*  $ /'R2$ $  *) -//#    ) )& +$* "  #  $' E%)  !$)$ $ &  $2  . " ) )-*)& % $   $- - $  -Z   +  CO 'i O % +  CO  ! $)$ $ &     % %'( & $     $%   O   +$ $ $ &     ) ' 8# #  $    # M  D   &D+$$ $ #  $   $&    $ $- - $  - ) #  $  # H  $$ $  CO    +$#$  #      A*  '       A   $# %  %& *) A $# #   'R ! # %  % # %+ * !%O  M*  $  (0%SS'3 $#$RQP   ! #   A&      $# %  %+$*   $ /'P  $!  $ *2$ $+$#$# %  %    A& #  $'   -#  $!$ *2$ %* !# %  %   #  $&  #  'E%* !# %  %     8# #  $ "  !    C$) H*2$ $  ' E 1-5"=A""111 ?=B1 CP- 5 A  ? C- 5 A  ? C- 5 A  ? C  GQ/(99>    $$+$    *$ +  . " ) )'   M       M "# , ()* &/)IJ  *  J  *  J  *  J   > B KL.ML L L   80< # B @ > 9 8 % J  8 % J M9 M8 M% MJ  +(,b @T 4b@T5 #$    $  !$  ' :$#$b@T* /"  . " ) )O      ' :$#$b@T* 0-. " ) )!+ O    +  $ $ C %  µ'E !  $&$ $ - -& #  $ `1R  $)   &$)   )+$#$ b@T* 0' P$b@T #$  & + #        RESET ':$ $#$QF  $P /! N  A*$. " ) )& O   #$   $b@T' -./8#$      * A  H#) ) &  $ A $. " %*O% ':$\G,G,/G,0]^\0/0]     N   %  # )#) ) &    `(%*$ $ ':$\G,G,/G,0]^\//[]!   )    $ !. " %*O% * 'l " ) )$%!$2  <00*+$+$0/0   $ & G,0-G,/& G,' )"0)"-)".)"#$   % )  *) /8 $  #) $ /<     $ A +   O % C$) $     $'; $               & 4  Qlh5& = A  H + 'E $      /   !   D  (  H& $#$T@F  ( O % !   Qlh& $#$QlhF  (   $ )   *) &   *) $'  : +C    P  >?/0$)+ +  H&  %  & *      & $#$`Q'( #$  = $+ #   #$  `FQF'  ;  M       M # B @ > 9 8 % J M    MUV  8>d%8 M  "1!/:$#$QF* 0-   . " ) )# M   N  $ %*/  / $  ':$#$QF   $& * /-*$. " ) )# %*'(  +       $  *)+$'P$QF #$ = $& +        A      N #   GQ/(99>' ,(1/,  (  1' P$   H +  #$ = $-#$     #$  H + 4TS5   $($+$   IRQ O% *  %' :$#$T@F   A * /- +   H       # M  $+$   IRQ  O% *  % ) & ) #%  #$`Q8c`Q0  $1' :$#$T@F^0! N  AC$) !  IRQ +$&$) $+$# M  H +    #$  + TS& 2$% )% )  + ' "# , ()* &/)IJ  *  J  *  J  *  J   > B 97F  KL.ML L L  P$T@F+       ) #   GQ/(99>  #O &0+$  ?$*#' (1/ 2(  1' P$   H#  $ #$   = $-+$#$ 1@F# M /!  #$ #  $41S5  $( C$) H IRQ ' C$) H#  $O    %   $  +$ 8# #  $  * !#  $Ko L  $)#    //iiiiii' (    N #   GQ/(99>+ #   #$#$1@F' +(1/+  1(  1' DP$  +% . " H ) ) #$  = $-#$     +%  ) )bS  $(+C  H IRQ ':$ ?$*#  A   QF* /!O #$b@F' "#$1XQ. h &F #D:$#$QlhF   A* /-*)C$)  &    %     #$ #$`Q8%`Q0!O %   Qlh':$#$QlhF   A *  %-  Qlh!   $ !*  %'QlhF #$ = $&   O +$ ?$*# `FQF' / P$+$ !$)GR. +$ " $ & $ $      A P(G'P$GR   A#$   "    C &     +$    'P$  + # $#$  ) #    ?$* A  +$#'R /  GR!   !$)  * 0!   !$)P(G' -3.-/P$$+$=/O +$  #  $':$* /"   %) $ $- * 0"  %)$/ $'P$   #$  $& + #   #$ ) #    ?$* !  +$ ?$*#' "1/4 5* "& 51' DP$     + $GQF #$ p $' P$     ) ) A #$)+$GQF   A/' , (E )   $      - +$ $ $   N  % $   /D<D<1R " ! $  8D00D001R' , (E ) %$      /0-+$$ $   $ %/D<D<1R"  !$ /D00D001R' (  N  A #$)  !+     $%#$GQF* 0'P$  + #    #$  ) #    ?$* !  +$#'  "  M       M # B @ > 9 8 % J U] ] ] ] J J J J  ()#6/@`.S DP$    H   A/+$ *)  !  $  $  D  TS^T@F^/  1S^1@F^/  bS^b@F^/ B$    d  @`lS^4TS'T@F5g41S'1@F5g4bS'b@F5 "# , ()* &/)IJ  *  J  *  J  *  J   > B KL.ML L L   80> P %   #$@`lS   A/-   IRQ   + &*  %' %   # O  +$  $(   #$   " A +$ ?$*#' ,6/T$$ @S DP$  H +  #$  -%#$     A * /+$  / O    $) C$)     #) $ '( #$`Q8%`Q0 $% )% )  + '(TS   A/+ ) &    $  #$T@F' :$ TS& T@F* /-C$) IRQ !       $C   & ! A#$ @`lS* /'P$TS!#O #$ ?$* A #$)   $(' 6/1 *@S D%1S^/!O $ $ $) $ & $$ $  $'E%#$1@F ! * /-   IRQ !O% *  %& #$@`lS!# M /'P$1S!# O #$ ?$* A #$)   $(' +6/b F@S DP$  H+%  ) )   *2$ +  )  )':$#$b@F  /-* /bS! * #$@`lS* /!+C  IRQ #  H' P$bS!#O #$ ?$* A #$)   $(' !78' 09:' B    ! #$+       $   $('E ! #$   * 0& +  $'    M       M # B @ > 9 8 % J  J J J J J J J  )!/ )! 2P$$ $ & `1R  $)   #$%"    $   +%%$  ,P1'P$  +    $  & +$    $ # M /'E% +$ #$  * 0"! #$%  N   $$*#  ! &   $  %$ $   &  !$)`1R   $'P$  +     #$  `FQF' (!;<1=(!/E ! #$     )      $G+       ' (  +  $  & +$ "   $ # M 0' F 3-"1   ?=B1 C 4 - ? C - ? C - ? C  O3 P R   $ $%&$$+$& $ ?$*GQ/(99> ">?'   &$$ +$  $ $%& $/ ?$*& $* C "#    $ $%       % "&$ $+$ $ $ $%& $$   +  ") % * $ ) &C $ $% *>  A ;(G* $$    %$ $ ' "# , ()* &/)IJ  *  J  *  J  *  J   > B 970  KL.ML L L   !"#$>8& '()*'+,-.'/'+012"'+3!.45'+(6$*'F+&  *  $)">?-&$$+$ $ $%& $ ?$*+$#)  !$)-&$ $+$  ) $ $%& $#)  !$)*) #  $D • ;)  !$)D K*&O -qL 4/5 • ;)O % !$)D K*&Oq- L 45 • ;)  !$)D K*&O -q`$L 485 • ;)O % !$)D K*&Oq`$- L 45 3 $)4/5& 45      +$   #) *)  <7# -   $  #  '3 $)485& 45    +$   #)   # M <7# -+    $+$ $%#+ ', )        )485& 45' , "1< 4G1B1 A-4 A -A -A - O3 P R   $ $%&$$+$& $ ?$*GQ/(99> ">?'E% ?$*       " $      "+$ $% )   $$) $  ?$*&     / '    "#  $  %K $ $ $L-K$ $L& K $$ $L    %$ $ $) $+$+$) ' (  "+$   ?$*D org 0000h mov r0,#0bh ;dia chi cua thanh ghi B mov a,#0 ;du lieu nap vao thanh ghi B movx @r0,a ;cho phep chinh cai dat gio mov a,#giayhientai mov r0,#0 ;dia chi cua o nho giay movx @r0,a ;nap giay hien tai "# , ()* &/)IJ  *  J  *  J  *  J   > B KL.ML L L   80 mov a,#phuthientai mov r0,#02 ;dia chi cua o nho phut movx @r0,a ;nap phut hien tai mov a,#giohientai mov r0,#04 ;dia chi cua o nho gio movx @r0,a ;nap gio hien tai mov r0,#0ah ;dia chi cua thanh ghi A mov a,#020h ;tu dieu khien cua thanh ghi A movx @r0,a ;cho phep bo dao dong chay lcall delay50 sjmp $ ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx delay50: mov 7eh,#0fh del12: mov 7dh,#0ffh del11: djnz 7dh,del11 djnz 7eh,del12 ret ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx end (  "&C     " % &$$+$- $*& ;(GD    "  &$$+$+%%$& $ $*  & 8#$$+$  /' ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;chuong trinh dieu khien LCD hien thi chuoi thong tin ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;dinh nghia cac bien E BIT P1.0 rw BIT P1.1 rs BIT P1.2 byteout equ p2 dklcd equ 70h bdn equ r6 giay equ r5 phut equ r4 gio equ r3 org 0000h mov sp,#68h ; lcall khoitao_rt ;goi chtr con khoi tao real time lcall khoitao_lcd ;goi chtr khoi tao LCD lcall xoavnh_hthi ;xoa vung nho hien thi main1: lcall doc_gpg ;doc thong so gio-phut-giay tu real time lcall bcd_maascii ;chuyen so bcd sang ma ASCII lcall hienthichung ;goi ra LCD de hien thi sjmp main1 ;tiep tuc ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;chtr con doc gio phut giay ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx doc_gpg: mov r0,#00 movx a,@r0 mov giay,a "# , ()* &/)IJ  *  J  *  J  *  J   > B 97  KL.ML L L  mov r0,#02 movx a,@r0 mov phut,a mov r0,#04 movx a,@r0 mov gio,a ret ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;chtr con chuyen so bcd sang ma ASCII ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx bcd_maascii: mov a,giay anl a,#0fh add a,#30h mov 4fh,a mov a,giay anl a,#0f0h swap a add a,#30h mov 4eh,a mov a,phut anl a,#0fh add a,#30h mov 4ch,a mov a,phut anl a,#0f0h swap a add a,#30h mov 4bh,a mov a,gio anl a,#0fh add a,#30h mov 49h,a mov a,gio anl a,#0f0h swap a add a,#30h mov 48h,a ret ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;Chuong trinh con hien thi noi dung tren LCD cua2 vung nho ;40H->4Fh hang 1 ;50H-> 5Fh hang 2; ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx hienthichung: mov A,#080h ;set DDRAM lcall ktao mov r1,#16 mov r0,#40h ;bat dau tu 0 fline: lcall Write djnz r1,fline mov a,#0c0h ;set DDRAM lcall ktao mov r1,#16 sline: lcall Write "# , ()* &/)IJ  *  J  *  J  *  J   > B KL.ML L L   8// djnz r1,sline ret ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;chtr con goi data hien thi ra LCD ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx write: mov a,@r0 write1: mov byteout,a lcall data_byte inc r0 ret ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;chtr con khoi tao LCD ;chuong trinh dieu khien LCD 16X2 tren kit vi dieu khien LOAI NHO ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx khoitao_lcd: mov dklcd,#0 lcall khtaolcd ;khoi tao lcd ret ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;chtr con khoi tao LCD ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx khtaolcd: setb e ;Enable clr rs ;RS low clr rw ;RW low mov a,#38h ;tu dieu khien LCD lcall ktao lcall ddelay41 ;delay 4.1 mSec mov A,#38h ;function set lcall ktao lcall ddelay100 ;delay mov A,#38h ;function lcall ktao mov A,#0ch ;tu dieu khien display on lcall ktao mov A,#01h ;tu dieu khien Clear display lcall ktao mov A,#06h ;tu dieu khien entry mode set lcall ktao mov A,#80h ;thiet lap dia chi LCD (set DD RAM) lcall ktao ret ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;chuong trinh con khoi tao LCD ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ktao: mov byteout,a lcall command_byte ret ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;Feed command/data to the LCD module ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx command_byte: clr rs ;RS low for a command byte ljmp bdelay "# , ()* &/)IJ  *  J  *  J  *  J   > B 9+  KL.ML L L  data_byte: setb rs ;RS high for a data byte bdelay: clr rw ;R/W low for a write mode clr e nop setb e ;Enable pulse nop nop mov byteout,#0ffh ;configure port1 to input mode setb rw ;set RW to read clr rs ;set RS to command clr e ;generate enable pulse nop nop setb e lcall ddelay100 ret ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;chuong trinh con delay 4.1 ms ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ddelay41: mov 7eh,#90h del412: mov 7fh,#200 djnz 7fh,$ djnz 7eh,del412 ret ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;chuong trinh con delay 255 microgiay ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ddelay100: mov 7fh,#00 djnz 7fh,$ ret delay1giay: mov 7ah,#20 xx2: mov 7bh,#0 xx1: mov 7ch,#0 djnz 7ch,$ djnz 7bh,xx1 djnz 7ah,xx2 ret ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;chuong trinh con khoi tao real time ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx khoitao_rt: mov r0,#0bh mov a,#0 movx @r0,a ;cho phep chinh cai dat gio mov r0,#0 movx @r0,a ;giay = 0 mov r0,#02 movx @r0,a ;phut = 0 mov r0,#04 movx @r0,a ;gio = 0 "# , ()* &/)IJ  *  J  *  J  *  J   > B KL.ML L L   8/8 mov r0,#0ah mov a,#020h movx @r0,a ;cho phep bo dao dong chay lcall delay1giay ret ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;chuong trinh con xoa vung nho hien thi ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xoavnh_hthi: mov r0,#40h mov a,#' ' xoac: mov @r0,a inc r0 cjne r0,#60h,xoac ret end (D'*(G-%>X3 ! $)  $   "      % -  -  - N* $;(G'  & eX       "#   $ $%&$$+$& $ $%#  $&$ #         )% $+$  %' R))% $+$ ) & * )  * *   $ $%& $$$%# +  -     "#     $  -  $  &  M  +$$       $   $   $%+% )%  $ $%  '   ) )    

Các file đính kèm theo tài liệu này:

  • pdfbai_giang_giao_tiep_ung_dung_vi_dieu_khien.pdf
Tài liệu liên quan