Mình đang lập trình asm trên 8051, đoạn code sau mình sử dụng ngắt timer 0, mỗi lần ngắt quét chân P1.0 thì hoặc chân P1.1 thì đảo chiều dich chữ chạy LCD nhưng không hiểu sao nó không chịu đỏi, mấy bạn coi giùm không biết cái code sai chỗ nào:
đây là mạch:
Bai_3.zip
ORG 0000H
EN BIT P3.4
RS BIT P3.5
LJMP MAIN
ORG 000BH
LJMP T0ISR
MAIN: MOV TMOD,#01H
CALL LCD_INIT
MOV DPTR,#TEXT
CALL DICHTRAI
MOV TH0,#HIGH(-10000)
MOV TL0,#LOW(-10000)
MOV IE,#82H
SETB TF0
SJMP $
T0ISR: CLR TR0
JNB P1.0,THOAT3
CALL DICHPHAI
JMP THOAT4
THOAT3: JNB P1.1,THOAT4
CALL DICHTRAI
MOV TH0,#HIGH(-10000)
MOV TL0,#LOW(-10000)
CLR TF0
SETB TR0
THOAT4: RETI
LCD_INIT:
MOV A,#38H
CALL WRITE_COM
MOV A,#0CH
CALL WRITE_COM
MOV A,#0H
CALL WRITE_COM
RET
WRITE_TEXT:
PUSH DPH
PUSH DPL
MOV DPTR,#8000H
LCALL WAIT_LCD
SETB RS
MOVX @DPTR, A
SETB EN
CLR EN
POP DPL
POP DPH
RET
WRITE_COM:
PUSH DPH
PUSH DPL
MOV DPTR,#8000H
LCALL WAIT_LCD
CLR RS
MOVX @DPTR, A
SETB EN
CLR EN
POP DPL
POP DPH
RET
DICHTRAI:
MOV A,#0D0H
CALL WRITE_COM
DT: CLR A
MOVC A,@A+DPTR
JZ THOAT ;Neu A=0 thi thi thoat
ACALL WRITE_TEXT
INC DPTR
JMP DT
THOAT: MOV A,#1CH ;Dich toan bo hien thi sang ben trai
CALL WRITE_COM
CALL DELAY
SJMP THOAT
DICHPHAI:
MOV A,#0B8H
CALL WRITE_COM
DP: CLR A
MOVC A,@A+DPTR
JZ THOAT2
ACALL WRITE_TEXT
INC DPTR
JMP DP
THOAT2:
MOV A,#18H
CALL WRITE_COM
CALL DELAY
SJMP THOAT2
WAIT_LCD:
MOV R7, #5
DEL1: MOV R6, #250
DJNZ R6, $
DJNZ R7, DEL1
RET
;DELAY: MOV R0,#200
;TT1: MOV TH0,#HIGH(-50000)
; MOV TL0,#LOW(-50000)
; SETB TR0
; JNB TF0,$
; DJNZ R0,TT1
; CLR TR0
; CLR TF0
; RET
DELAY: PUSH 02H
PUSH 01H
MOV R2,#100
DL5: MOV R1,#250
DL4: NOP
NOP
DJNZ R1,DL4
DJNZ R2,DL5
POP 02H
POP 01H
RET
TEXT: DB 'CHUC MUNG NAM MOI'
END
EN BIT P3.4
RS BIT P3.5
LJMP MAIN
ORG 000BH
LJMP T0ISR
MAIN: MOV TMOD,#01H
CALL LCD_INIT
MOV DPTR,#TEXT
CALL DICHTRAI
MOV TH0,#HIGH(-10000)
MOV TL0,#LOW(-10000)
MOV IE,#82H
SETB TF0
SJMP $
T0ISR: CLR TR0
JNB P1.0,THOAT3
CALL DICHPHAI
JMP THOAT4
THOAT3: JNB P1.1,THOAT4
CALL DICHTRAI
MOV TH0,#HIGH(-10000)
MOV TL0,#LOW(-10000)
CLR TF0
SETB TR0
THOAT4: RETI
LCD_INIT:
MOV A,#38H
CALL WRITE_COM
MOV A,#0CH
CALL WRITE_COM
MOV A,#0H
CALL WRITE_COM
RET
WRITE_TEXT:
PUSH DPH
PUSH DPL
MOV DPTR,#8000H
LCALL WAIT_LCD
SETB RS
MOVX @DPTR, A
SETB EN
CLR EN
POP DPL
POP DPH
RET
WRITE_COM:
PUSH DPH
PUSH DPL
MOV DPTR,#8000H
LCALL WAIT_LCD
CLR RS
MOVX @DPTR, A
SETB EN
CLR EN
POP DPL
POP DPH
RET
DICHTRAI:
MOV A,#0D0H
CALL WRITE_COM
DT: CLR A
MOVC A,@A+DPTR
JZ THOAT ;Neu A=0 thi thi thoat
ACALL WRITE_TEXT
INC DPTR
JMP DT
THOAT: MOV A,#1CH ;Dich toan bo hien thi sang ben trai
CALL WRITE_COM
CALL DELAY
SJMP THOAT
DICHPHAI:
MOV A,#0B8H
CALL WRITE_COM
DP: CLR A
MOVC A,@A+DPTR
JZ THOAT2
ACALL WRITE_TEXT
INC DPTR
JMP DP
THOAT2:
MOV A,#18H
CALL WRITE_COM
CALL DELAY
SJMP THOAT2
WAIT_LCD:
MOV R7, #5
DEL1: MOV R6, #250
DJNZ R6, $
DJNZ R7, DEL1
RET
;DELAY: MOV R0,#200
;TT1: MOV TH0,#HIGH(-50000)
; MOV TL0,#LOW(-50000)
; SETB TR0
; JNB TF0,$
; DJNZ R0,TT1
; CLR TR0
; CLR TF0
; RET
DELAY: PUSH 02H
PUSH 01H
MOV R2,#100
DL5: MOV R1,#250
DL4: NOP
NOP
DJNZ R1,DL4
DJNZ R2,DL5
POP 02H
POP 01H
RET
TEXT: DB 'CHUC MUNG NAM MOI'
END
Bai_3.zip
Comment