Thông báo

Collapse
No announcement yet.

giúp đỡ lập trình mạch đồng hồ bấm giờ thể thao dùng 8051 viết bằng ASM

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

  • giúp đỡ lập trình mạch đồng hồ bấm giờ thể thao dùng 8051 viết bằng ASM

    em chào các anh chị trong diễn đàn nhé!!!
    em đang hoc môn VXL, thầy bắt tụi em lam mạch đồng hồ bấm giờ thể thao lưu được 5 vận động viên.
    em tìm trên mạng thì thấy có 2 đoạn code của 2 mạch luôn, nhưng mà tụi em không biết vẽ hình làm sao cả mong mấy anh chị giúp đỡ nhé...
    ps: mạch có bốn nút bấm ( start, lưu vận động viên, reset, hiển thị vận động viên)



    code mạch đồng hồ 1
    ;here is assembly code
    org 0h mov 60h,#81h
    mov 61h,#0cfh ; 1.Storing data on specific memory location in ram
    mov 62h,#92h /////////
    mov 63h,#86h /////////
    mov 64h,#0cch /////////
    mov 65h,#0a4h /////////
    mov 66h,#0a0h /////////
    mov 67h,#8fh /////////
    mov 68h,#80h /////////
    mov 69h,#84h /////////

    jb p3.7,reset_1 ;To display 0000 on 7 seg when power on and on pressing button it statrs
    start:
    mov r7 ,#6 ;To increase number on extreme left 7 seg 6 times(0 to 5)
    setb rs1 ;select register bank 2
    mov r1,#60h ;move 60h to r1 to acsses data for extreme left 7 seg
    clr rs1 ;reject register bank 2

    label_3:
    mov r6,#10 ;To increase number on 2nd 7 seg from left 10 times(0 to 9)
    setb rs1
    mov r0,#60h ;move 60h to r0 to acsses data for 2nd 7 seg from left
    clr rs1

    label_2:
    mov r1,#60h ;move 60h to r1 to acsses data for 3rd 7 seg from left
    mov r5,#10 ;To increase number on 3rd 7 seg from left 10 times(0 to 9)
    label_1:

    mov r4,#10 ;To increase number on 4th 7 seg from left 10 times(0 to 9)
    mov r0,#60h ;move 60h to r0 to acsses data for 4th 7 seg from left
    label:

    mov r2,#7 ;for delay
    again:

    mov r3,#16 ;for delay




    here: mov a,@r0 ;move data on reg "a" from location saved in r0
    mov p2,a jnb p3.4,stop ;on preesing button watch stops
    clr p3.3 ;enable common anode of 4th 7 seg from left(it is clr p3.3 because transister convert it to setb p3.3)
    lcall delay
    setb p3.3 ;disable ////////////////////////////////// mov a,@r1 ;move data on reg "a" from location saved in r1
    mov p2,a
    jnb p3.4,stop
    clr p3.2
    lcall delay
    setb p3.2 setb rs1 ;select register bank 2 mov a,@r0 ;move data on reg "a" from location saved in r0 of bank 2
    mov p2 ,a
    jnb p3.4,stop
    clr p3.1
    clr p2.7 ;enable p2.7 to glow decimal point
    lcall delay setb p3.1 mov a,@r1 ;move data on reg "a: from location saved in r1 of bank 2
    mov p2,a
    jnb p3.4,stop
    clr p3.0
    lcall delay
    setb p3.0
    clr rs1 djnz r3,here ;for delay
    djnz r2,again ////////// inc r0 ;increase value in r0 of register bank 0 for 4th 7 seg from left
    djnz r4,label ;increase value for 4th 7 seg from left 10 times
    inc r1 ;increase value in r1 of register bank 0 for 3rd 7 seg from left
    djnz r5,label_1 ;increase value for 3rd 7 seg from left 10 times setb rs1 ;select register bank 2
    inc r0 ;increase value in r0 of register bank 2 for 2nd 7 seg from left
    clr rs1 ;reject register bank 2
    djnz r6 , label_2 ;increase value for 2nd 7 seg from left 10 times
    setb rs1
    inc r1 ;increase value in r1 of register bank 0 for 1st 7 seg from left clr rs1 djnz r7 , label_3 ;increase value for 1st 7 seg from left 6 times
    sjmp start

    here_1: sjmp here
    start_1: sjmp start
    reset_1: sjmp reset
    ////////////////////////////////////////­////////////////////////////////
    stop: mov a,@r0
    mov p2,a
    jnb p3.6,here ;p3.6 for resume
    jnb p3.5,reset ;p3.5 for rest
    clr p3.3
    lcall delay
    setb p3.3 mov a,@r1
    mov p2,a
    jnb p3.6,here
    jnb p3.5,reset
    clr p3.2
    lcall delay
    setb p3.2 setb rs1 mov a,@r0
    mov p2 ,a
    jnb p3.6,here_1
    jnb p3.5,reset
    clr p3.1
    clr p2.7
    lcall delay setb p3.1 mov a,@r1
    mov p2,a
    jnb p3.6,here_1
    jnb p3.5,reset
    clr p3.0
    lcall delay
    setb p3.0 clr rs1
    sjmp stop
    ////////////////////////////////////////­////////////////////////////////////////­/////
    reset: mov p2,#81h
    clr p3.3
    lcall delay
    setb p3.3 mov p2,#81h
    clr p3.2
    lcall delay
    setb p3.2 mov p2,#81h
    clr p3.1
    clr p2.7
    lcall delay setb p3.1
    mov p2,#81h
    clr p3.0
    lcall delay
    setb p3.0 jnb p3.7,start_1 ;p3.7 f0r start sjmp reset
    ////////////////////////////////////////­/////////////////////////////////////
    delay: setb rs0
    mov r2,#4

    gain: djnz r2,gain
    clr rs0
    ret

    end





    code mạch đồng hồ 2
    ORG 0
    LJMP MAIN
    ORG 0003H
    LJMP ISR_E0
    ORG 000BH
    LJMP ISR_T0
    ORG 0030H
    MAIN:
    MOV IE,#83H ; ngat timer0 , ngat ngoai 0
    SETB IT0 ;kich khoi canh xuong
    MOV TMOD,#01H
    JB P1.1,$
    LCALL DELAY10MS
    MOV TH0,#HIGH(-10000)
    MOV TL0,#LOW(-10000)
    SETB TR0
    MOV 16H,#0 ; luu phan tram giay
    MOV 17H,#0 ; --- giay
    MOV 18H,#0 ;luu phut
    MOV R1,#30H
    MOV R0,#30H ;o nho ban dau luu giu gia tri vdv
    MOV R7,#0 ; dem so lan xuat vdv

    LOOP:
    LCALL BIN_BCD ; chuyen sang dang bcd
    LCALL OUTLED ; xuat ra led
    CJNE R0,#3AH,LOOP
    JB P1.0,LOOP ; xem co phim nhan xuat vdv ko
    LCALL DELAY10MS
    NHAN_NUT:
    LCALL XUAT_VDV
    JnB P1.0,NHAN_NUT
    LCALL DELAY10MS
    BACK:
    LCALL XUAT_VDV
    JB P1.0,BACK
    LCALL DELAY10MS
    INC R7
    INC R1
    INC R1 ;xuat vdv tiep theo
    CJNE R7,#5,NHAN_NUT; da du 5 lan chua
    SETB P2.0
    SETB P2.1
    SETB P2.2
    SETB P2.3
    SETB EA
    SJMP MAIN
    ;************************************************* ********
    ISR_T0:
    CLR TR0
    MOV TH0,#HIGH(-10000)
    MOV TL0,#LOW(-10000)
    SETB TR0
    INC 16H; tang so phan tram giay len 1
    MOV A,16H
    CJNE A,#100,EXIT;da du 1giay chua
    MOV 16H,#0
    INC 17H; tang so giay len 1
    MOV A,17H
    CJNE A,#60,EXIT; da du 60 giay chua
    MOV 17H,#0
    INC 18H,# ;tang so phut len 1
    MOV A,18H
    CJNE A,#10,exit
    MOV 18H,#0
    EXIT:
    RETI
    ;************************************************* **********
    ISR_E0:
    MOV @R0,16H; dua so phan tram giay vao o nho 30h
    INC R0
    MOV @R0,17H; dua so giay vao o nho tiep theo
    INC R0
    MOV @R0,18H
    INC R0
    CJNE R0,#3AH,NHAY; da du 5 vdv chua
    CLR TR0
    CLR EA
    NHAY:
    RETI
    ;************************************************* **********
    ;****xuat van dong vien***
    XUAT_VDV:

    MOV A,@R1
    MOV B,#10
    INC R1
    DIV AB
    MOV 10H,B ; chuyen so hang don vi of phan tram giay vao o nho
    MOV 11H,A ; --------------- chuc -----------------
    MOV A,@R1
    MOV B,#10
    DIV AB
    MOV 12H,B ; chuyen so hang don vi of giay vao o nho
    MOV 13H,A ; -------------- chuc------------------
    MOV A,18H
    MOV 14H,A
    LCALL OUTLED
    DEC R1
    RET
    ;************************************************* *********
    BIN_BCD:
    MOV A,16H
    MOV B,#10
    DIV AB
    MOV 10H,B
    MOV 11H,A
    MOV A,17H
    MOV B,#10
    DIV AB
    MOV 12H,B
    MOV 13H,A
    MOV A,18H
    MOV 14H,A
    RET
    ;************************************************* *********
    OUTLED:
    MOV DPTR,#MALED
    MOV A,10H
    MOVC A,@A+DPTR
    MOV P0,A
    CLR P2.0
    LCALL DELAY_500US
    MOV DPTR,#MALED
    MOV A,11H
    MOVC A,@A+DPTR
    MOV P0,A
    CLR P2.1
    SETB P2.0
    LCALL DELAY_500US
    MOV DPTR,#MALED
    MOV A,12H
    MOVC A,@A+DPTR
    MOV P0,A
    CLR P2.2
    SETB P2.1
    LCALL DELAY_500US
    MOV DPTR,#MALED
    MOV A,13H
    MOVC A,@A+DPTR
    MOV P0,A
    CLR P2.3
    SETB P2.2
    LCALL DELAY_500US
    MOV DPTR,#MALED
    MOV A,18H
    MOVC A,@A+DPTR
    MOV P0,A
    CLR P2.4
    SETB P2.3
    RET
    DELAY_500US:
    MOV R6,#250
    DJNZ R6,$
    RET
    DELAY10MS:
    MOV R2,#25
    AGAIN:
    MOV R3,#200
    DJNZ R3,$
    DJNZ R2,AGAIN
    RET
    MALED: DB 09H,0BDH,13H,91H,0A5H
    DB 0C1H,41H,9DH,01H,81H
    END

Về tác giả

Collapse

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

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

Collapse

Đang tải...
X