下边是用汇编编写的一个多功能控制的流水灯,就是用8个开关去控制灯不同的流水方式,(灯挂在P2口,用P1口去读开关的状态,在没有别的开关按下去,想让灯一直在显示前一次开关按下对应的状态)
但是在调试时候显示,JB FLAG.5,NO5
JB FLAG.6,NO6
JB FLAG.7,NO7
后面显示错误,TARFE OUT OF RANGE ,我看书好象它的跳转的地址只有-128---+127,就是我的程序跳出了我们的范围,可以怎么改?
请各位大哥大姐指教,3Q!!!
FLAG EQU 20H
ORG 00H
LJMP MAIN
ORG 30H
MAIN:
MOV SP,#40H
LCALL INIT_IO
SCAN0:
JNB P1.0,KS0
SCAN1:
JNB P1.1,KS1
SCAN2:
JNB P1.2,KS2
SCAN3:
JNB P1.3,KS3
SCAN4:
JNB P1.4,KS4
SCAN5:
JNB P1.5,KS5
SCAN6:
JNB P1.6,KS6
SCAN7:
JNB P1.7,KS7
JB FLAG.0,NO0
JB FLAG.1,NO1
JB FLAG.2,NO2
JB FLAG.3,NO3
JB FLAG.4,NO4
JB FLAG.5,NO5
JB FLAG.6,NO6
JB FLAG.7,NO7
JMP SCAN0
KS0:
LCALL TM12S
JNB P1.0,NO0
LJMP SCAN1
KS1:
LCALL TM12S
JNB P1.1,NO1
LJMP SCAN2
KS2:
LCALL TM12S
JNB P1.2,NO2
LJMP SCAN3
KS3:
LCALL TM12S
JNB P1.3,NO3
LJMP SCAN4
KS4:
LCALL TM12S
JNB P1.4,NO4
LJMP SCAN5
KS5:
LCALL TM12S
JNB P1.5,NO5
LJMP SCAN6
KS6:
LCALL TM12S
JNB P1.6,NO6
LJMP SCAN7
KS7:
LCALL TM12S
JNB P1.7,NO7
RET
NO0:
MOV FLAG,#01H
MOV P2,#0FFH ;P2=1111 1111
LCALL DELAY
MOV P2,#00H ;P2=0000 0000
LCALL DELAY
SETB P1.0
LJMP SCAN1
NO1:
MOV FLAG,#02H
MOV P2,#0F0H ;P2=1111 0000
LCALL DELAY
MOV P2,#0FH ;P2=0000 1111
LCALL DELAY
SETB P1.1
LJMP SCAN2
NO2:
MOV FLAG,#04H
MOV P2,#055H ;P2=0101 0101
LCALL DELAY
MOV P2,#0AAH ;P2=1010 1010
LCALL DELAY
SETB P1.2
LJMP SCAN3
NO3:
MOV FLAG,#08H ;zuo yi
MOV R0,#08H
MOV A,#01H
LOOP3:
MOV P2,A
RL A
LCALL DELAY
DJNZ R0,LOOP3
SETB P1.3
LJMP SCAN4
NO4:
MOV FLAG,#10H ; you yi
MOV R0,#08H
MOV A,#80H
LOOP4:
MOV P2,A
RR A
LCALL DELAY
DJNZ R0,LOOP4
SETB P1.4
LJMP SCAN5
NO5:
MOV FLAG,#20H
MOV R1,#10H ;zuo mie
MOV R0,#08H
MOV A,#0FEH
LOOP5:
MOV P2,A
RL A
LCALL DELAY
DJNZ R0,LOOP5
SETB P1.5
LJMP SCAN6
NO6: ;you mie
MOV FLAG,#40H
MOV R0,#06H
MOV R0,#08H
MOV A,#7FH
LOOP6:
MOV P2,A
RR A
LCALL DELAY
DJNZ R0,LOOP6
SETB P1.6
LJMP SCAN7
NO7: ;zuo yi
MOV FLAG,#80H
MOV R0,#04H
MOV A,#01H
LOOP7:
MOV P2,A
RL A
RL A
LCALL DELAY
DJNZ R0,LOOP7
MOV R0,#04H
MOV A,#80H
LOOP8:
MOV P2,A
RR A
RR A
LCALL DELAY
DJNZ R0,LOOP8
SETB P1.7
LJMP SCAN0
TM12S:
MOV R3,#18H
TM:
MOV R4,#0FFH
TM6:
DJNZ R4,TM6
DJNZ R3,TM
RET
INIT_IO:
MOV P2,#00H ;CLR P2
RET
DELAY:
MOV R7,#04H
D1:
MOV R6,#0FFH
MOV R5,#0FFH
D2:
DJNZ R5,$
DJNZ R6,D2
DJNZ R7,D1
RET
END |