Thông báo

Collapse
No announcement yet.

Các bạn xem dùm mình đoạn mã này với, khó hiểu thật

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

  • Các bạn xem dùm mình đoạn mã này với, khó hiểu thật

    sh bit p2.0
    st bit p2.2
    da_ta bit p2.1

    org 0000h

    ljmp main

    org 30H
    main:
    clr sh
    clr st
    MOV R1,0 ;
    MOV R2,#256 ; nó báo sai chổ này, nhưng mình kiểm tra thì đâu có vượt quá 256 byte đâu
    MOV R3,#4 ;
    mov dptr,#mydata

    LOOP1: mov r4,#8 ;
    mov a,R1
    movc a,@a+dptr

    loop2:
    clr c
    rlc a
    mov da_ta,c
    setb sh
    clr sh
    djnz r4,loop2 ;
    inc R1
    djnz r3,LOOP1 ;
    setb st
    clr st
    lcall delay
    INC DPTR
    INC DPTR
    INC DPTR
    INC DPTR ;
    djnz r2,LOOP1
    ljmp main

    ;=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+

    delay:
    mov r7,#100
    d0: mov r6,#100
    here: NOP
    nop
    djnz r6,here
    djnz r7,d0
    ret

    ;=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+

    org 300h
    mydata:
    db 00000000b,00000001b,10000000b,00000000b
    db 00000000b,00000010b,01000000b,00000000b
    db 00000000b,00000100b,00100000b,00000000b
    db 00000000b,00001000b,00010000b,00000000b
    db 00000000b,00010000b,00001000b,00000000b
    db 00000000b,00100000b,00000100b,00000000b
    db 00000000b,01000000b,00000010b,00000000b
    db 00000000b,10000000b,00000001b,00000000b
    db 00000001b,00000000b,00000000b,10000000b
    db 00000010b,00000000b,00000000b,01000000b
    db 00000100b,00000000b,00000000b,00100000b
    db 00001000b,00000000b,00000000b,00010000b
    db 00010000b,00000000b,00000000b,00001000b
    db 00100000b,00000000b,00000000b,00000100b
    db 01000000b,00000000b,00000000b,00000010b
    db 10000000b,00000000b,00000000b,00000001b
    db 10000000b,00000000b,00000000b,00000001b
    db 01000000b,00000000b,00000000b,00000010b
    db 00100000b,00000000b,00000000b,00000100b
    db 00010000b,00000000b,00000000b,00001000b
    db 00001000b,00000000b,00000000b,00010000b
    db 00000100b,00000000b,00000000b,00100000b
    db 00000010b,00000000b,00000000b,01000000b
    db 00000001b,00000000b,00000000b,10000000b
    db 00000000b,10000000b,00000001b,00000000b
    db 00000000b,01000000b,00000010b,00000000b
    db 00000000b,00100000b,00000100b,00000000b
    db 00000000b,00010000b,00001000b,00000000b
    db 00000000b,00001000b,00010000b,00000000b
    db 00000000b,00000100b,00100000b,00000000b
    db 00000000b,00000010b,01000000b,00000000b
    db 00000000b,00000001b,10000000b,00000000b ;1


    db 00000000b,00000001b,10000000b,00000000b
    db 00000000b,00000011b,11000000b,00000000b
    db 00000000b,00000111b,11100000b,00000000b
    db 00000000b,00001111b,11110000b,00000000b
    db 00000000b,00011111b,11111000b,00000000b
    db 00000000b,00111111b,11111100b,00000000b
    db 00000000b,01111111b,11111110b,00000000b
    db 00000000b,11111111b,11111111b,00000000b
    db 00000001b,11111111b,11111111b,10000000b
    db 00000011b,11111111b,11111111b,11000000b
    db 00000111b,11111111b,11111111b,11100000b
    db 00001111b,11111111b,11111111b,11110000b
    db 00011111b,11111111b,11111111b,11111000b
    db 00111111b,11111111b,11111111b,11111100b
    db 01111111b,11111111b,11111111b,11111110b
    db 11111111b,11111111b,11111111b,11111111b
    db 11111111b,11111111b,11111111b,11111111b
    db 01111111b,11111111b,11111111b,11111110b
    db 00111111b,11111111b,11111111b,11111100b
    db 00011111b,11111111b,11111111b,11111000b
    db 00001111b,11111111b,11111111b,11110000b
    db 00000111b,11111111b,11111111b,11100000b
    db 00000011b,11111111b,11111111b,11000000b
    db 00000001b,11111111b,11111111b,10000000b
    db 00000000b,11111111b,11111111b,00000000b
    db 00000000b,01111111b,11111110b,00000000b
    db 00000000b,00111111b,11111100b,00000000b
    db 00000000b,00011111b,11111000b,00000000b
    db 00000000b,00001111b,11110000b,00000000b
    db 00000000b,00000111b,11100000b,00000000b
    db 00000000b,00000011b,11000000b,00000000b
    db 00000000b,00000001b,10000000b,00000000b ;2

    db 11111111b,11111111b,11111111b,11111111b
    db 11111111b,11111110b,01111111b,11111111b
    db 11111111b,11111100b,00111111b,11111111b
    db 11111111b,11111000b,00011111b,11111111b
    db 11111111b,11110000b,00001111b,11111111b
    db 11111111b,11100000b,00000111b,11111111b
    db 11111111b,11000000b,00000011b,11111111b
    db 11111111b,10000000b,00000001b,11111111b
    db 11111111b,00000000b,00000000b,11111111b
    db 11111110b,00000000b,00000000b,01111111b
    db 11111100b,00000000b,00000000b,00111111b
    db 11111000b,00000000b,00000000b,00011111b
    db 11110000b,00000000b,00000000b,00001111b
    db 11100000b,00000000b,00000000b,00000111b
    db 11000000b,00000000b,00000000b,00000011b
    db 10000000b,00000000b,00000000b,00000001b
    db 10000000b,00000000b,00000000b,00000001b
    db 11000000b,00000000b,00000000b,00000011b
    db 11100000b,00000000b,00000000b,00000111b
    db 11110000b,00000000b,00000000b,00001111b
    db 11111000b,00000000b,00000000b,00011111b
    db 11111100b,00000000b,00000000b,00111111b
    db 11111110b,00000000b,00000000b,01111111b
    db 11111111b,00000000b,00000000b,11111111b
    db 11111111b,10000000b,00000001b,11111111b
    db 11111111b,01000000b,00000011b,11111111b
    db 11111111b,11100000b,00000111b,11111111b
    db 11111111b,11110000b,00001111b,11111111b
    db 11111111b,11111000b,00011111b,11111111b
    db 11111111b,11111100b,00111111b,11111111b
    db 11111111b,11111110b,01111111b,11111111b
    db 11111111b,11111111b,11111111b,11111111b ;3

    db 01111111b,11111111b,11111111b,11111110b
    db 00111111b,11111111b,11111111b,11111100b
    db 00011111b,11111111b,11111111b,11111000b
    db 00001111b,11111111b,11111111b,11110000b
    db 00000111b,11111111b,11111111b,11100000b
    db 00000011b,11111111b,11111111b,11000000b
    db 00000001b,11111111b,11111111b,10000000b
    db 00000000b,11111111b,11111111b,00000000b
    db 00000000b,01111111b,11111110b,00000000b
    db 00000000b,00111111b,11111100b,00000000b
    db 00000000b,00011111b,11111000b,00000000b
    db 00000000b,00001111b,11110000b,00000000b
    db 00000000b,00000111b,11100000b,00000000b
    db 00000000b,00000011b,11000000b,00000000b
    db 00000000b,00000001b,10000000b,00000000b
    db 00000000b,00000001b,10000000b,00000000b
    db 00000000b,00000011b,11000000b,00000000b
    db 00000000b,00000111b,11100000b,00000000b
    db 00000000b,00001111b,11110000b,00000000b
    db 00000000b,00011111b,11111000b,00000000b
    db 00000000b,00111111b,11111100b,00000000b
    db 00000000b,01111111b,11111110b,00000000b
    db 00000000b,11111111b,11111111b,00000000b
    db 00000001b,11111111b,11111111b,10000000b
    db 00000011b,11111111b,11111111b,11000000b
    db 00000111b,11111111b,11111111b,11100000b
    db 00001111b,11111111b,11111111b,11110000b
    db 00011111b,11111111b,11111111b,11111000b
    db 00111111b,11111111b,11111111b,11111100b
    db 01111111b,11111111b,11111111b,11111110b
    db 11111111b,11111111b,11111111b,11111111b
    db 11111111b,11111111b,11111111b,11111111b ;4

    db 10000000b,00000000b,00000000b,00000001b
    db 11000000b,00000000b,00000000b,00000011b
    db 11100000b,00000000b,00000000b,00000111b
    db 11110000b,00000000b,00000000b,00001111b
    db 11111000b,00000000b,00000000b,00011111b
    db 11111100b,00000000b,00000000b,00111111b
    db 11111110b,00000000b,00000000b,01111111b
    db 11111111b,00000000b,00000000b,11111111b
    db 11111111b,10000000b,00000001b,11111111b
    db 11111111b,11000000b,00000011b,11111111b
    db 11111111b,11100000b,00000111b,11111111b
    db 11111111b,11110000b,00001111b,11111111b
    db 11111111b,11111000b,00011111b,11111111b
    db 11111111b,11111100b,00111111b,11111111b
    db 11111111b,11111110b,01111111b,11111111b
    db 11111111b,11111111b,11111111b,11111111b
    db 11111111b,11111111b,11111111b,11111111b
    db 11111111b,11111110b,01111111b,11111111b
    db 11111111b,11111100b,00111111b,11111111b
    db 11111111b,11111000b,00011111b,11111111b
    db 11111111b,11110000b,00001111b,11111111b
    db 11111111b,11100000b,00000111b,11111111b
    db 11111111b,11000000b,00000011b,11111111b
    db 11111111b,10000000b,00000001b,11111111b
    db 11111111b,00000000b,00000000b,11111111b
    db 11111110b,00000000b,00000000b,01111111b
    db 11111100b,00000000b,00000000b,00111111b
    db 11111000b,00000000b,00000000b,00011111b
    db 11110000b,00000000b,00000000b,00001111b
    db 11100000b,00000000b,00000000b,00000111b
    db 11000000b,00000000b,00000000b,00000011b
    db 10000000b,00000000b,00000000b,00000001b ;5



    db 10000000b,00000000b,00000000b,00000000b
    db 01000000b,00000000b,00000000b,00000000b
    db 00100000b,00000000b,00000000b,00000000b
    db 00010000b,00000000b,00000000b,00000000b
    db 00001000b,00000000b,00000000b,00000000b
    db 00000100b,00000000b,00000000b,00000000b
    db 00000010b,00000000b,00000000b,00000000b
    db 00000001b,00000000b,00000000b,00000000b
    db 00000000b,10000000b,00000000b,00000000b
    db 00000000b,01000000b,00000000b,00000000b
    db 00000000b,00100000b,00000000b,00000000b
    db 00000000b,00010000b,00000000b,00000000b
    db 00000000b,00001000b,00000000b,00000000b
    db 00000000b,00000100b,00000000b,00000000b
    db 00000000b,00000010b,00000000b,00000000b
    db 00000000b,00000001b,00000000b,00000000b
    db 00000000b,00000000b,10000000b,00000000b
    db 00000000b,00000000b,01000000b,00000000b
    db 00000000b,00000000b,00100000b,00000000b
    db 00000000b,00000000b,00010000b,00000000b
    db 00000000b,00000000b,00001000b,00000000b
    db 00000000b,00000000b,00000100b,00000000b
    db 00000000b,00000000b,00000010b,00000000b
    db 00000000b,00000000b,00000001b,00000000b
    db 00000000b,00000000b,00000000b,10000000b
    db 00000000b,00000000b,00000000b,01000000b
    db 00000000b,00000000b,00000000b,00100000b
    db 00000000b,00000000b,00000000b,00010000b
    db 00000000b,00000000b,00000000b,00001000b
    db 00000000b,00000000b,00000000b,00000100b
    db 00000000b,00000000b,00000000b,00000010b
    db 00000000b,00000000b,00000000b,00000001b ;6

    db 00000000b,00000000b,00000000b,00000001b
    db 00000000b,00000000b,00000000b,00000010b
    db 00000000b,00000000b,00000000b,00000100b
    db 00000000b,00000000b,00000000b,00001000b
    db 00000000b,00000000b,00000000b,00010000b
    db 00000000b,00000000b,00000000b,00100000b
    db 00000000b,00000000b,00000000b,01000000b
    db 00000000b,00000000b,00000000b,10000000b
    db 00000000b,00000000b,00000001b,00000000b
    db 00000000b,00000000b,00000010b,00000000b
    db 00000000b,00000000b,00000100b,00000000b
    db 00000000b,00000000b,00001000b,00000000b
    db 00000000b,00000000b,00010000b,00000000b
    db 00000000b,00000000b,00100000b,00000000b
    db 00000000b,00000000b,01000000b,00000000b
    db 00000000b,00000000b,10000000b,00000000b
    db 00000000b,00000001b,00000000b,00000000b
    db 00000000b,00000010b,00000000b,00000000b
    db 00000000b,00000100b,00000000b,00000000b
    db 00000000b,00001000b,00000000b,00000000b
    db 00000000b,00010000b,00000000b,00000000b
    db 00000000b,00100000b,00000000b,00000000b
    db 00000000b,01000000b,00000000b,00000000b
    db 00000000b,10000000b,00000000b,00000000b
    db 00000001b,00000000b,00000000b,00000000b
    db 00000010b,00000000b,00000000b,00000000b
    db 00000100b,00000000b,00000000b,00000000b
    db 00001000b,00000000b,00000000b,00000000b
    db 00010000b,00000000b,00000000b,00000000b
    db 00100000b,00000000b,00000000b,00000000b
    db 01000000b,00000000b,00000000b,00000000b
    db 10000000b,00000000b,00000000b,00000000b ;7

    db 00000000b,00000000b,00000000b,00000000b
    db 00000000b,00000000b,00000000b,00000000b
    db 00000000b,00000000b,00000000b,00000000b
    db 00000000b,00000000b,00000000b,00000000b
    db 11111111b,11111111b,11111111b,11111111b
    db 11111111b,11111111b,11111111b,11111111b
    db 11111111b,11111111b,11111111b,11111111b
    db 11111111b,11111111b,11111111b,11111111b
    db 00000000b,00000000b,00000000b,00000000b
    db 00000000b,00000000b,00000000b,00000000b
    db 00000000b,00000000b,00000000b,00000000b
    db 00000000b,00000000b,00000000b,00000000b
    db 11111111b,11111111b,11111111b,11111111b
    db 11111111b,11111111b,11111111b,11111111b
    db 11111111b,11111111b,11111111b,11111111b
    db 11111111b,11111111b,11111111b,11111111b
    db 00000000b,00000000b,00000000b,00000000b
    db 00000000b,00000000b,00000000b,00000000b
    db 00000000b,00000000b,00000000b,00000000b
    db 00000000b,00000000b,00000000b,00000000b
    db 11111111b,11111111b,11111111b,11111111b
    db 11111111b,11111111b,11111111b,11111111b
    db 11111111b,11111111b,11111111b,11111111b
    db 11111111b,11111111b,11111111b,11111111b
    db 00000000b,00000000b,00000000b,00000000b
    db 00000000b,00000000b,00000000b,00000000b
    db 00000000b,00000000b,00000000b,00000000b
    db 00000000b,00000000b,00000000b,00000000b
    db 11111111b,11111111b,11111111b,11111111b
    db 11111111b,11111111b,11111111b,11111111b
    db 11111111b,11111111b,11111111b,11111111b
    db 11111111b,11111111b,11111111b,11111111b ;8


    ;=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+


    end

    mình dùng MCS-51 IDE mô phỏng thì nó báo lỗi expression out of range ???. Nhưng nó vẫn xuất files hex ra và vẫn chạy bình thường như mình muốn, không hiểu sao. Bạn nào rành giải thích giùm mình với, mới tập tành ASM nên còn gà

  • #2
    Mình rất thích vụ này , đang được học 8051 vs ngôn ngữ máy asm vài bửa nay ,mới chỉ viết được code điều khiển 1port chạy hiệu ứng của 8 led à (89c51), các bạn biết viết code cách nào mà port 1 vừa chạy xong đến port2 rồi các port còn lại ko ,mình viết thử nhưng khi port1 chạy port2 cũng chạy theo luôn(ý là nó chạy song song ) , đoạn code của mình nè các bạn xem rồi cho mình ý nha cảm ơn vẻy much
    chúc các bạn thật nhiều sức khỏe để theo đuổi đam mê nha

    org 00h
    main:
    mov p1,#10101010b
    acall delay
    mov p1,#01010101b
    acall delay
    mov p2,#00001111b
    acall delay
    mov p2,#11110000b
    acall delay
    mov p2,#10000000b
    acall delay
    mov p2,#01000000b
    acall delay
    mov p2,#00100000b
    acall delay
    mov p2,#00010000b
    acall delay
    mov p2,#00001000b
    acall delay
    mov p2,#00001000b
    acall delay
    mov p2,#00000100b
    acall delay
    mov p2,#00000010b
    acall delay
    mov p2,#00000001b
    acall delay
    mov p0,#11111111b
    sjmp main
    delay:
    mov r2,#10
    loop:
    mov tmod,#00010000b
    mov tl1,#low(-1000)
    mov th1,#high(-1000)
    setb tr1
    jnb tf1,$
    clr tr1
    clr tf1
    djnz r0,loop
    ret
    end

    Comment


    • #3
      Bác phải sửa lại là :
      mov r2,#255
      Bởi vì đó là thanh ghi 8bit thi giá trị cực đại là 0FFH = 255
      Nếu mà bảng mã nhiều hơn 255 thi bác phải dùng thêm 01 thanh ghi nua để tạo vòng lặp lồng

      Comment


      • #4
        org 00h
        main:
        mov p1,#10101010b
        acall delay
        mov p1,#01010101b
        acall delay
        mov p1,#0
        acall delay

        mov p2,#00001111b
        acall delay
        mov p2,#11110000b
        acall delay
        mov p2,#10000000b
        acall delay
        mov p2,#01000000b
        acall delay
        mov p2,#00100000b
        acall delay
        mov p2,#00010000b
        acall delay
        mov p2,#00001000b
        acall delay
        mov p2,#00001000b
        acall delay
        mov p2,#00000100b
        acall delay
        mov p2,#00000010b
        acall delay
        mov p2,#00000001b
        acall delay
        mov p0,#11111111b
        sjmp main
        delay:
        mov r2,#10
        loop:
        mov tmod,#00010000b
        mov tl1,#low(-1000)
        mov th1,#high(-1000)
        setb tr1
        jnb tf1,$
        clr tr1
        clr tf1
        djnz r0,loop
        ret
        end
        Bác chỉ cần thêm chổ chử đỏ là đựơc tức là bác phải tắt Port1 trứơc, do bác chưa xóa Port 1 nên có cảm giác 2 Port đều chạy
        Last edited by phucan2104; 11-03-2012, 02:06.

        Comment


        • #5
          Nguyên văn bởi phucan2104 Xem bài viết
          Bác phải sửa lại là :
          mov r2,#255
          Bởi vì đó là thanh ghi 8bit thi giá trị cực đại là 0FFH = 255
          Nếu mà bảng mã nhiều hơn 255 thi bác phải dùng thêm 01 thanh ghi nua để tạo vòng lặp lồng
          Ah ra vậy mình tính 8*32=256 mà quên tính số 0 vô hèn chi nó báo lỗi hoài thank bạn nhiều nha

          Comment

          Về tác giả

          Collapse

          [VN]NMD Tìm hiểu thêm về [VN]NMD

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

          Collapse

          Đang tải...
          X