早教吧 育儿知识 作业答案 考试题库 百科 知识分享

闪烁变换的发光管控制器急求使用8位LED静态串行显示,8位查询式键盘,两组8位LED.(1)开机上电初使一只发光二极管亮,每隔2秒左移(即处于循环移位类型),且数码管显示“S.---LELT”(

题目详情
闪烁变换的发光管控制器急求
使用8位LED静态串行显示,8位查询式键盘,两组8位LED.
(1)开机上电初使一只发光二极管亮,每隔2秒左移(即处于循环移位类型),且数码管显示“S.---LELT”( 显示数码管最左位显示表示速度,高速(H)或慢速(S);右四位显示表示移动方向,循环左移
(LELT)、循环右移(righ)或循环交替(good)。
如为高速左移,即每隔1秒左移,且数码管显示“H.---LELT”。
(2)设计一个方向键,用于改变移动方向。如原发光二极管状态为每隔2秒左移,且数码管显示“S.---LELT”,则按动方向键后,发光二极管状态改变为每隔2秒右移,且数码管显示“S.---righ”; 如原发光二极管状态为每隔2秒右移,且数码管随之显示“S.---righ”,则按动方向键后,发光二极管状态改变为每隔2秒左移,且数码管随之显示“S.---LELT”。
(3)设计一个速度键,用于改变移动速度在高速到慢速间变换。如原发光二极管状态为每隔2秒左移,且数码管显示“S.---LELT”,则按动方向键后,每隔1秒左移,且数码管显示“H.---LELT”;再按一下速度键,又为原发光二极管状态为每隔2秒左移,且数码管显示“S.---LELT”。
(4)设计一个类型键,用于改变改变八个发光二极管亮的类型在两种类型间变换。类型1为循环移位;类型2为循环交替,即八个发光二极管亮的类型如从最左最右先亮,间隔一定时间后向中心移动然后再渐回归原位,并循环进行。
总之要设计按键,使得能控制移动方向、移动速度(高速或慢速)及类型,同时有相应的数码管显示。
请使用汇编语言,代码请发463291610@qq.com
▼优质解答
答案和解析
TICK EQU 10000
T100US EQU 156 ;
LEDBUF EQU 20H
C100US EQU 30H
DBUF EQU 40H
TEMP EQU 50H
COUNT EQU 60H
BUFSTORE EQU 61H
DIN BIT P3.4
CLK BIT P3.5
//////////定时常数////
ORG 0000H
LJMP MAIN
////转入主程序///
ORG 000BH
////中断入口/////////
LJMP T01NT
ORG 1000H
///以下键位判断///
K00: ACALL DELAY
MOV A, P1
CJNE A,#0FFH,K01
LJMP KEY
K01: CJNE A, #0FEH,K02
CPL 21H.0
LJMP KEY
K02: CJNE A, #0FDH,K03
CPL 21H.1
LJMP KEY
K03: CJNE A, #0FBH,KEY
CPL 21H.2
LJMP KEY
T01NT:
PUSH PSW ///进栈
MOV A,C100US+1
JNZ GOON //A不为00H跳转执行GOON
DEC C100US
GOON:
DEC C100US+1
MOV A,C100US
ORL A,C100US+1
JNZ EXIT //如果计数器不为零,则返回
MOV C100US,#4EH
MOV C100US+1,#20H ///定时2秒
KEY: MOV P1, #0FFH //P1接口置数
MOV A, P1
CJNE A, #0FFH, K00 ///转到键位判断
CLR C
MOV C, 21H.2 //模式判断
JNC MODE //判断模式,CY为零转入循环交替
MOV LEDBUF ,BUFSTORE
MOV C, 21H.1 //快慢判断
JNC OUTPHL //判断快慢,CY为零转入高速
CLR C
MOV C, 21H.0 //方向判断
JNC OUTPSR //判断方向,CY为零转入慢速右移
OUTPSL: //慢速左移
SETB 21H.0
SETB 21H.1
MOV A,LEDBUF
RL A
MOV LEDBUF,A
MOV BUFSTORE,LEDBUF
START1: ///慢速左移数码管显示
MOV DBUF+7,#07H
MOV DBUF+6,#06H
MOV DBUF+5,#05H
MOV DBUF+4,#04H
MOV DBUF+3,#03H
MOV DBUF+2,#02H
MOV DBUF+1,#01H
MOV DBUF,#00H
LJMP DISP
LJMP EXIT
EXIT:
POP PSW //出栈
RETI //中断返回
MODE: LJMP OUTPUT
OUTPSR: ///慢速右移
CLR 21H.0
SETB 21H.1
MOV A,LEDBUF
RR A
MOV LEDBUF,A
MOV BUFSTORE,LEDBUF
START2: //慢速右移数码管显示
MOV DBUF+7,#0FH
MOV DBUF+6,#0EH
MOV DBUF+5,#0DH
MOV DBUF+4,#0CH
MOV DBUF+3,#0BH
MOV DBUF+2,#0AH
MOV DBUF+1,#09H
MOV DBUF,#08H
LJMP DISP
LJMP EXIT
OUTPHL: //快速左移
MOV C100US,#27H
MOV C100US+1,#10H //定时1秒
MOV C,21H.0
JNC OUTPHR
SETB 21H.0
CLR 21H.1
MOV A,LEDBUF
RL A
MOV LEDBUF,A
MOV BUFSTORE,LEDBUF
START3: //快速左移数码管显示
MOV DBUF+7,#017H
MOV DBUF+6,#016H
MOV DBUF+5,#015H
MOV DBUF+4,#014H
MOV DBUF+3,#013H
MOV DBUF+2,#012H
MOV DBUF+1,#011H
MOV DBUF,#010H
LJMP DISP
SJMP EXIT
OUTPHR: //快速右移
CLR 21H.0
CLR 21H.1
MOV A,LEDBUF
RR A
MOV LEDBUF,A
MOV BUFSTORE,LEDBUF
START4: //快速右移数码管显示
MOV DBUF+7,#01FH
MOV DBUF+6,#01EH
MOV DBUF+5,#01DH
MOV DBUF+4,#01CH
MOV DBUF+3,#01BH
MOV DBUF+2,#01AH
MOV DBUF+1,#019H
MOV DBUF,#018H
LJMP DISP
OUTPUT:INC COUNT
MOV A,COUNT
CJNE A,#01H,PART2
MOV P2,#7EH
MOV LEDBUF,P2
LJMP START5
PART2:CJNE A,#02H,PART3
MOV P2,#0BDH
MOV LEDBUF,P2
LJMP START5

PART3:CJNE A,#03H,PART4
MOV P2,#0DBH
MOV LEDBUF,P2
LJMP START5
PART4:CJNE A,#04H,PART5
MOV P2,#0E7H
MOV LEDBUF,P2
LJMP START5
PART5:CJNE A,#05H,PART6
MOV P2,#0DBH
MOV LEDBUF,P2
LJMP START5
PART6:CJNE A,#06H,PART7
MOV P2,#0BDH
MOV LEDBUF,P2
LJMP START5
PART7:CJNE A,#07,PART8
MOV P2,#07EH
MOV LEDBUF,P2
LJMP START5
PART8:CJNE A,#07,PART9
MOV P2,#0FFH
MOV LEDBUF,P2
LJMP START5
PART9:CJNE A,#08H,PART10
MOV P2,#55H
MOV LEDBUF,P2
LJMP START5

PART10:CJNE A,#09H,PART11
MOV P2,#0AAH
MOV LEDBUF,P2
LJMP START5
PART11:CJNE A,#0AH,PART12
MOV P2,#0C3H
MOV LEDBUF,P2
LJMP START5
PART12:CJNE A,#0BH,PART13
MOV P2,#77H
MOV LEDBUF,P2
LJMP START5
PART13:CJNE A,#0CH,PART14
MOV P2,#0BBH
MOV LEDBUF,P2
LJMP START5
PART14:CJNE A,#0DH,PART15
MOV P2,#0DDH
MOV LEDBUF,P2
LJMP START5
PART15:CJNE A,#0DH,PART16
MOV P2,#0EEH
MOV LEDBUF,P2
LJMP START5
PART16:MOV COUNT,#01H
LJMP START5
/////花样结束/////////
START5:MOV DBUF+7,#027H //数码管显示
MOV DBUF+6,#026H
MOV DBUF+5,#025H
MOV DBUF+4,#024H
MOV DBUF+3,#023H
MOV DBUF+2,#022H
MOV DBUF+1,#021H
MOV DBUF,#020H
LJMP DISP
MAIN: //主程序
SETB 21H.0 //设初值
SETB 21H.1
SETB 21H.2
CLR COUNT
MOV TMOD,#02H //方式2,定时器
MOV TH0,#T100US
MOV TL0,#T100US
MOV IE,#10000010B
SETB TR0 //开始定时
MOV A,#0FEH
MOV LEDBUF,A
MOV BUFSTORE, A
MOV P2,A
MOV C100US, #27H
MOV C100US+1, #10H
LOOP:
MOV B,20H
MOV P2,B
LJMP LOOP
DISP: //静态数码管显示
MOV R0,#DBUF
MOV R1,#TEMP
MOV R2,#8
DP10:
MOV DPTR,#SEGTAB
MOV A,@R0
MOVC A,@A+DPTR
MOV @R1,A
INC R0
INC R1
DJNZ R2,DP10
MOV R0,#TEMP
MOV R1,#8
DP12:
MOV R2,#8
MOV A,@R0
DP13:
RLC A
MOV DIN,C
CLR CLK
SETB CLK
DJNZ R2,DP13
INC R0
DJNZ R1,DP12
LJMP EXIT
SEGTAB:
DB 6DH,80H,40H,40H,38H,79H,38H,31H
DB 6DH,80H,40H,40H,77H,30H,6FH,74H
DB 76H,80H,40H,40H,38H,79H,38H,31H
DB 76H,80H,40H,40H,77H,30H,6FH,74H
DB 40H,40H,6FH,3FH,3FH,5EH,40H,40H
RETI
DELAY:MOV R4, #02H
AA1: MOV R5, #0F8H
AA: NOP
NOP
DJNZ R5, AA
DJNZ R4, AA1
RET
END