đây là code... không biết có lỗi gì không nhưng khi nappj cho 89c51 thì chạy rất thất thường
$MOD51
ORG 00H
JMP MAIN
ORG 23H
JMP NGAT
ORG 30H
MAIN:
LCALL TIMER
NUT:
JB P1.0,TIEP1
MOV R6,#'A'
SETB TI
LCALL SANGDUOI
TIEP1:
JB P1.1,TIEP2
MOV R6,#'B'
SETB TI
LCALL SANGDAN
TIEP2:
JB P1.2,TIEP3
MOV R6,#'C'
SETB TI
LCALL DUOIDON
TIEP3:
JB P1.3,NUT
MOV R6,#'D'
SETB TI
LCALL STOP
SJMP NUT
;************************************************* *******
LOOP:
MOV R7,50H
CJNE R7,#'1',KT1
LCALL SANGDUOI
KT1:
CJNE R7,#'2',KT2
LCALL SANGDAN
KT2:
CJNE R7,#'3',KT3
LCALL DUOIDON
KT3:
CJNE R7,#'4',LOOP
LCALL STOP; TAT LED
;************************************************* *************
SANGDUOI:
CLR P1.4
SETB P1.5
SETB P1.6
SETB P1.7
MOV R0,#00H
MOV DPTR,#DATADISH1
LAP1:
MOV A,R0
MOVC A,@A+DPTR
MOV P0,A
LCALL DELAY
INC R0
MOV R7,50H
CJNE R7,#'2',LOP1
JMP SANGDAN
LOP1:
CJNE R7,#'3',LOP2
JMP DUOIDON
LOP2:
CJNE R7,#'4',LOP3
JMP STOP
LOP3:
CJNE R7,#36,LAP1
SJMP SANGDUOI
DATADISH1:
DB 0FEH,0FDH,0FBH,0F7H,0EFH,0DFH,0BFH,7FH
DB 7EH,7DH,7BH,77H,6FH,5FH,3FH
DB 3EH,3DH,3BH,37H,2FH,1FH
DB 1EH,1DH,1BH,17H,0FH
DB 0EH,0DH,0BH,07H
DB 06H,05H,03H
DB 02H,01H
DB 00H
;************************************************* ************
SANGDAN:
CLR P1.5
SETB P1.4
SETB P1.6
SETB P1.7
MOV R1,#00H
MOV DPTR,#DATADISH2
LAP2:
MOV A,R1
MOVC A,@A+DPTR
MOV P0,A
LCALL DELAY
INC R1
MOV R7,50H
CJNE R7,#'1',LOP1A
LCALL SANGDUOI
LOP1A:
CJNE R7,#'3',LOP2A
LCALL DUOIDON
LOP2A:
CJNE R7,#'4',LOP3A
LCALL STOP
LOP3A:
CJNE R7,#9,LAP2
SJMP SANGDAN
DATADISH2:
DB 0FFH,0FEH,0FCH,0F8H,0F0H,0E0H,0C0H,80H,00H
;************************************************* ************
DUOIDON:
CLR P1.6
SETB P1.5
SETB P1.4
SETB P1.7
MOV R2,#00H
MOV DPTR,#DATADISH3
LAP3:
MOV A,R2
MOVC A,@A+DPTR
MOV P0,A
LCALL DELAY
INC R2
MOV R7,50H
CJNE R7,#'1',LOP1B
JMP SANGDUOI
LOP1B:
CJNE R7,#'2',LOP2B
JMP SANGDAN
LOP2B:
CJNE R7,#'4',LOP3B
JMP STOP
LOP3B:
CJNE R7,#36,LAP3
SJMP DUOIDON
DATADISH3:
DB 0FEH,0FDH,0FBH,0F7H,0EFH,0DFH,0BFH,7FH
DB 7EH,7DH,7BH,77H,6FH,5FH,3FH
DB 3EH,3DH,3BH,37H,2FH,1FH
DB 1EH,1DH,1BH,17H,0FH
DB 0EH,0DH,0BH,07H
DB 06H,05H,03H
DB 02H,01H
DB 00H
;************************************************* ************
STOP:
CLR P1.7
SETB P1.5
SETB P1.6
SETB P1.4
MOV R7,50H
CJNE R7,#'1',LOP1C
JMP SANGDUOI
LOP1C:
CJNE R7,#'2',LOP2C
JMP SANGDAN
LOP2C:
CJNE R7,#'3',LOP3C
JMP DUOIDON
LOP3C:
MOV P0,#0FFH
LCALL DELAY
SJMP STOP
;************************************************* ************
DELAY:
PUSH 00H
PUSH 01H
PUSH 02H
MOV R3,#4
BB:
MOV R4,#200
AA:
JB P1.0,NUT21
JNB P1.0,$
MOV 50H,#'1'
MOV R6,#'A'
SETB TI
LJMP SANGDUOI
NUT21:
JB P1.1,NUT31
JNB P1.1,$
MOV 50H,#'2'
MOV R6,#'B'
SETB TI
LJMP SANGDAN
NUT31:
JB P1.2,NUT41
JNB P1.2,$
MOV 50H,#'3'
MOV R6,#'C'
SETB TI
LJMP DUOIDON
NUT41:
JB P1.3,CHO
JNB P1.3,$
MOV 50H,#'4'
MOV R6,#'D'
SETB TI
LJMP STOP
CHO:
MOV R5,00H
DJNZ R5,$
DJNZ R4,AA
DJNZ R3,BB
POP 02H
POP 01H
POP 00H
RET
;****************************************
TIMER:
MOV SCON,#50H
MOV TMOD,#20H
MOV TH1,#-3
SETB EA
SETB ES
CLR TI
SETB TR1
RET
NGAT:
JNB RI,TRUYEN
MOV A,SBUF
MOV 50H,A
CLR RI
SJMP THOATNGAT
TRUYEN:
MOV A,R6
CLR TI
MOV SBUF,A
JNB TI,$
CLR TI
THOATNGAT:
RETI
END
$MOD51
ORG 00H
JMP MAIN
ORG 23H
JMP NGAT
ORG 30H
MAIN:
LCALL TIMER
NUT:
JB P1.0,TIEP1
MOV R6,#'A'
SETB TI
LCALL SANGDUOI
TIEP1:
JB P1.1,TIEP2
MOV R6,#'B'
SETB TI
LCALL SANGDAN
TIEP2:
JB P1.2,TIEP3
MOV R6,#'C'
SETB TI
LCALL DUOIDON
TIEP3:
JB P1.3,NUT
MOV R6,#'D'
SETB TI
LCALL STOP
SJMP NUT
;************************************************* *******
LOOP:
MOV R7,50H
CJNE R7,#'1',KT1
LCALL SANGDUOI
KT1:
CJNE R7,#'2',KT2
LCALL SANGDAN
KT2:
CJNE R7,#'3',KT3
LCALL DUOIDON
KT3:
CJNE R7,#'4',LOOP
LCALL STOP; TAT LED
;************************************************* *************
SANGDUOI:
CLR P1.4
SETB P1.5
SETB P1.6
SETB P1.7
MOV R0,#00H
MOV DPTR,#DATADISH1
LAP1:
MOV A,R0
MOVC A,@A+DPTR
MOV P0,A
LCALL DELAY
INC R0
MOV R7,50H
CJNE R7,#'2',LOP1
JMP SANGDAN
LOP1:
CJNE R7,#'3',LOP2
JMP DUOIDON
LOP2:
CJNE R7,#'4',LOP3
JMP STOP
LOP3:
CJNE R7,#36,LAP1
SJMP SANGDUOI
DATADISH1:
DB 0FEH,0FDH,0FBH,0F7H,0EFH,0DFH,0BFH,7FH
DB 7EH,7DH,7BH,77H,6FH,5FH,3FH
DB 3EH,3DH,3BH,37H,2FH,1FH
DB 1EH,1DH,1BH,17H,0FH
DB 0EH,0DH,0BH,07H
DB 06H,05H,03H
DB 02H,01H
DB 00H
;************************************************* ************
SANGDAN:
CLR P1.5
SETB P1.4
SETB P1.6
SETB P1.7
MOV R1,#00H
MOV DPTR,#DATADISH2
LAP2:
MOV A,R1
MOVC A,@A+DPTR
MOV P0,A
LCALL DELAY
INC R1
MOV R7,50H
CJNE R7,#'1',LOP1A
LCALL SANGDUOI
LOP1A:
CJNE R7,#'3',LOP2A
LCALL DUOIDON
LOP2A:
CJNE R7,#'4',LOP3A
LCALL STOP
LOP3A:
CJNE R7,#9,LAP2
SJMP SANGDAN
DATADISH2:
DB 0FFH,0FEH,0FCH,0F8H,0F0H,0E0H,0C0H,80H,00H
;************************************************* ************
DUOIDON:
CLR P1.6
SETB P1.5
SETB P1.4
SETB P1.7
MOV R2,#00H
MOV DPTR,#DATADISH3
LAP3:
MOV A,R2
MOVC A,@A+DPTR
MOV P0,A
LCALL DELAY
INC R2
MOV R7,50H
CJNE R7,#'1',LOP1B
JMP SANGDUOI
LOP1B:
CJNE R7,#'2',LOP2B
JMP SANGDAN
LOP2B:
CJNE R7,#'4',LOP3B
JMP STOP
LOP3B:
CJNE R7,#36,LAP3
SJMP DUOIDON
DATADISH3:
DB 0FEH,0FDH,0FBH,0F7H,0EFH,0DFH,0BFH,7FH
DB 7EH,7DH,7BH,77H,6FH,5FH,3FH
DB 3EH,3DH,3BH,37H,2FH,1FH
DB 1EH,1DH,1BH,17H,0FH
DB 0EH,0DH,0BH,07H
DB 06H,05H,03H
DB 02H,01H
DB 00H
;************************************************* ************
STOP:
CLR P1.7
SETB P1.5
SETB P1.6
SETB P1.4
MOV R7,50H
CJNE R7,#'1',LOP1C
JMP SANGDUOI
LOP1C:
CJNE R7,#'2',LOP2C
JMP SANGDAN
LOP2C:
CJNE R7,#'3',LOP3C
JMP DUOIDON
LOP3C:
MOV P0,#0FFH
LCALL DELAY
SJMP STOP
;************************************************* ************
DELAY:
PUSH 00H
PUSH 01H
PUSH 02H
MOV R3,#4
BB:
MOV R4,#200
AA:
JB P1.0,NUT21
JNB P1.0,$
MOV 50H,#'1'
MOV R6,#'A'
SETB TI
LJMP SANGDUOI
NUT21:
JB P1.1,NUT31
JNB P1.1,$
MOV 50H,#'2'
MOV R6,#'B'
SETB TI
LJMP SANGDAN
NUT31:
JB P1.2,NUT41
JNB P1.2,$
MOV 50H,#'3'
MOV R6,#'C'
SETB TI
LJMP DUOIDON
NUT41:
JB P1.3,CHO
JNB P1.3,$
MOV 50H,#'4'
MOV R6,#'D'
SETB TI
LJMP STOP
CHO:
MOV R5,00H
DJNZ R5,$
DJNZ R4,AA
DJNZ R3,BB
POP 02H
POP 01H
POP 00H
RET
;****************************************
TIMER:
MOV SCON,#50H
MOV TMOD,#20H
MOV TH1,#-3
SETB EA
SETB ES
CLR TI
SETB TR1
RET
NGAT:
JNB RI,TRUYEN
MOV A,SBUF
MOV 50H,A
CLR RI
SJMP THOATNGAT
TRUYEN:
MOV A,R6
CLR TI
MOV SBUF,A
JNB TI,$
CLR TI
THOATNGAT:
RETI
END
Comment