原用按钮开关控制跑马灯的速度,改成VR控制跑马灯的速度,汇编语言如何修改呢?
ORG 00H ;程序起始地址00H
MOV R0,#01111111B
MOV R4,#50 ;LED移动速度初值
;=======================================================
CHKPB: ORL P1,#11111111B ;设定埠1 接脚高电位
MOV A,P1 ;读取埠脚状态
CPL A ;取1的补码
JB ACC.2,UP ;按PB3减速
JB ACC.3,DOWN ;按PB4加速
SJMP PELE
;=======================================================
UP: MOV A,R4 ;减速
ADD A,#6 ;R4愈大,速度愈慢
JZ PELE ;R4最小值250
INC R4
INC R4
SJMP PELE
;=======================================================
DOWN: MOV A,R4 ;加速
ADD A,#236 ;R4愈小,速度愈快
JZ PELE ;R4最小值20
DEC R4
DEC R4
SJMP PELE
;=======================================================
PELE: MOV R0,#0 ;取码指标初值
MOV R1,#7 ;资料码总数
NEXT: MOV DPTR,#TABLE ;
MOV A,R0 ;将数据码取出
MOVC A,@A+DPTR ;
;=======================================================
接上述
MOV R2,#56 ;LED右移次数
RAGAIN: MOV P0,A ;由埠1,埠2,
INC A,R1
MOV P1,A
INC A,R1
MOV P2,A
INC A,R1
MOV P3,A
ACALL DELAY01 ;
RR A ;右移一次
DJNZ R2,RAGAIN
;=======================================================
MOV R2,#56 ;LED左移次数
LAGAIN: MOV P0,A ;由埠1,埠2,
INC A,R1
MOV P1,A
INC A,R1
MOV P2,A
INC A,R1
MOV P3,A
ACALL SPEED
RL A ;左移一次
DJNZ R2,LAGAIN
;------------------------------------------------------
INC R0 ;取码指标加1
DJNZ R1,NEXT ;取下一码
;=======================================================
MOV R2,#20 ;LED闪烁10次
MOV A,#0
FLASH: MOV P0,A ;由埠1,埠2,
INC A,R1
MOV P1,A
INC A,R1
MOV P2,A
INC A,R1
MOV P3,A
ACALL SPEED
CPL A
DJNZ R2,FLASH
SJMP PELE
SJMP CHKPB
;=======================================================
SPEED: MOV A,R4 ;决定LED移动速度
MOV R5,A ;的子程序
T5: ACALL DELAY
DJNZ R5,T5
RET
;------------------------------
DELAY: MOV R6,#5
T6: MOV R7,#98
DJNZ R7,$
DJNZ R6,T6
RET
;=======================================================
TABLE: ;数据码储存起始地址
DB 0FEH,0FCH,0F8H,0F0H,0E0H,0C0H, 80H, 00H
DB 01H, 03H, 07H, 0FH, 1FH, 3FH, 7FH,0FFH
DB 0FFH, 00H,0FFH, 00H,0FFH, 00H,0FFH, 00H
DB 0FEH,0FCH,0F9H,0F3H,0E7H,0CFH, 9FH, 3FH
DB 7EH,0FEH,0FCH,0F9H,0F3H,0E7H,0CFH, 9FH
DB 3FH, 7EH,0FEH,0FCH,0F9H,0F3H,0E7H,0CFH
DB 9FH, 3FH,0FFH,0FEH,0FDH,0FBH,0F7H,0EFH
DB 0DFH,0BFH, 7FH, 7EH, 7DH, 7BH, 77H, 6FH
DB 5FH, 3FH, 3EH, 3DH, 3BH, 37H, 2FH, 1FH
DB 1EH, 1DH, 1BH, 17H, 0FH, 0EH, 0DH, 0BH
DB 07H, 06H, 05H, 03H, 01H, 00H, 80H,0C0H
DB 0E0H,0F8H,0FCH,0FEH,0FFH, 55H,0AAH, 55H
DB 0AAH, 55H,0AAH, 55H,0AAH, 55H,0AAH, 55H
DB 0AAH, 33H, 99H, 66H, 33H, 99H, 66H, 33H
DB 99H, 66H, 33H, 99H, 66H, 33H, 99H, 66H
DB 33H, 99H, 66H, 33H, 99H, 66H, 33H, 99H
DB 66H, 33H, 99H, 66H, 7EH,0BDH,0DBH,0E7H
DB 0DBH,0BDH, 7EH,0BDH,0DBH,0E7H,0DBH,0BDH
DB 7EH,0BDH,0DBH,0E7H,0DBH,0BDH, 7EH,0BDH
DB 0DBH,0E7H,0DBH,0BDH, 7EH,0FFH,0FEH,0FDH
DB 0FBH,0F7H,0EFH,0DFH,0BFH, 7FH, 7EH, 7DH
DB 7BH, 77H, 6FH, 5FH, 3FH,0BEH,0BDH,0BBH
DB 0B7H,0AFH, 9FH, 5FH,0DEH,0DDH,0DBH,0D7H
DB 0CFH,0AFH, 6FH,0EEH,0EDH,0EBH,0E7H,0D7H
DB 0B7H, 77H,0F6H,0F5H,0F3H,0EBH,0DBH,0BBH
DB 7BH,0FAH,0F9H,0F5H,0EDH,0DDH,0BDH, 7DH
DB 0FCH,0FAH,0F6H,0EEH,0DEH,0BEH, 7EH,0FDH
DB 0FBH,0F7H,0EFH,0DFH,0BFH, 7FH,0FFH,0CCH
;======================================================
END |