+ All Categories
Home > Documents > Vxl Chapter 07 Giaotiep Ungdung Vdk

Vxl Chapter 07 Giaotiep Ungdung Vdk

Date post: 15-Apr-2018
Category:
Upload: hoangtuongckd08
View: 222 times
Download: 0 times
Share this document with a friend

of 67

Transcript
  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    1/67

    !!!! "#$%&'()*"#$%&'()*"#$%&'()*"#$%&'()*

    ++++ ,-,-,-,- .(,/*.(,/*.(,/*.(,/*!!!! "#$%.(,/*"#$%.(,/*"#$%.(,/*"#$%.(,/* ).(,/*).(,/*).(,/*).(,/*(((( """"#$%&'()*.(,/*#$%&'()*.(,/*#$%&'()*.(,/*#$%&'()*.(,/*

    12"+13112"+13112"+13112"+131++++

    345163345163345163345163

    "7078"7078"7078"7078++++ ",78",78",78",789999 "7070"7070"7070"7070

    4:4:4:4:++++ 5";

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    2/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    +D0+D0+D0+D0 KL.MKL.MKL.MKL.M

    9999 "1"=A43""1@>"=A43""1@>"=A43>>>>+00,+00,+00,+00,9999 >?"1@H"1?"1@H"1+00,"1@"=A43>+00,"1@"=A43>+00,"1@"=A43>+00,DDDD 1-5"=A43B13=?HB1"5

    1-5"=A43B13=?HB1"51-5"=A43B13=?HB1"51-5"=A43B13=?HB1"5

    EEEE 1-5"=A""111?=B1C1-5"=A""111?=B1C1-5"=A""111?=B1C1-5"=A""111?=B1CFFFF 3-"1?=B1C43-"1?=B1C43-"1?=B1C43-"1?=B1C4OOOO3333,,,, "1I>&!"#$%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"'[email protected]'#%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)(

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    3/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    KL.MKL.MKL.MKL.M

    !"#$9>&(8&'()*'+,-.'/'+012"'+3!.45'+(6$*'F+&

    (P!?#$%&(SK1+5*/'+012"'+3!6+7&(P!?#$8&(S#/)(

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    4/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    +E7+E7+E7+E7 KL.MKL.MKL.MKL.M

    & X

    PPPP PPPP!"#$$%&$'

    (%$)*&$)+,-.+/0%0*1'

    %*&$)*2$!&$$+$"+$!*345$%+/061%7061%$&$/--8&+9061%90061%$&$0':$!*;&4$+5+/?/#@()*>

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    5/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    KL.MKL.MKL.MKL.M 0 '

    +$&$$+$)&+%%$A+$)+$"%$)+-%+"#"#$*+%%$'

    !!!! "#$%&'()*P"#$%&'()*P"#$%&'()*P"#$%&'()*P,$">?-!&$%"$+$8HD

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;chuong trinh dieu khien 32 led chop tat;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    org 0000h ;khai bao dia chi bat dau cua chuong trinhlb: mov p0,#00h ;sang 8 led cua p0

    mov p1,#00h ;sang 8 led cua p1mov p2,#00h ;sang 8 led cua p2mov p3,#00h ;sang 8 led cua p3lcall delay ;goi chuong trinh con delay

    mov p0,#0ffh ;tat 8 led cua p0mov p1,#0ffh ;tat 8 led cua p1mov p2,#0ffh ;tat 8 led cua p2mov p3,#0ffh ;tat 8 led cua p3lcall delay ;goi chuong trinh con delaysjmp lb ;lam lai tu dau

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;chuong trinh con;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxdelay: mov r6,#0ffh ;nap hang so delay FFH vao thanh ghi r6de : 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

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    6/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    +E++E++E++E+ KL.MKL.MKL.MKL.M

    djnz r6,de ;giam thanh ghi r6 di 1 va nhay khi r6 khac 00ret ;thoat khoi chuong trinh con

    end

    ,$">?-!&$%"$+$8&HD;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;chuong trinh dieu khien 32 led sang dan len va tat dan;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    org 0000hmov p0,#0ffh ;tat port 0mov p1,#0ffh ;tat port 1mov p2,#0ffh ;tat port 2mov p3,#0ffh ;tat port 3

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;dieu khien sang dan len;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxlb: 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 traimov p0,a ;chuyen noi dung port0 vao thanh ghi Amov a,p1 ;xoay noi dung p1rlc amov p1,amov a,p2 ;xoay noi dung p2rlc amov p2,amov a,p3 ;xoay noi dung p3rlc amov p3,a jc lb ;thuc hien tiep khi C=1

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;dieu khien tat dan

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxlb1: lcall delay ;goi chuong trinh con delay

    setb c ;lam cho bit C = 1mov a,p0 ;chuyen noi dung port0 vao thanh ghi Arlc a ;xoay noi dung thanh ghi A sang traimov p0,a ;chuyen noi dung port0 vao thanh ghi Amov a,p1 ;xoay noi dung p1rlc amov p1,amov a,p2 ;xoay noi dung p2rlc amov p2,amov a,p3 ;xoay noi dung p3rlc a

    mov p3,a jnc lb1 ;thuc hien tiep khi C=0sjmp lb ;sau khi 8 led sang het thi quay lai tu dau

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;chuong trinh con delay;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxdelay: mov r6,#0ffhde : mov r7,#0ffh

    djnz r7,$djnz r6,deret

    end

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    7/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    KL.MKL.MKL.MKL.M "$$$%&$$+$&$D

    ? I$$%$%D+$!/&$$+$+%%$&$>$1">?8':$9@J'

    ? I$$%$$%D+$+%%$&$@($$*!>">?':$@J'

    Y1

    VCC

    R2330

    C

    10

    R4330

    RESET

    R8330

    R5330

    LED1

    45

    976

    21

    1038

    a

    bcde

    f

    gdpA1A2

    VCC

    R6330

    R1330

    AT89S52

    2122232425262728

    17

    16

    2930

    11

    10

    31

    19

    189

    3938

    373635343332

    12

    345678

    1213

    1415

    P2.0P2.1P2.2P2.3P2.4P2.5P2.6P2.7

    RD

    WR

    PSENALE/P

    TXD

    RXD

    EA/VP

    X1

    X2

    RST

    P0.0

    P0.1P0.2P0.3P0.4P0.5P0.6P0.7

    P1.0/T2

    P1.1/T2XP1.2P1.3P1.4P1.5P1.6P1.7

    INT0INT1

    T0T1

    R3330

    R

    10k

    R7330

    !"#$9&'()*'+,-*:;

    (N1")P'%X(SQ=")O'+,*;12"1Q+,*/'+3F=1P(8=(5="?'()*'+,-.'/'+012"'+3!.45'%6+7#/)(

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    8/67

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    9/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    KL.MKL.MKL.MKL.M ?-&$%"$+$/>%*0%'

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;chuong trinh dem len tu 0 den 9 hien thi tren 1 led;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    dem equ r2led equ p1

    org 0000h ;bat dau chuong trinh

    main0: mov dem,#00h ;dem=00main1 mov a,dem

    mov led,a ;goi ra led hien thilcall delay

    inc dem ;tang gia tri demcjne dem,#10,main1 ;ss dem voi 10ljmp main0 ;lam lai tu dau

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;chuong trinh con delay;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxdelay: mov r5,##0ffhloop1: mov r6,#0ffh

    djnz r6,$djnz r5,loop1ret

    end

    &C"$%&C8*$)!@($$*!>"+$$%$$*!-$*!P(G'

    ).(,/*).(,/*).(,/*).(,/*PPPPB*.&$$$%$+$$>"+%%$

    .'Q>">?

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    10/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    +EF+EF+EF+EF KL.MKL.MKL.MKL.M

    ] % % % 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%&%O1%S"##>?D

    M),"+I 7- ? ^ + 7 = O ( (SL),"+IJ % % J J J J J J J% % % % % % J J % ]E8 % J % J J % J J >9 % J % % J J J J J> % J J % % J J % EE@ % J J % J J % J E8B % J J J J J % J A8

    # % % % % % J J J ]%A % J J J J J J J AJE % 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#/)(

    (*!+$%)'

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    11/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    KL.MKL.MKL.MKL.M

    VCC

    b

    R10

    10k

    LED5

    45976

    211038

    abcde

    fg

    dpA1A2

    fa

    LED2

    45976

    211038

    abcde

    fg

    dpA1A2

    LED0

    45976

    211038

    abcde

    fg

    dpA1A2

    c

    LED3

    45976

    211038

    abcde

    fg

    dpA1A2

    LED6

    45976

    211038

    abcde

    fg

    dpA1A2

    d

    Q2A564

    g

    Q5A564

    gf

    p27

    p24

    dp

    b

    e

    R13

    10k

    p

    b

    R8330p

    P23VCC

    p pc

    c

    f

    c

    b

    c

    d

    a

    g

    LED1

    45976

    211038

    abcde

    fg

    dpA1A2

    p

    p22

    VCC

    c

    P24

    p26

    gp

    db

    p25

    C

    10

    R6330

    g

    VCC

    c

    a

    d

    R16

    10k

    d

    R5330

    e

    R15

    10k

    Q7A564

    d

    a

    P25

    p21

    RESETVCC

    g

    Q3A564

    bf

    g

    R1330

    e

    LED7

    45976

    211038

    abcde

    fg

    dpA1A2

    e

    P20

    p23

    R10k

    VCC

    f

    AT89S52

    21222324252627

    28

    17

    16

    2930

    11

    10

    31

    19

    189

    3938373635343332

    12345678

    1213

    1415

    P2.0P2.1P2.2P2.3P2.4P2.5

    P2.6P2.7

    RD

    WR

    PSENALE/P

    TXD

    RXD

    EA/VP

    X1

    X2RST

    P0.0P0.1P0.2P0.3P0.4P0.5P0.6P0.7

    P1.0/T2P1.1/T2X

    P1.2P1.3P1.4P1.5P1.6P1.7

    INT0INT1

    T0T1

    R2330

    R14

    10k

    d

    Q4A564

    p

    d

    LED4

    45976

    211038

    abcde

    fg

    dpA1A2

    b

    VCCP26

    R11

    10k

    R7330

    b

    R17

    10k

    Q1A564

    a

    c

    e

    Y1

    p

    R12

    10k

    f

    P21

    p20

    fR4330

    a

    Q6A564

    e

    a

    gf

    e

    VCCVCC

    b

    e

    P27

    c

    R3330

    VCC

    e

    a f

    Q0A564

    a

    g

    P22

    !"#$@&'()*'+,-.'/'+012"'+3!.45'A6+7#/)(

    ">?

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    12/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    +E0+E0+E0+E0 KL.MKL.MKL.MKL.M

    ">?7@(>>&$$$*!%P(G*!>-@(>/89N$$*!89$+$9 $'Q%$+$>'

    >$+$/"&$$+$!#$%$*!P(G@($$*!$+$>-8#$$%$+$@($$*!/$2'BC$)T/'>$+$@(>/89D+$*%$"T/'>$*0-+$%*"T/'>$*3'

    .9"$$/#M/=9+.-$$H#M>=9+.'G$$H+$&$$$$."*$"%%'

    ,$U+&HU+"%*H"%$4*H5%$V03W'

    ,$9>."%.%$V703W'

    D&$*&$)#"4+.5 mAILED5

    = -*&$)* VVLED

    8.1= ':$$)*2$D

    =

    =

    = 5505

    45.08.15

    mA

    VVV

    I

    VVVR

    LED

    OLLEDCC

    BT

    D"$$#M0*1X%9'BN"DNA$*$)'B&$$)*&$) $)$*$)&$)C$D

    =

    =

    = 75,6840

    45.08.15

    _mA

    VVV

    I

    VVVR

    QUETLED

    OLLEDCC

    Quet

    ,)$)$*&M**&$79 %0M*N*)&).'

    (N1")P'8X(SQ=")O'+,*;12"1Q+,*/'+3F=1P(8=(5="?'()*'+,-.'/'+012"'+3!.45'A6+7#/)(

    (((( "#$%&'()*"#$%&'()*"#$%&'()*"#$%&'()*.(,/*.(,/*.(,/*.(,/*PPPP,C

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    13/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    KL.MKL.MKL.MKL.M

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    14/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    +F7+F7+F7+F7 KL.MKL.MKL.MKL.M

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxdelay1: mov r7,#0fh

    djnz r7,$ret

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;khai bao ma 7 doan tu so '0' den so '9';xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxma7doan: db 0C0h,0F9h,0A4h,0B0h,99h,92h,82h,0F8h,80h,90h

    end

    (D'*(G-9X3!&$%"%*$">?7'

    (D'*(G->X3!&$%"%*$*'

    (D'*(G-@X3!&$%"%*$$*'

    & X

    12"+=1P12"+=1P12"+=1P12"+=1P*)%)%$+$%C*%Y$$

    $%$!$& $%#$+$&C*&$C-*C$#C*)!$)*!-$-Z%%%CX+/%&$"+%%$/%$%&$/!&">?>D

    RESET

    VCC

    SW1

    R210k

    R110k

    AT89S52

    2122232425262728

    17

    16

    2930

    11

    10

    31

    19

    189

    39383736353433

    32

    1234567

    8

    1213

    1415

    P2.0P2.1P2.2P2.3P2.4P2.5P2.6P2.7

    RD

    WR

    PSENALE/P

    TXD

    RXD

    EA/VP

    X1

    X2RST

    P0.0P0.1P0.2P0.3P0.4P0.5P0.6

    P0.7

    P1.0/T2P1.1/T2X

    P1.2P1.3P1.4P1.5P1.6

    P1.7

    INT0INT1

    T0T1

    C1

    C

    SW2

    VCC

    R1R

    Y1

    !"#$#&'()*'+,-.'/'+012"'+3!.45'8!15*!"(,!&

    :$%"!&%*$3-+$%"!*!*$;'">?>-%%$%!&T'0&T'/&$$+$'("!+$*$$*$&$&$)&$%'

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    15/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    KL.MKL.MKL.MKL.M 7/

    ,$&$$+$"*$/$)++$%&$*++CN%+$)+"+)'

    ("$+$)G(%Q&Q';$+$"">?9D

    !"#$A&;1/)0/'+012"'+3!&

    I$$CDRA$+$%$)")-+$*C*Q%+D

    %+%"$%-%%")':$*O*%C*Q+D%+%")$%-%%"+%".*$'

    ("&$%D;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;chtr dieu khien dong co: khi nhan nut start thi dong co quay;khi nhan nut stop thi dong co ngung;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    start bit p2.0 ;phim sw1stop bit p2.1 ;phim sw2dk_dc equ p1.0 ;ngo ra dieu khien dong co

    org 0000hmain1: clr dk_dc ;cho dong co ngung;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;chtr con dieu khien dong co quay thuan;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    jb start,$ ;cho nhan start jnb start,$ ;cho buong nut nhan

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    16/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    +F++F++F++F+ KL.MKL.MKL.MKL.M

    setb dk_dc ;cho dong co chay

    jb stop,$ ;cho nhan stop jnb stop,$ ;cho buong nut nhansjmp main1

    end

    3$%+%%$&$!&'P$T/'0T/+%%$$+$)'

    ++++ 3451?=163P3451?=163P3451?=163P3451?=163P:$%%$&C/7C*-0C*-A$#C**

    C"$+%%$+$*)$*#%+%%$'Q+%%$&$$+$&$/7%">?'

    VCC

    SWC

    SW5

    C3

    H0SW4

    SW7

    SW8

    SWA

    R2 10k

    H1

    SWE

    SWB

    SW1

    C0

    H2

    R0 10k

    SW3

    SWD

    C2

    R3 10k

    SW6SW2

    SW0

    C1

    R1 10k

    SWF

    SW9

    H3

    !"#$E&'()*'+,-.'/'+012"'+3!.45'F(*:(G!-"HF>I>&

    #C**)[!3\0D8]&$!"

    *3-&)(\0D8]O%*!.'&)+%%$&$/&$$+$-&$$+$!O%*!.

    )&!$)+%.."$)#>?8D

    (SK1+5*I1(,*:(>=)G* "(G-7;S6'+G1=1P(>"(D!? "(,!"HF

    9 8 % J 9 8 % J

    % % % J % % % % ")N!?!"(,!-"HF

    % % % J % % % J "(,!-"HFMVJ

    % % % J % % J % "(,!-"HFMV%% % % J % J % % "(,!-"HFMV8

    % % % J J % % % "(,!-"HFMV9

    % % J % % % % % ")N!?!"(,!-"HF

    % % J % % % % J "(,!-"HFMV>

    % % J % % % J % "(,!-"HFMV@

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    17/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    KL.MKL.MKL.MKL.M 78

    % % J % % J % % "(,!-"HFMVB

    % % J % J % % % "(,!-"HFMV#

    % J % % % % % % ")N!?!"(,!-"HF

    % J % % % % % J "(,!-"HFMVA

    % J % % % % J % "(,!-"HFMVE

    % J % % % J % % "(,!-"HFMV

    % J % % J % % % "(,!-"HFMV

    J % % % % % % J ")N!?!"(,!-"HF

    J % % % % % % J "(,!-"HFMV

    J % % % % % J % "(,!-"HFMV

    J % % % % J % % "(,!-"HFMV

    J % % % J % % % "(,!-"HFMV]

    (P!?#$9&(SK1+5*I1(,*:(=)G*.(DF(S"(D!?/;4!"#'

    (".C*&$%"&"+!$".C*+$*O*)#$+&%"O'

    :$%C*"$$%C*+$&$*%$-+$

    %)&$O%+$%C*"&$O!$))&$)$%$$%C*$'B$2%+$%*)C*&C!1"!$!1$*"X)$C*%&%)$)&$O-+$$)O&$)C*%$.$$)C*&2%&$%$)$%%+$#C*"'

    ;O%*!.-+$*C*%&*!C*">?/0D

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    18/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    +FD+FD+FD+FD KL.MKL.MKL.MKL.M

    !"#$%J&;1/)0K1+5*F(*:(G!-"HF>I>&

    ;%)$C*">?//D

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    19/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    KL.MKL.MKL.MKL.M 7

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    20/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    +FF+FF+FF+FF KL.MKL.MKL.MKL.M

    mtphim equ p3 ;ket noi voi ma tran ban phimmaphim equ r5 ;luu tamma phimmaquet equ 11111110B ;FEH

    org 0000hmov dptr,#ma7doanmov quet,#07fh ;xuat ma quet chi cho 1 led sangmov led7,#7fh

    main: lcall keypres ;goi chtr con quet phimcjne a,#0ffh,main1sjmp main

    main1: lcall gma_hthi ;goi chtr con giai ma hien thisjmp main

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;Chuong trinh con giai ma fim nhan va hien thi ra 1 led 7 doan;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxgma_hthi: movc a,@a+dptr

    mov led7,aret

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    ;Chuong trinh con quet phim va chong doi phim;su dung cac thanh ghi: R4, R5, R6, R7, A;neu khong nhan thi (A) = FF, neu nhan thi (A) chua ma phim nhan;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxkeypres: mov r4,#10 ;nhap so dem 10 lankeypres1 : lcall KEY ;Neu co phim an thi co c=1

    jc pn1 ;kiem tra tiep neu c = 1ret ;Neu khong co phim nhan thi co c=0

    pn1: djnz r4,keypres1 ;Quay ve lap lai chong naypush acc ;Cat noi dung ma phim trong A

    keypres2: mov r4,#10 ;Nhap so dem 10 lan cho nha phimkeypres3: lcall key ;Co phim nhan hay khong

    jc keypres2 ;Co thi kiem tra laidjnz r4,keypres3 ;Khong thi lap lai 50 lan va dam baopop acc ;Khoi phuc lai gia tri cho Aret ;ket thuc mot chuong trinh con

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;Chuong trinh con quet phim;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxkey: mov r7,#maquet ;bat dau voi cot so 0(feh)

    mov r6,#4 ;Su dung r6 lam bo demmov maphim,#00

    key1: mov mtphim,r7 ;xuat ma quet ra cotmov a,mtphim ;Doc lai port1 de xu ly tiep theoanl a,#0f0h ;xoa 4 bit thap la hang

    cjne a,#0f0h,key2 ;co nhan fim thi nhay

    mov a,r7rl a ;xoay de chuyen den cot ke tiepmov r7,a

    mov a,maphim ;chuyen ma fim sang cot keadd a,#4mov maphim,a

    djnz r6,key1 ;Neu nhu sau moi lan 1 cot ma khong

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    21/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    KL.MKL.MKL.MKL.M 7>

    clr c ;clr c neu nhu khong co phim duoc anmov a,#0ffh ;thoat voi ma trong a = FFhret

    key2: swap akey4: rrc a ;xoay sang phai tim bit 0

    jnc key3 ;nhay neu (c)=0inc maphim ;tang ma fim len cot ke

    sjmp key4 ;tiep tuc cho den khi duoc (C)=0

    key3: mov a,maphimsetb cret

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;khai bao du lieu ma phim;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxma7doan: db 0c0h,0f9h,0a4h,0b0h,099h,092h,082h,0f8h

    db 080h,090h,088h,083h,0c6h,0a1h,086h,08eh

    end

    I$$CD"$).#C*+$*C*%-%)$-*!C*-$$*!C*&$/>)%9+%%$.'

    PC**)+%%$&$8-.$+$9$-$+$0'

    (/$O%*!.>S3^0//////P/$2'

    RA$%%*)>'

    I$"+$*O*%C*+_

    E%+%C*"*!C*%$$1^SS3-%%C*

    "$%%)$#M$)&+$*$O*C*%)+_E%+"O*%&$+-%%"$%+$*O*%C*&$%)*!C*'

    R!C*!$$*!*!>&$'

    E%%C**$"*!C**$!$*!C**%'

    (D'*(G-BX3!*)"&$D*A$$%0-+$%C**$"C*!! +%# $ $ * C45'

    (D'*(G-#X3!#C**)$+$)#&$DR)QD+$%")'

    R)QD+$%")'

    R)$D+$%")$'

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    22/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    +F0+F0+F0+F0 KL.MKL.MKL.MKL.M

    & _X

    ?=B1C"7078P?=B1C"7078P?=B1C"7078P?=B1C"7078P,$*$C$)C$)%%$$#$)%

    +&%#$'R)&$*$$1G(0909A1G(090'(%*&$)&$*D

    ? 1G(9#$'

    ? $$$/006'

    ? G2$$%&$&$OA&$$+$'

    ? (!8$%'

    ? (!&%'

    ? G

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    23/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    KL.MKL.MKL.MKL.M 7

    !"#$%9&M4/)02"),'O+N!*:)!?JAJE&

    Q+%%$&$$+$&$@(1G(090">?/D

    C1

    C

    R1R

    IN1

    IN5

    IN7

    VCC

    v R110k

    IN2

    AT89S52

    2122232425262728

    17

    16

    2930

    11

    10

    31

    19

    189

    3938373635343332

    12345678

    1213

    1415

    P2.0P2.1P2.2P2.3P2.4P2.5P2.6P2.7

    RD

    WR

    PSENALE/P

    TXD

    RXD

    EA/VP

    X1

    X2RST

    P0.0P0.1P0.2P0.3P0.4P0.5P0.6

    P0.7

    P1.0/T2P1.1/T2X

    P1.2P1.3P1.4P1.5P1.6

    P1.7

    INT0INT1

    T0T1

    C2

    0.001

    IN3

    IN6

    IN0

    Y1

    VCC

    RESET

    1KR2

    IN4

    VCC

    ADC0809

    109

    7

    1714158

    18192021

    6

    22

    11

    12

    16

    26272812345

    252423

    CLKOE

    EOC

    D0D1D2D3D4D5D6

    D7

    START

    ALE

    VCC

    REF+

    REF-

    IN0IN1IN2IN3

    IN4IN5IN6IN7

    A0A1A2

    U2A

    7414

    12

    VCC !"#$%>&'()*'+,-.'/'+012"'+3!.45'JAJE&

    ) % ">?/- &$ $ +$ /DG05-8O%/9+411/105-/O%C$)%41;F5-/O%C$)$+$1G(090#H$4Q1`5-/O%C$)$+$O%!$)4JF5-/)C$)#."$+%$%)!$)'

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    24/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    +,7+,7+,7+,7 KL.MKL.MKL.MKL.M

    I$$$@(1G(090">?/?/7D

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    25/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    KL.MKL.MKL.MKL.M >/

    45 4#5

    !"#$%B&;1/)0/'+012"'+3!JAJE&

    ;45$+$$#MC$)$FJ(-4#5"'$$$$$$'

    ,C>D("$$%&$$+$&$1G(090&9>'aD/+0&!$)+$$%O$':%.$M*+00%SS'

    quet equ p0 ;dieu khien quet transistorled7 equ p3 ;dieu khien cac doan a,b,c,...

    inadc equ p1 ;nhap du lieu tu adccontrol equ p2 ;dieu khien adc

    ;ALE bit p0.3start bit p2.3

    org 0000hmov dptr,#ma7doan

    main: lcall ctcd_adc ;goi chtr con chuyen doi du lieulcall gma_hex_bcd ;goi chtrinh con giai ma so hex sang led 7 doanlcall delayhthiljmp main ;nhay ve chuyen doi tro lai

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;chtrinh con chuyen so hex thanh so BCD va sau do thi chuyen

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    26/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    ++++,+,+,+,+ KL.MKL.MKL.MKL.M

    ;ma BCD thanh ma 7 doan de hien thi so thap phan;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxgma_hex_bcd:

    mov b,#10 ;chuyen so hex sang ma BCDdiv abmov 10h,b ;luu hang don vi BCD

    mov b,#10

    div ab ;(a) chua so hang tram, (b) chua hang chuc

    movc a,@a+dptrmov 25h,a ;cat so hang tram

    mov a,bmovc a,@a+dptrmov 26h,a

    mov a,10hmovc a,@a+dptrmov 27h,aret

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;chuong trinh con chuyen doi du lieu analog sang so ket qua luu trong A;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxctcd_adc: mov control,#00000000B ;goi ra port

    setb start ;start = 1nopnopclr startlcall delayhthi ;goi chtr con delay co hien thimov a,inadc ;doc du lieu sau khi chuyen doiret

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;chuong trinh con co ghep chtr con hien thi

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxdelayhthi: mov 7eh,#20pqn: mov 7fh,#30delpqn: lcall hthi ;goi chuong trinh con hien thi

    djnz 7fh,delpqnd jnz 7eh,pqnret

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;chuong trinh con hien thi ket qua dang so hex sau khi giai ma ra led;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxhthi: mov led7,27h ;lay du lieu tung kenh

    mov quet,#11111110b ;goi ma quet cho 1 led sanglcall delay10

    mov quet,#0ffh ; tat het de chong lem

    mov led7,26h ;lay du lieu tung kenhmov quet,#11111101b ;goi ma quet cho 1 led sanglcall delay10mov quet,#0ffh ; tat het de chong lemret

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxdelay10: mov 7ch,#50h

    djnz 7ch,$ret

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    27/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    KL.MKL.MKL.MKL.M >8

    ;khai bao ma 7 doan tu so '0' den so '9'ma7doan: db 0C0h,0F9h,0A4h,0B0h,099h,092h,082h,0F8h

    db 080h,090h,088h,083h,0c6h,0a1h,086h,08ehend

    "+$#DK.L&K>L$$%$+$9>-K$L+%%$&$9!$)%!090-KL

    +%%$$+$+&C$)$+$Q&1;F%$'"1G($O'$$"&$

    $+$!$).9>$!$)'

    (D'*(G-AX3!&$%"$+0&+%.$%P(G8'

    (D'*(G-EX3!&$%"$1G(+0&+/$8>'

    ++++ ?=B1C"",78P?=B1C"",78P?=B1C"",78P?=B1C"",78P,$&$*1G(090$9#$-+$!&$%#$$"&$

    *$)#$%@(;>/0'(%*&$)&$*D

    ? 1G()%/#$'

    ? (!8$C&$;#'

    ? (!&`bE=3J;G&!Q1bQ$*&$+$."$'

    ? E$2$%//0">?/>

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    28/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    +,D+,D+,D+,D KL.MKL.MKL.MKL.M

    !"#$%#&M4/)0="(N!#%JE&

    Q$$%&$$+$&$1G(@(;>/0">?/9D

    +5V

    C40.33

    C2

    1MC50.15

    Y1

    VCC

    R2 1M

    C1

    C

    R3

    5K

    R420K

    AT89S52

    2122232425262728

    17

    16

    2930

    11

    10

    31

    19

    189

    3938373635343332

    12345678

    1213

    1415

    P2.0P2.1P2.2P2.3P2.4P2.5P2.6P2.7

    RD

    WR

    PSENALE/P

    TXD

    RXD

    EA/VP

    X1

    X2RST

    P0.0P0.1P0.2P0.3P0.4P0.5P0.6P0.7

    P1.0/T2P1.1/T2X

    P1.2P1.3P1.4P1.5P1.6P1.7

    INT0INT1

    T0T1

    J1

    CON2

    12

    R1R

    -5V

    C31

    +5V

    RESET

    VCC

    Y23.58MHz

    R5 22K

    U1

    ICL7109

    3534

    1615141312111098765

    3639

    25

    2322

    32

    2124

    2627

    33

    40

    28

    201918

    30

    31

    373829

    17

    432

    IN+IN-

    B1B2B3B4B5B6B7B8B9B10B11B12

    REFIN+REFIN-

    BUFOSCOUT

    OSCOUTOSCIN

    INT

    MODEOSCSEL

    RUN/HOLDSEND

    COM

    V+

    V-

    CE/LOADHBEN

    LBEN

    BUFF

    AZ

    REFCAP+REFCAP-REFOUT

    TEST

    ORPOLSTATUS

    !"#$%A&'()*'+,-.'/'+012"'[email protected]'#%JE&

    ">?/9-&$$+$/+%%$&$/!$)%!1G(>/0P/cP/'$+$#*D$+$$(F-

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    29/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    KL.MKL.MKL.MKL.M >

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    30/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    +,F+,F+,F+,F KL.MKL.MKL.MKL.M

    !"#$8J&M4/)0="(N!JAJA&

    Q$$%&$$+$&$G1(0909">?/D

    -12V

    -

    +

    IC2OP07

    3

    26

    7

    4 8

    1

    R2

    5K

    C2

    C

    VCC

    R45K

    Y1

    VCC

    IC1 DAC 0808

    56789

    101112

    14

    15

    16

    4

    13

    3

    2

    D0D1D2D3D4D5D6D7

    VREF+

    VREF-

    COMP

    OUTVcc

    -Vcc

    GND

    5V -12V

    R35K

    VCC

    R1R

    -12V

    +12V

    C1

    C

    J1

    ANALOG OUT

    1

    2

    RESET

    AT89S52

    212223

    2425262728

    17

    16

    2930

    11

    10

    31

    19

    189

    3938373635343332

    12345678

    1213

    1415

    P2.0P2.1P2.2

    P2.3P2.4P2.5P2.6P2.7

    RD

    WR

    PSENALE/P

    TXD

    RXD

    EA/VP

    X1

    X2RST

    P0.0P0.1P0.2P0.3P0.4P0.5P0.6P0.7

    P1.0/T2P1.1/T2X

    P1.2P1.3P1.4P1.5P1.6P1.7

    INT0INT1

    T0T1

    !"#$8%&M4/)0?'()*'+,-.'/'+012"'+3!.45'JAJA&

    $$%&$$+$/O%!$)%%G1(0909-C$)!G1(.*+%$?*JT0>A?*>/-#$%`)$$G1('

    & X

    ?=B1C?=B1C?=B1C?=B1C4:P4:P4:P4:P$$%$+$$%#0,1("$

    $+$)$$%$'($$$%#*-Q(`-`@1(-Z

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    31/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    KL.MKL.MKL.MKL.M >>

    !"#$$%&$'

    :$$#$%%D$)*&$))-*&$))&$)*&$)$%$*$+$$'

    Q*$$%&$$+$&$">?D

    /,-$*&$)@ ($

    *&$))'R2$/$%$*&/$%$*'

    VCC

    AT89S52

    2122232425262728

    17

    16

    2930

    11

    10

    31

    19

    189

    3938373635343332

    12345678

    1213

    1415

    P2.0P2.1P2.2P2.3

    P2.4P2.5P2.6P2.7

    RD

    WR

    PSENALE/P

    TXD

    RXD

    EA/VP

    X1

    X2RST

    P0.0P0.1P0.2P0.3P0.4P0.5P0.6P0.7

    P1.0/T2P1.1/T2X

    P1.2P1.3P1.4P1.5P1.6P1.7

    INT0INT1

    T0T1

    VCC

    D1

    Q2

    +12V

    R1R

    RESET

    Y1

    C1

    C

    Q1

    R1210K

    R2RELAY

    5

    2 1

    3 4

    5

    2 1

    3 4

    +12V

    D2R1RELAY

    5

    2 1

    3 4

    5

    2 1

    3 4

    10KR11

    !"#$88&M4/)0?'()*'+,-.'/'+012"'+3!.45':+6(Q&

    ">?/+%$*D%$%$*$+$$)"+$&$$+$*$%$)"*!$)*!*3*$2)'3%$$"&$$+$*$$)"H)-+$)!O+$%)%'B$$*%$$+$#M)'

    B+H+%$*#M*/!+$$+$$A@($$%b;E908">?8D

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    32/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    +,0+,0+,0+,0 KL.MKL.MKL.MKL.M

    VCC

    +12V

    +12V

    +12V

    R2RELAY

    5

    2 1

    3 4

    5

    2 1

    3 4

    IC2

    ULN2803

    10

    1

    2345678

    18

    17161514131211

    9COM

    IN1IN2IN3IN4IN5IN6IN7IN8

    OUT1OUT2OUT3OUT4OUT5OUT6OUT7OUT8

    GND

    R3RELAY

    5

    2 1

    3 4

    5

    2 1

    3 4

    R10k

    R1RELAY

    5

    2 1

    3 4

    5

    2 1

    3 4

    VCC

    +12V

    R4RELAY

    5

    2 1

    3 4

    5

    2 1

    3 4

    +12V

    AT89S52

    21

    22232425262728

    17

    16

    2930

    11

    10

    31

    19

    189

    3938373635343332

    12345678

    12

    13

    1415

    P2.0P2.1P2.2P2.3P2.4P2.5P2.6P2.7

    RD

    WR

    PSENALE/P

    TXD

    RXD

    EA/VP

    X1

    X2RST

    P0.0P0.1P0.2P0.3P0.4P0.5P0.6P0.7

    P1.0/T2P1.1/T2X

    P1.2P1.3P1.4P1.5P1.6P1.7

    INT0INT1

    T0T1

    RESET

    +12V

    Y1

    RN210k

    12

    3456789

    C

    10

    !"#$89&M4/)0?'()*'+,-.'/'+012"'+3!.45'>:+6(QK1(?'()*'+,-8AJ9&

    b;E908@($$%)*D&$*2$!&%&!"/)G!?=4O;45=6)(

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    33/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    KL.MKL.MKL.MKL.M >

    !"#$8@&(5==1)G!7(NQO+N!*:)!?/)G!?=4O;45=&

    B)#

    .(D?'(PL;P/(017(NQ/)56(D7(NQ *";5> `"(SQI+F"!"O+N!-"(P'*;4!?;5!?&

    ';S!?1Q+N!O;45=*:+N!

    '+,-*"+)=")

    '+,-*"+)=")

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    34/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    +07+07+07+07 KL.MKL.MKL.MKL.M

    1)G!7(NQ=)D!6(

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    35/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    KL.MKL.MKL.MKL.M 9/

    !"#$8A&'+012"'+3!2H="8=1)G!7(NQ&

    ' T%$$+$$+$!#">?D

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    36/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    +0++0++0++0+ KL.MKL.MKL.MKL.M

    !"#$8E&'+012"'+3!-"),'"4

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    37/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    KL.MKL.MKL.MKL.M 98

    Q*$$%&$$+$&$)#">?80D

    RN210k

    1

    23456789

    VCC

    IC2

    ULN2803

    10

    12345678

    1817161514131211

    9COM

    IN1IN2IN3IN4IN5IN6IN7IN8

    OUT1OUT2OUT3OUT4OUT5OUT6OUT7OUT8

    GND

    Coil4

    Coil1

    Y1

    Coil3

    +12V

    RESETCoil2

    DONG CO BUOC

    AT89S52

    2122232425262728

    17

    16

    2930

    11

    10

    31

    19

    189

    3938373635343332

    12345678

    1213

    1415

    P2.0P2.1P2.2P2.3P2.4P2.5P2.6P2.7

    RD

    WR

    PSENALE/P

    TXD

    RXD

    EA/VP

    X1

    X2RST

    P0.0P0.1P0.2P0.3P0.4P0.5P0.6P0.7

    P1.0/T2P1.1/T2X

    P1.2P1.3P1.4P1.5P1.6P1.7

    INT0INT1

    T0T1

    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 p1org 0000h

    main: mov outstep,#10001000blcall delaymov outstep,#01000100blcall delaymov outstep,#00100010blcall delaymov outstep,#00010001blcall delaysjmp main

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;chuong trinh con delay;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxdelay: mov r6,#0del: mov r7,#0

    djnz r7,$djnz r6,delret

    end

    ("$+$)#./&$D;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    38/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    +0D+0D+0D+0D KL.MKL.MKL.MKL.M

    ;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 p1sobuoc equ 50 ;loai dco: 50x4=200 buoc

    org 0000h

    mov dptr,#datastep ;nap dia chi quan ly mamov r0,#0mov r2,#sobuoc ;50 chu ky la vong

    main2: mov r1,#4 ;1 chu ky 8 buoc

    main1: mov a,r0movc a,@a+dptrmov outstep,alcall delay

    inc r0anl 00h,#03h ;anl r0 voi 00000011bdjnz r1,main1

    djnz r2,main2sjmp $ ;dung lai;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;chtr con delay;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxdelay: mov r6,#10hdel: mov r7,#0

    djnz r7,$djnz r6,delret

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;khai du lieu dieu khien dong co buoc;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxdatastep: db 10001000b

    db 01000100bdb 00100010bdb 00010001b

    end

    B)#$&C%/&00#'

    (D'*(G-%JX3!$%+%*$+$/)#&$%Q-Q-@&&$$%&$>',$%"$+$)#&$D+$%Q")&$%#>-+$%")-+$%$")$'

    & X 15="P15="P15="P15="P

    ef$$%&$>%&"$%0%A%O0%SX+$$+C+-!$;(G'

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    39/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    KL.MKL.MKL.MKL.M 9%%/9$!$)$!$%#$+$&;(G'

    9999 >?3-"1?=B1C"P>?3-"1?=B1C"P>?3-"1?=B1C"P>?3-"1?=B1C"P!"#$$%&$$+$&$;(G'3">?8!"#

    +%%$&$$+$9>(>

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    40/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    +0F+0F+0F+0F KL.MKL.MKL.MKL.M

    !"#$98&'()*'+,-.'/'+012"'+3!A##@%.45'&

    (&$$+$19Q

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    41/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    KL.MKL.MKL.MKL.M 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"!+ND!$)*$!$!$)!'P$Q^/"!$)*2$+$)/#$'

    ($)($)($)($)(-(-(-(-####%&($%&($%&($%&($''''D)$+$4$"#$G^/-H$"#$G^05-H*4*"#$(^/-H"#$(^05-&%4%"#$P^/-H"#$P^05'

    &($)&($)&($)&($)####$%$.%&/0($%$.%&/0($%$.%&/0($%$.%&/0(''''D)$+$$$4Q(^/-Q(^0"+5-4`;^/"$-`;^0"$5'E)$#)GG`1R&2+$'

    ((-123456(7(8((-123456(7(8((-123456(7(8((-123456(7(8####/(94565$/(94565$/(94565$/(94565$''''D)$%)#)`1R+C'

    ((((((((-123456(--123456(--123456(--123456(- ####/(4565$/(4565$/(4565$/(4565$''''D)$%)#)`1R!!$)$'

    3$)%$)&)$!$);(G'

    GC$)+$$)$!$)&;(G">?8D

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    42/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    +00+00+00+00 KL.MKL.MKL.MKL.M

    !"#$9>&(

    E"&%"$+$D

    ? B$+$C$)`Q'

    ? B$+$C$)`=hO%*%'? B$+$C$)F*'

    ? i%!$)G>cG0'

    ? B$+$C$)F&*%'

    ? B$+$C$)`=h*$'

    EEEE

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    43/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    KL.MKL.MKL.MKL.M 9

    45 4#5

    !"#$9@&;1/)0/'+012"'+3!&

    "45C#*."+$;(G-$%)&`1R&$)."$!$);(G$/&$%'

    ;"4#5#$%"$)."+$;(G#*#D$*!$+$893;(G&$)C%'/*'$%$)&$$$/006'(%$$$*!$+$893-0(3-&0/3$%)%");(G'

    ;$)$$+$$!$);(G$"D

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    44/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    +87+87+87+87 KL.MKL.MKL.MKL.M

    !"#$9B&;1/)0I1(,*6+G!"")(R=7;S6'+G1:(&

    &D&%%$$+$%;(G-&

    $!$)$%;(GX+$).C$)$+$`Q'

    (#$"$%&+$$%$O$+$=!$)"$$+$=!$)+$*#$GP>O*$+$=!$)!)O%"$-%!)O"&j)$+$=!$)$%'

    FFFF "1

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    45/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    KL.MKL.MKL.MKL.M /

    ORG 0000Hmov 0a2h,#0LCALL khtaolcd ;khoi tao lcdLCALL first_line ;goi chtr con hien thi hang thu nhatLCALL scond_line ;goi chtr con hien thi hang thu haiSJMP $

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;chtr con khoi tao LCD;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxkhtaolcd: setb e ;Enable

    clr rs ;RS lowclr rw ;RW low

    MOV a,#38h ;tu dieu khien LCDLCALL KTAOLCALL ddelay41 ;delay 4.1 mSec

    MOV A,#38h ;function setLCALL KTAOLCALL ddelay100 ;delay

    MOV A,#38h ;functionLCALL KTAO

    MOV A,#0ch ;tu dieu khien display onLCALL KTAOMOV A,#01h ;tu dieu khien Clear displayLCALL KTAO

    MOV A,#06h ;tu dieu khien entry mode setLCALL KTAO

    MOV A,#80h ;thiet lap dia chi LCD (set DD RAM)LCALL KTAO

    MOV A,#0fh ;enable display cursorLCALL KTAO

    RET;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;chuong trinh con delay 4.1 ms;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxddelay41: mov r6,#90hdel412: mov r7,#200

    djnz r7,$djnz r6,del412ret

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;chuong trinh con delay 255 microgiay;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxddelay100: mov r7,#00

    djnz r7,$ret

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;Feed command/data to the LCD module;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxcommand_byte:

    clr rs ;RS low for a command byteljmp bdelay

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    46/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    +8++8++8++8+ KL.MKL.MKL.MKL.M

    data_byte: setb rs ;RS high for a data bytebdelay: clr rw ;R/W low for a write mode

    clr enop

    setb e ;Enable pulsenop

    nop

    mov byteout,#0ffh ;configure port1 to input mode

    setb rw ;set RW to readclr rs ;set RS to commandclr e ;generate enable pulse

    nopnopsetb elcall ddelay100ret

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    ;Chuong trinh con hien thi noi dung hang thu 1 tren LCD;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxfirst_line: MOV A,#080h ;set DDRAM

    LCALL KTAOMOV DPTR,#FLINE_DATAlcall Writeret

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;Chuong trinh con hien thi noi dung hang thu 2 tren LCD;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxscond_line: mov a,#0c0h ;set DDRAM

    LCALL KTAOmov dptr,#sline_datalcall writeret

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;chuong trinh con khoi tao LCD;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxKTAO: mov byteout,a

    lcall command_byteRET

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;chtr con goi data hien thi ra LCD;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxwrite: MOV A,#0

    MOVC A,@a+dptrCJNE A,#99h,WriteaRET

    Writea: mov byteout,aacall data_byteinc dptrSJMP Write

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx; Data bytes;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxFLINE_DATA: DB 'NGUYEN DINH PHU ',099hSLINE_DATA: DB 'DAI HOC SPKT HCM',099hEND

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    47/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    KL.MKL.MKL.MKL.M 8

    (D'*(G-%%X3!$%+%*$+$/;(G$%&/#C**)[&&$%"+$%C*%"*"$%$&C)#$-%$'

    (D'*(G-%8X3!$%+%*$+$/;(G$%&/#C**)[&&$%"$$$-N*'

    & X

    15=345P15=345P15=345P15=345P.$)*)-!$$$)

    &"#$$%&$$+$&$*)&**$+$*)'

    ;*)/)#%C*)$+C#%+'(%!C*)C45A9[949&9)5&C+C$)*-%$

    #$) 4$5 $$45'; "+$$&"*A$$%&*+"%!-*$%!-&d$!$'

    3">?8>$$$)*)&$*+D

    !"#$9#&+7F(*:(G!@T#&

    ++++ "=-H1&

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    48/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    +8D+8D+8D+8D KL.MKL.MKL.MKL.M

    1%$&$*3&%$*;"-$"H'

    3!.">?89*)9[9$!1-$!1D

    "P(Q.R)#L$S"P(Q.R)#L$S"P(Q.R)#L$S"P(Q.R)#L$STTTTUQV)#L$RPUQV)#L$RPUQV)#L$RPUQV)#L$RP

    R2$+C"*!!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

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    49/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    KL.MKL.MKL.MKL.M =9-C&"%!+!%*&$)&$&*'BN)"$N&'P"*&$)&$/0*1%0*1&,-&$./9[9"$N+990*1%/70*1'

    &$*&$)#"4+.50*1-*&$)*,':$$)*2$D

    === 10020

    2

    mA

    V

    I

    UR

    LED

    "$$#M/70*1-+$#"D

    mAmA

    ITBLED

    208

    160_

    ==

    Q$)%DVmAV

    LEDLED16100160

    _==

    "%%!%X+,%/,'

    Q*$+$*)">?8D

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    50/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    +8F+8F+8F+8F KL.MKL.MKL.MKL.M

    !"#$9E&M4/)0F(

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    51/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    KL.MKL.MKL.MKL.M >

    [ [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&

    ? (

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    52/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    +80+80+80+80 KL.MKL.MKL.MKL.M

    main: mov hang,#007h ;goi du lieu ra hang 1

    mov cotx,#00000001b ;goi ma quet cho 1 transistor danlcall delaymov cotx,#00h ;chong lem

    mov hang,#0DBh ;goi du lieu ra hang 2mov cotx,#00000010b ;cot thu 2 dan

    lcall delaymov cotx,#00h ;chong lem

    mov hang,#0ddh ;goi du lieu re hang 3mov cotx,#00000100blcall delaymov cotx,#00h

    mov hang,#0DBh ;goi du lieu ra hang 4mov cotx,#00001000blcall delaymov cotx,#00h

    mov hang,#007h ;goi du lieu ra hang 5

    mov cotx,#00010000blcall delaymov cotx,#00h

    sjmp main;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;chuong trinh con delay nho;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxdelay: mov r5,#10de: mov r6,#20

    djnz r6,$djnz r5,deret

    end

    (D'*(G-%9X3!$%+%*$+$*)9[9$7P

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    53/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    KL.MKL.MKL.MKL.M

    ? (@(C&$R(/79/9P&GQ/9>'

    ? G!$)+#*%+/0N*+%@('

    ? C#$&)'

    ? P)%*$--$----N*$%/00'

    ? (%$$"P(GA'

    ? (*)D*/$&*$'

    ? (+%%$+$R&@'

    ? B#!$)$%+$)*@('

    ? (/9#`1RD/#&$$+$-//#$*#)`1R'(!$)&!+#*%+$*%%'

    ? (C$)!O&)"'

    ? (C$)#H'

    ? (8#H&+$*'

    9999 >?"1@H"1+"00,P>?"1@H"1+"00,P>?"1@H"1+"00,P>?"1@H"1+"00,P3">?0@(?$*GQ/(99>D

    !"#$>J&M4/)0="(N!=1P(:+(6$*'F+M%8AA#&

    @(D

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    54/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    977977977977 KL.MKL.MKL.MKL.M

    '(

    P$%+$)*#$&"$&$!$)C$)'BO%+$$%+A$&!$)O%+$$$+=$'B=!$)+*)*$$)'

    E%`?$*',(($)!&g?/0'C$)Qlh*AH#$QlhF`$P'C$)Qlh+

    O%$)+$,%'

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    55/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    KL.MKL.MKL.MKL.M 80/

    (P!?#$%J&(5=*")N!?L),*H!"'+G1!?)S:(MUV&

    ""'( !&)O%'QO%1Q=1;F*

    #%$#GQ/(99>'Q$%+$O%$)#1Q!O#%%(Q+'

    ""')( (GQ=`G+$)&*RJ'

    :$RJ+%%$,-#$R'+$GQO+$$$+#&$GQ#'+-C$)GQO$$GQ/(99>O%!$)'+$-OGQ!$+$GQ/(99>%!$)$'

    :$RJ%$O%IEG-#$@'+$-GQ$`4RD 5' RD O++$GQ/(99>$+$#!$)'C$)RD!O*C$)JF#4 OE5%#)'

    WR/ )$(( WR/ !)':$RJ+%%$,%)$R-"*$)

    WR/ O+$)$+A$'

    (+$$ WR/ $*+$GQ*'

    (+$$$ WR/ $*%%."%C$)GQ'

    :$RJ%$IEG%)$@-C$) WR/ C$))C*%$WR '%)- WR/ dC$)

    h$F#4WR 5#)`1R'CS * " ( C $) C * % O%

    GQ/(99>' CS $$C+$$GQ&1Q%)$R&%RD &WR %)$@'(+PO* CS +$C"+O%'

    :$$)%,%'

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    56/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    97+97+97+97+ KL.MKL.MKL.MKL.M

    ()#()%( 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*HH#)$#GQ/(99>%)Y?!%':$ RESET *%&%,(('

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    57/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    KL.MKL.MKL.MKL.M 808

    :$,((O%$)+8&-$),((%#$H$&$$$$*#GQ/(99>!%`$*(+)`1R'

    PGQ/(99>"#">?/'

    !"#$>%&)3=";5=O)G!"45O+N!*:)!?=1P(+(6$*'F+M%8AA#&

    P#*//#`1R-/#`1R#*$$--!$)#$&$&$)$+$"'%/9#$A$%!D

    $(G$$'

    P$>$1#$'

    P$##$'

    (%&$$M#'$$-$$AA+$#M$$#`1RC'

    E)$/0#$$-$/4P$5AP(G4P$(G$*5'

    +$$!$)&$$--&$#$#"

    #$QF$P$$%)*$/NA&$)))O."O%'

    E$$/0$$$--&$#$*)!4P(G5"#$+$!$) 4G*XGR5$P$A*$C'

    %/0#$$-$$+$!$)'T$O#$QF$P+$$)O&$)))$$-&$'

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    58/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    97D97D97D97D KL.MKL.MKL.MKL.M

    R2$+$)-$$))%$*)+$!'G!$)!+$%++$)$/0#!$)'

    P>?//"#&P(G$$--$'

    (SQ6;

    8 "15* J$@E JJ$9 JJ$@E

    9 "15*"+

    '4DXF)7+%8?'4D %$%8 J%$JA%$A J%$%8A%$E8>

    '4DXF)7+8>?'4D J$89 JJ$%# JJ$89

    '4D"+

    A "(5!? %$%8 J%$J J%$%8

    E (bF J$EE JJ$B9 JJ$EE

    (P!?#$%%&(5=/W!"7(

    P$+$=/+$%++$)$$$':$/$-#$#$OTR+$A*$/'R2$$*)-//#))&+$*"#$'

    E%)!$)$$&$2."))-*)&%$$--$-Z+CO'iO%+CO!$)$$&%%'(&$$%O+$$$&)'

    8##$#MD

    &D+$$$#$$&$$--$-)#$#H$$$CO+$#$#A*'

    A$#%%&*)A$##'R!

    #%%#%+*!%OM*$(0%SS'3$#$RQP!#A& $#%%+$*$/'P$!$*2$$+$#$#%%A$'-#$!$*2$%*!#%%#$'E%*!#%%8##$"!C$)H*2$$'

    EEEE 1-5"=A""111?=B1CP1-5"=A""111?=B1CP1-5"=A""111?=B1CP1-5"=A""111?=B1CPGQ/(99>$$+$*$+."))'

    M M

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    59/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    KL.MKL.MKL.MKL.M 80 9 8 % J 8 % J M9 M8 M% MJ

    +(,b@T4b@T5#$$!$':$#$b@T*/"."))O'

    :$#$b@T*0-."))!+O+$$C%'E!$&$$--$`1R$)&$))+$#$b@T*0'

    P$b@T#$&+# RESET ':$$#$QF$P/!NA*$."))&O#$$b@T'

    -./8#$*AH#))&$A$."%*O%':$\G,G,/G,0]^ \0/0]N%#)#))&`(%*$$':$\G,G,/G,0]^\//[]!)$!."%*O%*'l"))$%!$2?/0$)++H&%&*&$#$`Q'(#$=$+##$`FQF'

    ;;;;

    M M# B @ > 9 8 % JM MUV 8>d%8 M

    "1!/:$#$QF*0-."))#MN$%*//$':$#$QF$&*/-*$."))#%*'(+$*)+$'P$QF#$=$&+AN#GQ/(99>'

    ,(1/,(1' P$H+#$=$-#$#$H+4TS5$($+$ IRQ O%*%'

    :$#$T@FA*/-+H#M$+$ IRQ

    O%*%)&)#%#$`Q8c`Q0$1'

    :$#$T@F^0!NAC$)! IRQ +$&$)$+$#MH+

    #$+TS&2$%)%)+'

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    60/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    97F97F97F97F KL.MKL.MKL.MKL.M

    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$(+CH IRQ ':$?$*#

    AQF*/!O#$b@F'

    "#$1XQ.h&F#D:$#$QlhFA*/-*)C$)&%#$#$`Q8%`Q0!O%Qlh':$#$QlhFA*%-Qlh!$!*%'QlhF#$=$&O+$?$*#`FQF'

    /P$+$!$)GR.+$"$&$$AP(G'P$GRA#$"C&+$'P$+#$#$)#?$*A+$#'R/GR!!$)*0!!$)P(G'

    -3.-/P$$+$=/O+$#$':$*/"%)$$-*0"%)$/$'P$#$$&+##$)#?$*!+$?$*#'

    "1/45*"&51'DP$+$GQF#$p$'P$))A#$)+$GQFA/'

    ,(E)$-+$$$N%$/D

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    61/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    KL.MKL.MKL.MKL.M 80>

    P%#$@`lSA/- IRQ +&*%'%#

    O+$$(#$"A+$?$*#'

    ,6/T$$@SDP$H+#$-%#$A*/+$/O$)C$)#)$'(#$`Q8%`Q0$%)%)+'(TSA/+)&$#$T@F'

    :$TS&T@F*/-C$)IRQ !$C&!A#$@`lS*/'P$TS!#O#$?$*A#$)$('

    6/1*@SD%1S^/!O$$$)$&$$$$'E%#$1@F!*/-IRQ !O%*%$@`lS!#M/'P$1S!#

    O#$?$*A#$)$('

    +6/bF@SDP$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'

    (!;">?'&$$

    +$$$%&$/ ?$*&$*C"#$$% %"&$$+$$$$%&$$+")%*$)&C$$%*>A;(G*$$%$$'

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    62/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    970970970970 KL.MKL.MKL.MKL.M

    !"#$>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+$#)*)

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    63/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    KL.MKL.MKL.MKL.M 80

    mov a,#phuthientaimov r0,#02 ;dia chi cua o nho phutmovx @r0,a ;nap phut hien tai

    mov a,#giohientaimov r0,#04 ;dia chi cua o nho giomovx @r0,a ;nap gio hien tai

    mov r0,#0ah ;dia chi cua thanh ghi Amov a,#020h ;tu dieu khien cua thanh ghi Amovx @r0,a ;cho phep bo dao dong chay

    lcall delay50

    sjmp $

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    delay50: mov 7eh,#0fhdel12: mov 7dh,#0ffhdel11: djnz 7dh,del11

    djnz 7eh,del12ret

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxend

    ("&C" %&$$+$-$*&;(GD "&$$+$+%%$&$$*&8#$$+$/';xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;chuong trinh dieu khien LCD hien thi chuoi thong tin;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;dinh nghia cac bien

    E BIT P1.0rw BIT P1.1rs BIT P1.2

    byteout equ p2dklcd equ 70h

    bdn equ r6giay equ r5phut equ r4gio equ r3

    org 0000hmov sp,#68h

    ; lcall khoitao_rt ;goi chtr con khoi tao real timelcall khoitao_lcd ;goi chtr khoi tao LCDlcall xoavnh_hthi ;xoa vung nho hien thi

    main1: lcall doc_gpg ;doc thong so gio-phut-giay tu real timelcall bcd_maascii ;chuyen so bcd sang ma ASCIIlcall hienthichung ;goi ra LCD de hien thisjmp main1 ;tiep tuc

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;chtr con doc gio phut giay;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxdoc_gpg: mov r0,#00

    movx a,@r0mov giay,a

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    64/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    97979797 KL.MKL.MKL.MKL.M

    mov r0,#02movx a,@r0mov phut,amov r0,#04movx a,@r0mov gio,aret

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;chtr con chuyen so bcd sang ma ASCII;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxbcd_maascii: mov a,giay

    anl a,#0fhadd a,#30hmov 4fh,a

    mov a,giayanl a,#0f0hswap aadd a,#30hmov 4eh,a

    mov a,phutanl a,#0fhadd a,#30hmov 4ch,a

    mov a,phutanl a,#0f0hswap aadd a,#30hmov 4bh,a

    mov a,gioanl a,#0fhadd a,#30hmov 49h,a

    mov a,gioanl a,#0f0hswap aadd a,#30hmov 48h,aret

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;Chuong trinh con hien thi noi dung tren LCD cua2 vung nho;40H->4Fh hang 1;50H-> 5Fh hang 2;;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxhienthichung: mov A,#080h ;set DDRAM

    lcall ktao

    mov r1,#16mov r0,#40h ;bat dau tu 0

    fline: lcall Writedjnz r1,fline

    mov a,#0c0h ;set DDRAMlcall ktaomov r1,#16

    sline: lcall Write

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    65/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    KL.MKL.MKL.MKL.M 8//

    djnz r1,slineret

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;chtr con goi data hien thi ra LCD;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxwrite: mov a,@r0write1: mov byteout,a

    lcall data_byte

    inc r0ret

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;chtr con khoi tao LCD;chuong trinh dieu khien LCD 16X2 tren kit vi dieu khien LOAI NHO;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxkhoitao_lcd: mov dklcd,#0

    lcall khtaolcd ;khoi tao lcdret

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;chtr con khoi tao LCD;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    khtaolcd: setb e ;Enableclr rs ;RS lowclr rw ;RW low

    mov a,#38h ;tu dieu khien LCDlcall ktaolcall ddelay41 ;delay 4.1 mSec

    mov A,#38h ;function setlcall ktaolcall ddelay100 ;delay

    mov A,#38h ;functionlcall ktao

    mov A,#0ch ;tu dieu khien display onlcall ktaomov A,#01h ;tu dieu khien Clear displaylcall ktao

    mov A,#06h ;tu dieu khien entry mode setlcall ktao

    mov A,#80h ;thiet lap dia chi LCD (set DD RAM)lcall ktaoret

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;chuong trinh con khoi tao LCD;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxktao: mov byteout,a

    lcall command_byteret

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;Feed command/data to the LCD module;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxcommand_byte:

    clr rs ;RS low for a command byteljmp bdelay

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    66/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    9+9+9+9+ KL.MKL.MKL.MKL.M

    data_byte: setb rs ;RS high for a data bytebdelay: clr rw ;R/W low for a write mode

    clr enop

    setb e ;Enable pulsenop

    nop

    mov byteout,#0ffh ;configure port1 to input mode

    setb rw ;set RW to readclr rs ;set RS to commandclr e ;generate enable pulse

    nopnopsetb elcall ddelay100ret

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;chuong trinh con delay 4.1 ms;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxddelay41: mov 7eh,#90hdel412: mov 7fh,#200

    djnz 7fh,$djnz 7eh,del412ret

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;chuong trinh con delay 255 microgiay;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxddelay100: mov 7fh,#00

    djnz 7fh,$ret

    delay1giay: mov 7ah,#20xx2: mov 7bh,#0xx1: mov 7ch,#0

    djnz 7ch,$djnz 7bh,xx1djnz 7ah,xx2ret

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;chuong trinh con khoi tao real time;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    khoitao_rt: mov r0,#0bhmov a,#0movx @r0,a ;cho phep chinh cai dat gio

    mov r0,#0movx @r0,a ;giay = 0

    mov r0,#02movx @r0,a ;phut = 0

    mov r0,#04movx @r0,a ;gio = 0

  • 8/3/2019 Vxl Chapter 07 Giaotiep Ungdung Vdk

    67/67

    "#"#"#"#,,,,()*&/)IJ()*&/)IJ()*&/)IJ()*&/)IJ >B>B>B>B

    mov r0,#0ahmov a,#020hmovx @r0,a ;cho phep bo dao dong chaylcall delay1giayret

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;chuong trinh con xoa vung nho hien thi

    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxoavnh_hthi: mov r0,#40hmov a,#' '

    xoac: mov @r0,ainc r0cjne r0,#60h,xoacret

    end

    (D'*(G-%>X3!$)$"%---N*$;(G'

    &eX

    "#$$%&$$+$&$$%#$&$ #)%$+$%'

    R))%$+$)&*)**$$%&$$$%#+-"#$-$&M+$$$$$%+%)%$$%'

    ))


Recommended