多花样LED流动灯控制器(使用P1口和P2口连接16个LED发光二极管,制作出9个花样数据表,使用查表的方式编程控制LED灯)。主要设计内容如下:
(1)用单片机I/O设计驱动16或32个LED灯;
(2)用步进按键K1,改变流动灯显示速度(速度有10级,每按键1次步进加1);
(3)用步进按键K2,改变流动灯显示花样(花样有10个,每按键1次步进加1);
(4)用按键K3,设置流动灯从花样0~9按顺序全部显示,反复循环。
程序模块如下:1.定时器T010ms扫描是否有键输入
KEYIN: MOV TL0,#0F0H
MOV TH0,#0D8H
JNB P3.4, JY0
JNB P3.5, JY1
JNB P3.7, JY2
ACALL XIANSHI
AJMP EXT
JY0: JB P3.4,ZS0
ACALL XIANSHI
AJMP EXT
ZS0: INC 40H
MOV R1,40H
CLR F0
CJNE R1,#10,CL0
MOV 40H,#00
AJMP EXT
JY1: JB P3.5,ZS1
ACALL XIANSHI
AJMP EXT
ZS1: DEC R2
SETB F0
CJNE R2,#00H,CL1
MOV 41H,#09
ACALL XIANSHI
AJMP EXT
JY2: JB P3.7,ZS2
ACALL XIANSHI
AJMP EXT
ZS2: INC 42H
SETB F0
MOV R3,42H
CJNE R3,#02,CL2
MOV 42H,#00
ACALL XIANSHI
AJMP EXT
CL0: ACALL XIANSHI
AJMP EXT
CL1: ACALL XIANSHI
AJMP EXT
CL2: ACALL XIANSHI
AJMP EXT
EXT: RETI
2.数码管显示模块(显示key1(R2),key2(R1),key3当前状态)
XIANSHI:
MOV 41H,R2
MOV 30H,#04
HL1: MOV R0,#40H
MOV P2,#7FH
HL: MOV A,@R0
MOV DPTR,#TAB10
MOVC A,@A+DPTR
MOV SBUF,A
JNB TI,$
CLR TI
MOV A,P2
RL A
MOV P2,A
INC R0
DJNZ 30H,HL
RET
3.定时器T1进行20ms延时处理,一个等级对应一个标志位(R4控制次数)
INP1: MOV TL0, #0E0H
MOV TH1, #0B1H ;
CJNE R2,#09,JM0
CJNE R4,#09,JN0
SETB 21H.1
AJMP TM0
JN0: DEC R4
AJMP TM0
JM0: CJNE R2,#08,JM1
CJNE R4,#08,JN1
SETB 21H.0
AJMP TM0
JN1: DEC R4
AJMP TM0
JM1: CJNE R2,#07,JM2
CJNE R4,#07,JN2
SETB 20H.7
AJMP TM0
JN2: DEC R4
AJMP TM0
JM2: CJNE R2,#06,JM3
CJNE R4,#06,JN3
SETB 20H.6
AJMP TM0
JN3: DEC R4
AJMP TM0
JM3: CJNE R2,#05,JM4
CJNE R4,#05,JN4
SETB 20H.5
AJMP TM0
JN4: DEC R4
AJMP TM0
JM4: CJNE R2,#04,JM5
CJNE R2,#04,JN5
SETB 20H.4
AJMP TM0
JN5: DEC R4
AJMP TM0
JM5: CJNE R2,#03,JM6
CJNE R4,#03,JN6
SETB 20H.3
AJMP TM0
JN6: DEC R4
AJMP TM0
JM6: CJNE R2,#02,JM7
CJNE R4,#02,JN7
SETB 20H.2
AJMP TM0
JN7: DEC R4
AJMP TM0
JM7: CJNE R2,#01,JM8
CJNE R4,#01,JN8
SETB 20H.1
AJMP TM0
JN8: DEC R4
AJMP TM0
JM8: CJNE R2,#00,TM0
CJNE R4,#00,TM0
MOV R4,#09
SETB 20H.0
MOV R2,#10
TM0: RETI
4. 延时模块,采用查询标志位的方式
DEL: CJNE R2,#09,LP1
JNB 21H.1, $
CLR 21H.1
AJMP CQ
LP1: CJNE R2,#08,LP2
JNB 21H.0, $
CLR 21H.0
AJMP CQ
LP2: CJNE R2,#07,LP3
JNB 20H.7,$
CLR 20H.7
AJMP CQ
LP3: CJNE R2,#06,LP4
JNB 20H.6,$
CLR 20H.6
AJMP CQ
LP4: CJNE R2,#05,LP5
JNB 20H.5,$
CLR 21H.5
AJMP CQ
LP5: CJNE R2,#04,LP6
JNB 20H.4,$
CLR 21H.4
AJMP CQ
LP6: CJNE R2,#03,LP7
JNB 20H.3,$
CLR 21H.3
AJMP CQ
LP7: CJNE R2,#02,LP8
JNB 20H.2,$
CLR 21H.2
AJMP CQ
LP8: CJNE R2,#01,LP9
JNB 20H.1,LP3
CLR 21H.1
AJMP CQ
LP9: CJNE R2,#00,CQ
JNB 20H.0,$
CLR 21H.0
CQ: RET
5.主程序点亮LED,采用查表方式处理,程序如下
ORG 0000H
AJMP MAIN
ORG 000BH
AJMP KEYIN
ORG 001B
AJMP INP1
MAIN: MOV R2,#09
MOV R4,#09
MOV 40H,#00
MOV 41H,#00
MOV 42H,#00
MOV 43H,#00
MOV TMOD,#01H ; 计时器T0,工作方式1
MOV TL0,#0F0H ; 初值
MOV TH0,#0D8H
MOV TL1,#0E0H
MOV THL,#0B1H
MOV SCON,#00H
MOV 20H,#00
CLR 21H.0
CLR 21H.0
SETB F0
SETB TR0
SETB TR1 ;开计时器
SETB EA ;开中断
SETB ET0
SETB ET1
EXT1: CJNE R1,#00,LP0
ETT0: MOV R7,#00
MOV R6,#08
HI0: MOV A,R6
MOV P1,#0FFH
MOV DPTR,#TAB1
MOVC A,@A+DPTR
MOV P0,A
ACALL DEL
INC R6
DJNZ R7,HI0
MOV R7,#08
MOV R6,#00
HI1: MOV P0,#0FFH
MOV A,R6
MOVC A,@A+DPTR
MOV P1,A
ACALL DEL
INC R6
DJNZ R7,HI1
JB F0, ETT0
SETB F0
AJMP EXT1
LP0: CJNE R1,#01,LP1
ETT: MOV R6,#00
MOV R7,#08
HL2: MOV A,R6
MOV P1,#0FFH
MOV DPTR,#TAB2
MOVC A,@A+DPTR
MOV P0,A
ACALL DEL
INC R6
DJNZ R7,HL2
MOV R7,#08
MOV R6,#00
HL3: MOV P0,#0FFH
MOV A,R6
MOVC A,@A+DPTR
MOV P1,A
ACALL DEL
INC R6
DJNZ R7,HL3
JB F0,ETT
SETB F0
AJMP EXT1
LP1: CJNE R1,#02,LP2
ETT2: MOV R6,#00
MOV R7,#08
HL6: MOV A,R6
MOV P1,#0FFH
MOV DPTR,#TAB3
MOVC A,@A+DPTR
MOV P0,A
ACALL DEL
INC R6
DJNZ R7,HL6
MOV R7,#08
MOV R6,#00
HL7: MOV P0,#0FFH
MOV A,R6
MOVC A,@A+DPTR
MOV P1,A
ACALL DEL
INC R6
DJNZ R7,HL7
JB F0 ,ETT2
SETB F0
AJMP EXT1
LP2: CJNE R1,#03,PP1
ET2: MOV R6,#00
MOV R7,#08
HL8: MOV A,R6
MOV P1,#0FFH
MOV DPTR,#TAB4
MOVC A,@A+DPTR
MOV P0,A
INC R6
ACALL DEL
DJNZ R7,HL8
MOV R7,#08
MOV R6,#00
HL9: MOV P0,#0FFH
MOV A,R6
MOVC A,@A+DPTR
MOV P1,A
ACALL DEL
INC R6
DJNZ R7,HL9
JB F0,ET2
SETB F0
AJMP EXT1
PP1: CJNE R1,#04,LPO3
ET3: MOV R6,#00
MOV R7,#08
HL10: MOV A,R6
MOV P1,#0FFH
MOV DPTR,#TAB5
MOVC A,@A+DPTR
MOV P0,A
ACALL DEL
INC R6
DJNZ R7,HL10
MOV R7,#08
MOV R6,#00
HL11: MOV P0,#0FFH
MOV A,R6
MOVC A,@A+DPTR
MOV P1,A
ACALL DEL
INC R6
DJNZ R7,HL11
JB F0, ET3
SETB F0
AJMP EXT1
LPO3: CJNE R1,#05,LPO2
ET4: MOV R6,#00
MOV R7,#08
HL12: MOV A,R6
MOV P1,#0FFH
MOV DPTR,#TAB6
MOVC A,@A+DPTR
MOV P0,A
ACALL DEL
INC R6
DJNZ R7,HL12
MOV R7,#08
MOV R6,#00
HL13: MOV P0,#0FFH
MOV A,R6
MOVC A,@A+DPTR
MOV P1,A
ACALL DEL
INC R6
DJNZ R7,HL13
JB F0, ET4
SETB F0
AJMP EXT1
LPO2: CJNE R1,#06,LPO1
ET5: MOV R6,#00
MOV R7,#08
HL14: MOV A,R6
MOV P1,#0FFH
MOV DPTR,#TAB6
MOVC A,@A+DPTR
MOV P0,A
ACALL DEL
INC R6
DJNZ R7,HL12
MOV R7,#08
MOV R6,#00
HL15: MOV P0,#0FFH
MOV A,R6
MOVC A,@A+DPTR
MOV P1,A
ACALL DEL
INC R6
DJNZ R7,HL13
JB F0, ET5
SETB F0
AJMP EXT1
LPO1: CJNE R1,#07,LPO0
ET6: MOV R6,#00
MOV R7,#08
HL16: MOV A,R6
MOV P1,#0FFH
MOV DPTR,#TAB7
MOVC A,@A+DPTR
MOV P0,A
ACALL DEL
INC R6
DJNZ R7,HL14
MOV R7,#08
MOV R6,#00
HL17: MOV P0,#0FFH
MOV A,R6
MOVC A,@A+DPTR
MOV P1,A
ACALL DEL
INC R6
DJNZ R7,HL15
JB F0, ET6
SETB F0
AJMP EXT1
LPO0: CJNE R1,#08,PL0
ET7: MOV R6,#00
MOV R7,#08
HL18: MOV A,R6
MOV P1,#0FFH
MOV DPTR,#TAB9
MOVC A,@A+DPTR
MOV P0,A
ACALL DEL
INC R6
DJNZ R7,HL18
MOV R7,#08
MOV R6,#00
HL19: MOV P0,#0FFH
MOV A,R6
MOVC A,@A+DPTR
MOV P1,A
ACALL DEL
INC R6
DJNZ R7,HL19
JB F0, ET7
SETB F0
AJMP EXT1
PL0: CJNE R1,#09,PL1
ET8: MOV R6,#00
MOV R7,#08
HL20: MOV A,R6
MOV P1,#0FFH
MOV DPTR,#TAB7
MOVC A,@A+DPTR
MOV P0,A
ACALL DEL
INC R6
DJNZ R7,HL20
MOV R7,#08
MOV R6,#00
HL21: MOV P0,#0FFH
MOV A,R6
MOVC A,@A+DPTR
MOV P1,A
ACALL DEL
INC R6
DJNZ R7,HL21
JB F0, ET8
SETB F0
AJMP EXT1
PL1: CJNE R3,#01,LPO4
LPO4: AJMP EXT1
LLP1: MOV R5,#09
MOV R7,#08
MOV R6,#00
MOV P1,#0FFH
LPP1: MOV A,R6
MOV DPTR,#TAB1
MOVC A,@A+DPTR
MOV P0,A
ACALL DEL
INC R6
DJNZ R7,LPP1
MOV R7,#08
MOV R6,#00
MOV P0,#0FFH
LPP2: MOV A,R6
MOV DPTR,#TAB1
MOVC A,@A+DPTR
MOV P1,A
ACALL DEL
INC R6
DJNZ R7,LPP2
MOV R6,#00
MOV R7,#08
MOV P1,#0FFH
LPP3: MOV A,R6
MOV DPTR,#TAB2
MOVC A,@A+DPTR
MOV P0,A
ACALL DEL
INC R6
DJNZ R7,LPP3
MOV R7,#08
MOV R6,#00
MOV P0,#0FFH
LPP4: MOV A,R6
MOV DPTR,#TAB2
MOVC A,@A+DPTR
MOV P1,A
ACALL DEL
INC R6
DJNZ R7,LPP4
MOV R6,#00
MOV R7,#08
MOV P1,#0FFH
LPP5: MOV A,R6
MOV DPTR,#TAB3
MOVC A,@A+DPTR
MOV P0,A
ACALL DEL
INC R6
DJNZ R7,LPP5
MOV R7,#08
MOV R6,#00
MOV P0,#0FFH
LPP6: MOV A,R6
MOV DPTR,#TAB3
MOVC A,@A+DPTR
MOV P1,A
ACALL DEL
INC R6
DJNZ R7,LPP6
MOV R6,#00
MOV R7,#08
MOV P1,#0FFH
LPP7: MOV A,R6
MOV DPTR,#TAB4
MOVC A,@A+DPTR
MOV P0,A
ACALL DEL
INC R6
DJNZ R7,LPP7
MOV R7,#08
MOV R6,#00
MOV P0,#0FFH
LPP8: MOV A,R6
MOV DPTR,#TAB4
MOVC A,@A+DPTR
MOV P1,A
ACALL DEL
INC R6
DJNZ R7,LPP8
MOV R6,#00
MOV R7,#08
MOV P1,#0FFH
LPP9: MOV A,R6
MOV DPTR,#TAB5
MOVC A,@A+DPTR
MOV P0,A
ACALL DEL
INC R6
DJNZ R7,LPP9
MOV R7,#08
MOV R6,#00
MOV P0,#0FFH
LPP10: MOV A,R6
MOV DPTR,#TAB5
MOVC A,@A+DPTR
MOV P1,A
ACALL DEL
INC R6
DJNZ R7,LPP10
MOV R6,#00
MOV R7,#08
MOV P1,#0FFH
LPP11: MOV A,R6
MOV DPTR,#TAB6
MOVC A,@A+DPTR
MOV P0,A
ACALL DEL
INC R6
DJNZ R7,LPP11
MOV R7,#08
MOV R6,#00
MOV P0,#0FFH
LPP12: MOV A,R6
MOV DPTR,#TAB6
MOVC A,@A+DPTR
MOV P1,A
ACALL DEL
INC R6
DJNZ R7,LPP12
MOV R6,#00
MOV R7,#08
MOV P1,#0FFH
LPP13: MOV A,R6
MOV DPTR,#TAB7
MOVC A,@A+DPTR
MOV P0,A
ACALL DEL
INC R6
DJNZ R7,LPP13
MOV R7,#08
MOV R6,#00
MOV P0,#0FFH
LPP14: MOV A,R6
MOV DPTR,#TAB7
MOVC A,@A+DPTR
MOV P1,A
ACALL DEL
INC R6
DJNZ R7,LPP14
MOV R6,#00
MOV R7,#08
MOV P1,#0FFH
LPP15: MOV A,R6
MOV DPTR,#TAB8
MOVC A,@A+DPTR
MOV P0,A
ACALL DEL
INC R6
DJNZ R7,LPP15
MOV R7,#08
MOV R6,#00
MOV P0,#0FFH
LPP16: MOV A,R6
MOV DPTR,#TAB8
MOVC A,@A+DPTR
MOV P1,A
ACALL DEL
INC R6
DJNZ R7,LPP16
MOV R6,#00
MOV R7,#08
MOV P1,#0FFH
LPP17: MOV A,R6
MOV DPTR,#TAB9
MOVC A,@A+DPTR
MOV P0,A
ACALL DEL
INC R6
DJNZ R7,LPP17
MOV R7,#08
MOV R6,#00
MOV P0,#0FFH
LPP18: MOV A,R6
MOV DPTR,#TAB9
MOVC A,@A+DPTR
MOV P1,A
ACALL DEL
INC R6
DJNZ R7,LPP18
DJNZ R5,OPP
OPP: AJMP LLP1
LPPO4: AJMP PP1
TAB1: DB 18H,24H,42H,81H,18H,24H,42H,81H
TAB2: DB 10H,10H,10H,00H,00H,00H,00H,00H
TAB3: DB 10H,10H,10H,01H,00H,00H,00H,00H
TAB4: DB 08H,10H,10H,00H,08H,00H,00H,00H
TAB5: DB 06H,10H,10H,00H,00H,00H,00H,00H
TAB6: DB 04H,10H,10H,00H,00H,00H,00H,00H
TAB7: DB 02H,10H,10H,00H,00H,00H,00H,00H
TAB8: DB 18H,24H,42H,81H,18H,24H,42H,81H
TAB9: DB 18H,24H,42H,81H,18H,24H,42H,81H
TAB10: DB 0FCH,60H,0DAH,0F2H,66H,0B6H,0BEH,0E0H,0FEH,0F6H
END
keil编译器给我的结果反馈是我的中断乱了,求大佬指点,该咋改程序
|