基于單片機(jī)的LED彩燈控制器
4.2 源程序
ORG 0000H ;中斷入口程序;
LJMP START
ORG 0003H
RETI
ORG 000BH
RETI
ORG 0013H
RETI
ORG 001BH
RETI
CLEAR: RET; ; 初始化程序
;START:ACALL CLEAR ; 主 程 序
STAR1:MOV P3,#0FFH
JNB P3.2,FUN2
JNB P3.3,FUN3 ;關(guān)閉按紐
JNB P3.4,FUN0
JNB P3.5,FUN1
JNB F0,STAR1 ;曾經(jīng)有鍵按下F0置1
RET;
FUN0:LCALL DL10MS ;消除抖動(dòng)
JB P3.4,STAR1
WAITL0:JNB P3.4,WAITL0 ;等待鍵釋放
SETB F0
FUN01:LCALL FUN00
LCALL STAR1
LJMP FUN01;
FUN1:LCALL DL10MS ;消除抖動(dòng)
JB P3.5,STAR1
WAITL1:JNB P3.5,WAITL1 ;等待鍵釋放
SETB F0
FUN10:LCALL FUN11
LCALL STAR1
LJMP FUN10;
FUN2:LCALL DL10MS ;消除抖動(dòng)
JB P3.2,STAR1
WAITL2:JNB P3.2,WAITL2 ;等待鍵釋放
SETB F0
FUN20:LCALL FUN22
LCALL STAR1
LJMP FUN20;
FUN3:LCALL DL10MS ;消除抖動(dòng)
JB P3.3,STAR1
WAITL3:JNB P3.3,WAITL3 ;等待鍵釋放
CLR F0
MOV P1,#0FFH ;關(guān)顯示
LJMP STAR1;
FUN00:MOV A,#0FEH ;從P1.0到P1.7移動(dòng)點(diǎn)亮
FUN000:MOV P0,A
LCALL DL05S
JNB ACC.7,OUT
RL A
AJMP FUN000
OUT: RET;
FUN11:MOV A,#0FEH ;從P1.0到P1.7依次點(diǎn)亮
FUN111:MOV P1,A
LCALL DL05S
JZ OUT
RL A
ANL A,P1
AJMP FUN111;
FUN22:MOV A,#0FEH ;間隔點(diǎn)亮
FUN222:MOV P1,A
LCALL DL01S
CPL A
RL A
MOV P1,A
LCALL DL01S
RET;
FUN33: MOV A,#01H ;逐點(diǎn)熄滅
FUN333: MOV P1,A
LCALL DL01S
JNZ OUT
RL A
ORL A,P1
AJMP FUN333
DL01S:MOV R2,#0FFH ; 延時(shí)程序
MOV R7,#02H
LOOP1: DJNZ R2,LOOP1
LOOP5:DJNZ R7,DL512
RET
DL10MS:MOV R3,#14H
LOOP2: LCALL DL512
DJNZ R3,LOOP2
RET
DL05S:MOV R4,#0AH
LOOP3: LCALL DL10MS
DJNZ R4,LOOP3
RET
DL30S:MOV R5,#03H
LOOP4:LCALL DL05S
DJNZ R5,LOOP4
RET
END
4.2一秒鐘定時(shí)程序
MOV B,#0AH ;允許中斷
MOV TMOD,#01H ;工作方式1
MOV TH0,#0B0H
MOV TL0,#3CH
SETB TR0 ;啟動(dòng)計(jì)數(shù)
SETB EA ;開(kāi)中斷
BU:JBC TF0,SHI
SJMP BU
SHI:MOV TH0,#3CH
MOV TL0,#0B0H
RET
led燈相關(guān)文章:led燈原理
評(píng)論