單片機(jī)交通燈實(shí)驗(yàn)匯編語(yǔ)言程序
SUL11:
CJNE R3,#0,DD1
AJMP SU1A
SU0B: MOV P2,#00H
CLR P0.4
MOV A,R4
MOV R1,A
MOV B,#5
DIV AB
MOV B,#3
MUL AB
MOV R0,A
SETB P0.6
SETB P2.1
SETB P2.6
AJMP LKEY
SU1B:DEC R0
DEC R1
SUL44: CJNE R0,#5,SUL45
SETB P2.3
SUL45: CJNE R0,#4,SUL46
SETB P2.3
SUL46: CJNE R0,#3,SUL40
SETB P2.3
SUL40: CJNE R0,#2,SUL41
SETB P2.3
SUL41: CJNE R0,#1,SUL42
SETB P2.3
SUL42: CJNE R0,#0,SUL43
CLR P0.6
CLR P2.1
SETB P0.4
SETB P2.0
MOV A,R1
MOV R0,A
SUL43: CJNE R1,#0,LKEY
AJMP SU0
LKEY:;CLR P2.3
JB P3.5,LKEY1
LCALL DELAY
MOV R2,#45
LKEY1: JB P3.2,LKEY2
LCALL DELAY
MOV R2,#60
LKEY2: JB P3.3,LKEY3
LCALL DELAY
MOV A,R2
ADD A,#5
MOV R2,A
CJNE R2,#95,LDD
MOV R2,#95
LKEY3: JB P3.4,LDD
LCALL DELAY
MOV A,R2
SUBB A,#5
MOV R2,A
CJNE R2,#0,LDD
MOV R2,#0
AJMP LDD
LDD:MOV R3,#50;數(shù)碼1
LDD1: MOV P1,#00H
MOV A,R0
MOV B,#10
DIV AB
MOV DPTR,#TAB
MOVC A,@A+DPTR
MOV P1,A
SETB P0.0
LCALL DELAY1
CLR P0.0
MOV A,B
MOV DPTR,#TAB
MOVC A,@A+DPTR
MOV P1,A
SETB P0.1
LCALL DELAY1
CLR P0.1;數(shù)碼2
MOV A,R1
MOV B,#10
DIV AB
MOV DPTR,#TAB
MOVC A,@A+DPTR
MOV P1,A
SETB P0.2
LCALL DELAY1
CLR P0.2
MOV A,B
MOV DPTR,#TAB
MOVC A,@A+DPTR
MOV P1,A
SETB P0.3
LCALL DELAY1
CLR P0.3;數(shù)碼3
MOV A,R2
MOV B,#10
DIV AB
MOV DPTR,#TAB
MOVC A,@A+DPTR
MOV P1,A
SETB P3.6
LCALL DELAY1
CLR P3.6
MOV A,B
MOV DPTR,#TAB
MOVC A,@A+DPTR
MOV P1,A
SETB P3.7
LCALL DELAY1
CLR P3.7
DEC R3
CJNE R3,#25,SUL10
CLR P2.3
SUL10:
CJNE R3,#0,LDD1
AJMP SU1B
TAB:
DB0C0H;"0"
DB0F9H;"1"
DB0A4H;"2"
DB0B0H;"3"
DB 99H;"4"
DB 92H;"5"
DB 82H;"6"
DB0F8H;"7"
DB 80H;"8"
DB 90H;"9"
DELAY:
MOV R5,#100
L3:MOV R6,#100
L1:MOV R7,#6
L2:DJNZ R7,L2
DJNZ R6,L1
DJNZ R5,L3
RET
DELAY1:
MOV R7,#30
D1:MOV R6,#10
D2:DJNZ R6,D2
DJNZ R7,D1
RET
END
評(píng)論