Thông báo

Collapse
No announcement yet.

Lập trình và mô phỏng mạch máy tính đơn giản sử dụng bàn phím ma trận 4x4

Collapse
X
 
  • Lọc
  • Giờ
  • Show
Clear All
new posts

  • Lập trình và mô phỏng mạch máy tính đơn giản sử dụng bàn phím ma trận 4x4

    Mo Phong May Tinh Bo Tui Ban Phim 4x4 voi 2 led 7 doan noi vao P0 va P1 dung 89C51 Va 74LS134 .zip để thực hiện 4 phép tính (cộng, trừ, nhân chia) đơn giản của 2 số hạng có 1 chữ số.

    Nhấp đúp vào hình để xem hình lớn hơn
    Click image for larger version

Name:	clip_image002.png
Views:	1
Size:	6.5 KB
ID:	1413031

    Dưới đây la code chương trình

    ;-----------------------------------****CHUONG TRINH CHINH****-------------------

    ORG 00H
    MOV P0,#0FFH
    MOV R0,#1 ; BIEN SO HANG 1: SO HANG THU 1 ; 2: SO HANG THU 2
    MOV R1,#0 ; BIEN PHEP TOAN 1:+ ; 2:- ; 3:X ; 4:÷
    MOV R6,#0 ; SO HANG THU 1
    MOV R7,#0 ; SO HANG THU 2
    JMP Main

    Sw7:
    CJNE R0,#1,NH7
    MOV R6,#7
    MOV R0,#2
    MOV 31H,#7
    JMP Hienthi
    NH7:
    MOV R7,#7
    MOV R0,#1
    MOV 31H,#7
    JMP Hienthi

    Sw8:
    CJNE R0,#1,NH8
    MOV R6,#8
    MOV R0,#2
    MOV 31H,#8
    JMP Hienthi

    NH8:
    MOV R7,#8
    MOV R0,#1
    MOV 31H,#8
    JMP Hienthi

    Sw9:
    CJNE R0,#1,NH9
    MOV R6,#9
    MOV R0,#2
    MOV 31H,#9
    JMP Hienthi
    NH9:

    MOV R7,#9
    MOV R0,#1
    MOV 31H,#9
    JMP Hienthi

    Sw4:
    CJNE R0,#1,NH42
    MOV R6,#4
    MOV R0,#2
    MOV 31H,#4
    JMP Hienthi
    NH42:
    MOV R7,#4
    MOV R0,#1
    MOV 31H,#4
    JMP Hienthi

    Sw5:
    CJNE R0,#1,NH5
    MOV R6,#5
    MOV R0,#2
    MOV 31H,#5
    JMP Hienthi
    NH5:
    MOV R7,#5
    MOV R0,#1
    MOV 31H,#5
    JMP Hienthi

    Swcong:
    MOV R1,#1
    JMP Main

    Swtru:
    MOV R1,#2
    JMP Main

    Swnhan:
    MOV R1,#3
    JMP Main

    Swchia:
    MOV R1,#4
    JMP Main

    Main: ; QUET PHIM
    MOV P0,#0FEH ; COT CAC PHIM 7,8,9,÷
    JNB P0.4,Sw7
    JNB P0.5,Sw8
    JNB P0.6,Sw9
    JNB P0.7,Swchia

    MOV P0,#0FDH ; COT CAC PHIM 4,5,6,X
    JNB P0.4,Sw4
    JNB P0.5,Sw5
    JNB P0.6,Sw6
    JNB P0.7,Swnhan

    MOV P0,#0FBH ; COT CAC PHIM 1,2,3,-
    JNB P0.4,Sw1
    JNB P0.5,Sw2
    JNB P0.6,Sw3
    JNB P0.7,Swtru

    MOV P0,#0F7H ; COT CAC PHIM ON/C,0,=,+
    JNB P0.4,Swon
    JNB P0.5,Sw0
    JNB P0.6,Swbang
    JNB P0.7,Swcong
    SJMP Main

    Sw6:
    CJNE R0,#1,NH6
    MOV R6,#6
    MOV R0,#2
    MOV 31H,#6
    JMP Hienthi
    NH6:
    MOV R7,#6
    MOV R0,#1
    MOV 31H,#6
    JMP Hienthi

    Sw1:
    CJNE R0,#1,NH1
    MOV R6,#1
    MOV R0,#2
    MOV 31H,#1
    JMP Hienthi
    NH1:
    MOV R7,#1
    MOV R0,#1
    MOV 31H,#1
    JMP Hienthi

    Sw2:
    CJNE R0,#1,NH2
    MOV R6,#2
    MOV R0,#2
    MOV 31H,#2
    JMP Hienthi
    NH2:
    MOV R7,#2
    MOV R0,#1
    MOV 31H,#2
    JMP Hienthi

    Sw3:
    CJNE R0,#1,NH3
    MOV R6,#3
    MOV R0,#2
    MOV 31H,#3
    JMP Hienthi
    NH3:
    MOV R7,#3
    MOV R0,#1
    MOV 31H,#3
    JMP Hienthi

    Swon:
    MOV 31H,#0
    MOV R0,#1
    MOV R1,#0
    MOV R6,#0
    MOV R7,#0
    JMP Hienthi

    Sw0:
    CJNE R0,#1,NH0
    MOV R6,#0
    MOV R0,#2
    MOV 50H,#0
    JMP Hienthi
    NH0:
    MOV R7,#0
    MOV R0,#1
    MOV 31H,#0
    JMP Hienthi

    Swbang:
    CJNE R1,#1,KT02
    MOV A,R6
    ADD A,R7
    JMP KTHUC

    KT02:
    CJNE R1,#2,KT03
    MOV A,R6
    SUBB A,R7
    SJMP KTHUC

    KT03:
    CJNE R1,#3,KT04
    MOV A,R6
    MOV B,R7
    MUL AB
    SJMP KTHUC

    KT04:
    CJNE R1,#4,KTHUC
    MOV A,R6
    MOV B,R7
    DIV AB

    KTHUC:
    MOV 31H,A

    Hienthi:
    MOV A,31H
    MOV B,#10
    DIV AB ;HANG CHUC
    MOV DPTR,#MALED7
    MOVC A,@A+DPTR
    MOV P1,A ;XUAT MA RA LED 7 DOAN
    CLR P2.1
    SETB P2.1 ;TAO XUNG CANH LEN IC2
    MOV A,B ;HANG DON VI
    MOV DPTR,#MALED7
    MOVC A,@A+DPTR
    MOV P1,A ;XUAT MA RA LED 7 DOAN
    CLR P2.0
    SETB P2.0 ;TAO XUNG CANH LEN IC1
    CALL Delay
    JMP Main ;QUAY LAI TIEP TUC QUET PHIM

    MALED7: ; MA LED 7 DOAN

    DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H


    Delay: ; TAO THOI GIAN TRE(205X20MS)
    PUSH 07
    MOV R2,#205
    SETB TR0
    Delay1:
    MOV TH0,#HIGH(-20000)
    MOV TL0,#LOW(-20000)
    JNB TF0,$
    CLR TF0
    DJNZ R2,Delay1
    CLR TR0
    POP 07
    RET

    END
    Last edited by Thienprodhtd; 23-05-2012, 11:14.

  • #2
    bạn ơi có mạch máy tính bỏ tui khac không bạn
    Nguyên văn bởi Thienprodhtd Xem bài viết
    [ATTACH]45423[/ATTACH] để thực hiện 4 phép tính (cộng, trừ, nhân chia) đơn giản của 2 số hạng có 1 chữ số.

    Nhấp đúp vào hình để xem hình lớn hơn
    [ATTACH=CONFIG]45425[/ATTACH]

    Dưới đây la code chương trình

    ;-----------------------------------****CHUONG TRINH CHINH****-------------------

    ORG 00H
    MOV P0,#0FFH
    MOV R0,#1 ; BIEN SO HANG 1: SO HANG THU 1 ; 2: SO HANG THU 2
    MOV R1,#0 ; BIEN PHEP TOAN 1:+ ; 2:- ; 3:X ; 4:÷
    MOV R6,#0 ; SO HANG THU 1
    MOV R7,#0 ; SO HANG THU 2
    JMP Main

    Sw7:
    CJNE R0,#1,NH7
    MOV R6,#7
    MOV R0,#2
    MOV 31H,#7
    JMP Hienthi
    NH7:
    MOV R7,#7
    MOV R0,#1
    MOV 31H,#7
    JMP Hienthi

    Sw8:
    CJNE R0,#1,NH8
    MOV R6,#8
    MOV R0,#2
    MOV 31H,#8
    JMP Hienthi

    NH8:
    MOV R7,#8
    MOV R0,#1
    MOV 31H,#8
    JMP Hienthi

    Sw9:
    CJNE R0,#1,NH9
    MOV R6,#9
    MOV R0,#2
    MOV 31H,#9
    JMP Hienthi
    NH9:

    MOV R7,#9
    MOV R0,#1
    MOV 31H,#9
    JMP Hienthi

    Sw4:
    CJNE R0,#1,NH42
    MOV R6,#4
    MOV R0,#2
    MOV 31H,#4
    JMP Hienthi
    NH42:
    MOV R7,#4
    MOV R0,#1
    MOV 31H,#4
    JMP Hienthi

    Sw5:
    CJNE R0,#1,NH5
    MOV R6,#5
    MOV R0,#2
    MOV 31H,#5
    JMP Hienthi
    NH5:
    MOV R7,#5
    MOV R0,#1
    MOV 31H,#5
    JMP Hienthi

    Swcong:
    MOV R1,#1
    JMP Main

    Swtru:
    MOV R1,#2
    JMP Main

    Swnhan:
    MOV R1,#3
    JMP Main

    Swchia:
    MOV R1,#4
    JMP Main

    Main: ; QUET PHIM
    MOV P0,#0FEH ; COT CAC PHIM 7,8,9,÷
    JNB P0.4,Sw7
    JNB P0.5,Sw8
    JNB P0.6,Sw9
    JNB P0.7,Swchia

    MOV P0,#0FDH ; COT CAC PHIM 4,5,6,X
    JNB P0.4,Sw4
    JNB P0.5,Sw5
    JNB P0.6,Sw6
    JNB P0.7,Swnhan

    MOV P0,#0FBH ; COT CAC PHIM 1,2,3,-
    JNB P0.4,Sw1
    JNB P0.5,Sw2
    JNB P0.6,Sw3
    JNB P0.7,Swtru

    MOV P0,#0F7H ; COT CAC PHIM ON/C,0,=,+
    JNB P0.4,Swon
    JNB P0.5,Sw0
    JNB P0.6,Swbang
    JNB P0.7,Swcong
    SJMP Main

    Sw6:
    CJNE R0,#1,NH6
    MOV R6,#6
    MOV R0,#2
    MOV 31H,#6
    JMP Hienthi
    NH6:
    MOV R7,#6
    MOV R0,#1
    MOV 31H,#6
    JMP Hienthi

    Sw1:
    CJNE R0,#1,NH1
    MOV R6,#1
    MOV R0,#2
    MOV 31H,#1
    JMP Hienthi
    NH1:
    MOV R7,#1
    MOV R0,#1
    MOV 31H,#1
    JMP Hienthi

    Sw2:
    CJNE R0,#1,NH2
    MOV R6,#2
    MOV R0,#2
    MOV 31H,#2
    JMP Hienthi
    NH2:
    MOV R7,#2
    MOV R0,#1
    MOV 31H,#2
    JMP Hienthi

    Sw3:
    CJNE R0,#1,NH3
    MOV R6,#3
    MOV R0,#2
    MOV 31H,#3
    JMP Hienthi
    NH3:
    MOV R7,#3
    MOV R0,#1
    MOV 31H,#3
    JMP Hienthi

    Swon:
    MOV 31H,#0
    MOV R0,#1
    MOV R1,#0
    MOV R6,#0
    MOV R7,#0
    JMP Hienthi

    Sw0:
    CJNE R0,#1,NH0
    MOV R6,#0
    MOV R0,#2
    MOV 50H,#0
    JMP Hienthi
    NH0:
    MOV R7,#0
    MOV R0,#1
    MOV 31H,#0
    JMP Hienthi

    Swbang:
    CJNE R1,#1,KT02
    MOV A,R6
    ADD A,R7
    JMP KTHUC

    KT02:
    CJNE R1,#2,KT03
    MOV A,R6
    SUBB A,R7
    SJMP KTHUC

    KT03:
    CJNE R1,#3,KT04
    MOV A,R6
    MOV B,R7
    MUL AB
    SJMP KTHUC

    KT04:
    CJNE R1,#4,KTHUC
    MOV A,R6
    MOV B,R7
    DIV AB

    KTHUC:
    MOV 31H,A

    Hienthi:
    MOV A,31H
    MOV B,#10
    DIV AB ;HANG CHUC
    MOV DPTR,#MALED7
    MOVC A,@A+DPTR
    MOV P1,A ;XUAT MA RA LED 7 DOAN
    CLR P2.1
    SETB P2.1 ;TAO XUNG CANH LEN IC2
    MOV A,B ;HANG DON VI
    MOV DPTR,#MALED7
    MOVC A,@A+DPTR
    MOV P1,A ;XUAT MA RA LED 7 DOAN
    CLR P2.0
    SETB P2.0 ;TAO XUNG CANH LEN IC1
    CALL Delay
    JMP Main ;QUAY LAI TIEP TUC QUET PHIM

    MALED7: ; MA LED 7 DOAN

    DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H


    Delay: ; TAO THOI GIAN TRE(205X20MS)
    PUSH 07
    MOV R2,#205
    SETB TR0
    Delay1:
    MOV TH0,#HIGH(-20000)
    MOV TL0,#LOW(-20000)
    JNB TF0,$
    CLR TF0
    DJNZ R2,Delay1
    CLR TR0
    POP 07
    RET

    END

    Comment

    Về tác giả

    Collapse

    Thienprodhtd Tìm hiểu thêm về Thienprodhtd

    Bài viết mới nhất

    Collapse

    Đang tải...
    X