Thông báo

Collapse
No announcement yet.

chỉ dẫn đèn giao thông

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

  • chỉ dẫn đèn giao thông

    em đang làm cái đồ án thí nghiệm vi xử lý về đèn giao thông.mai nộp rồi mà giờ còn sai tùm lum.các bác ai rành giúp em sửa lại với
    ORG 0X0000H
    LJMP MAIN
    ORG 0X0023H
    LJMP USART_ISR
    ORG 0X000BH
    LJMP TIMER0_ISR

    DB0 EQU P1.0
    DB1 EQU P1.1
    DB2 EQU P1.2
    DB3 EQU P1.3
    DB4 EQU P1.4
    DB5 EQU P1.5
    DB6 EQU P1.6
    DB7 EQU P1.7
    RS EQU P2.5
    EN EQU P2.6
    RW EQU P2.7
    DATA EQU P1
    RED EQU P2.1
    YELLOW EQU P2.2
    GREEN EQU P2.3
    TX EQU P3.1
    RX EQU P3.0
    LEDR EQU P3.2
    LEDY EQU P3.3
    LEDG EQU P3.4
    LED7DV EQU P0
    LED7CH EQU PX

    MAIN : SETB RX
    SETB RED
    SETB YELLOW
    SETB GREEN
    MOV DPTR,#LUT
    LCD_INT
    MOV TMOD,#21H
    CLR TF0
    MOV TH0,#HIGH(-10000)
    MOV TL0,LOW(-10000)
    SETB TR0
    MOV SCON,#51H
    MOV TH1,#-3 ; TOC DO 9600 BUAD
    SETB TR1
    MOV IE,#92H ; CHO PHEP NGAT VOI CONG NOI TIEP VA TIMER
    MOV IP,10H ; UU TIEN CHO NGAT CONG NOI TIEP
    MOV R1,#15
    MOV R2,#3
    MOV R3,#45
    LOOP :
    JNB RED,TIEP_1
    CLR LEDG
    CLR LEDY
    SETB LEDR
    LCALL CLEAR_LCD
    MOV A,#'D'
    LCALL WRITE_LCD
    MOV A,#'U'
    LCALL WRITE_LCD
    MOV A,#'N'
    LCALL WRITE_LCD
    MOV A,'G'
    LCALL WRITE_LCD
    JMP VONG
    TIEP_1:
    JNB YELLOW,TIEP_2
    SETB LEDY
    CLR LEDG
    CLR LEDR
    LCALL CLEAR_LCD
    MOV A,#'D'
    LCALL WRITE_LCD
    MOV A,#'U'
    LCALL WRITE_LCD
    MOV A,#'N'
    LCALL WRITE_LCD
    MOV A,#'G'
    LCALL WRITE_LCD
    JMP VONG
    TIEP_2:
    JNB GREEN,VONG
    SETB LEDG
    CLR LEDR
    CLR LEDY
    LCALL CLEAR_LCD
    MOV A,#'D'
    LCALL WRITE_LCD
    MOV A,#'I'
    LCALL WRITE_LCD
    VONG:
    LJMP LOOP


    USART_ISR:
    JB TI,TRANS ; nhay den TRANs va thoat ra ngoai neu co Ti duoc bat
    MOV A,SBUF ; neu bat co bao Ri thi lay gia tri ve
    ANL A,#7FH ; lay ve ma ASCII
    CJNE R7,#3,INS_1 ; ma lenh nay dung de chi ra den nao duco dung
    CJNE R7,#2,INS_2 ; so hang chuc
    CJNE R7,#1,INS_3 ; so hang don vi
    CLR RI ; xoa co Ri de chuan bi cho lan ngat tiep theo
    RETI ; tro ve chuong trinh main
    INS_1:
    CJNE A,#68,KHAC_DEN_DO
    MOV R0,#11000000B
    JMP THOAT_1
    KHAC_DEN_DO:
    CJNE A,#86,KHAC_DEN_VANG
    MOV R0,#10000000B
    JMP THOAT_1
    KHAC_DEN_VANG:
    CJNE A,#88,KHAC_DEN_XANH
    MOV R0,#01000000B
    JMP THOAT_1
    KHAC_DEN_XANH:
    CLR RI
    RETI
    THOAT_1 :
    DEC R7
    JMP THOAT
    INS_2:
    CLR C
    SUBB A,#48
    MOV B,#10
    MUL AB
    ADD A,R0
    MOV R0,A
    DEC R7
    JMP THOAT
    INS_3:
    CLR C
    ADD A,R0
    MOV R0,A
    DEC R7
    JMP THOAT
    THOAT:
    CJNE R7,#0,OUT
    CALL UPDATE_REG
    MOV R7,#3
    JMP OUT
    OUT:
    CLR RI
    RETI
    TRANS:
    CLR TI ; xoa co Ti chuan bi cho ngat ke tiep
    RETI ; tro ve chuong trinh main


    TIMER0_ISR:
    CLR TR0 ;dung timer0
    CJNE R4,#3,KHAC_DO
    SETB LEDR
    CLR LEDG
    CLR LEDY
    LCALL CLEAR_LCD
    MOV A,#'D'
    LCALL WRITE_LCD
    MOV A,#'U'
    LCALL WRITE_LCD
    MOV A,#'N'
    LCALL WRITE_LCD
    MOV A,'G'
    LCALL WRITE_LCD
    CJNE R5,#1,DEM_1S
    DJNZ R6,DEM_1S
    DEC R4
    MOVE R6,R3
    JMP RA
    KHAC_DO:
    CJNE R4,#2,KHAC_XANH
    SETB LEDG
    CLR LEDR
    CLR LEDY
    LCALL CLEAR_LCD
    MOV A,#'D'
    LCALL WRITE_LCD
    MOV A,#'I'
    LCALL WRITE_LCD
    CJNE R5,#1,DEM_1S
    DJNZ R6,DEM_1S
    DEC R4
    MOVE R6,R2
    JMP RA
    KHAC_XANH:
    CJNE R4,#1,KHAC
    SETB LEDY
    CLR LEDG
    CLR LEDR
    LCALL CLEAR_LCD
    MOV A,#'D'
    LCALL WRITE_LCD
    MOV A,#'U'
    LCALL WRITE_LCD
    MOV A,#'N'
    LCALL WRITE_LCD
    MOV A,#'G'
    LCALL WRITE_LCD
    CJNE R5,#1,DEM_1S
    DJNZ R6,DEM_1S
    DEC R4
    MOVE R6,R1
    JMP RA
    KHAC:
    MOV R4,#3
    JMP RA
    DEM_1S:
    MOV A,R6
    MOV B,#10
    DIV AB
    MOV A,@A + DPTR
    MOV LED7CH,A
    MOV A,R6
    MOV B,#10
    DIV AB
    MOV A,B
    MOV A,@A +DPTR
    MOV LED7DV,A
    DJNZ R5,DEM_10US
    MOV R5,#100
    JMP RA
    DEM_10US:
    MOV TH0,#HIGH(-10000)
    MOV TL0,#LOW(-10000)
    JMP RA
    RA:
    CLR TF0
    SETB TR0
    RETI

    UPDATE_REG:
    MOV A,R0
    ANL A,#11000000B
    CJNE A,#11000000B,CON_1
    MOV A,R0
    ANL A,#00111111B
    NOV R0,A
    MOV R1,R0 ;R1 LUU GIA TRI THOI GIAN DEN DO
    JMP VE
    CON_1:
    CJNE A,#10000000B,CON_2
    MOV A,R0
    ANL A,#00111111B
    NOV R0,A
    MOV R2,R0 ; R2 LUU GIA TRI THOI GIAN DEN VANG
    JMP VE
    CON_2
    CJNE A,#01000000,VE
    MOV A,R0
    ANL A,#00111111B
    NOV R0,A
    MOV R3,R0 ;R3 LUU GIA TRI THOI GIAN DEN XANH
    VE:
    RET
    LCD_INT:
    SETB EN
    CLR RS
    MOV DATA,#38H
    CLR EN
    LCALL WAIT_LCD
    SETB EN
    CLR RS
    MOV DATA,#0EH
    CLR EN
    LCALL WAIT_LCD
    SETB EN
    CLR RS
    MOV DATA,#06H
    CLR EN
    LCALL WAIT_LCD
    RET
    WAIT_LCD:
    SETB EN
    CLR RS
    SETB RW
    MOV DATA,#0FFH
    MOV A,DATA
    JB ACC.7,WAIT_LCD
    CLR EN
    CLR RW
    RET
    CLEAR_LCD:
    SETB EN
    CLR RS
    MOV DATA,#01H
    CLR EN
    LCALL WAIT_LCD
    RET
    WRITE_TEXT:
    SETB EN
    SETB RS
    MOV DATA,A
    CLR EN
    LCALL WAIT_LCD
    RET
    LUT: DB 126,48,47,121,55,91,95,112,127,123

Về tác giả

Collapse

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

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

Collapse

Đang tải...
X