PWM控制LED臺燈程序帶紅外遙控
;------------------------------------------------
IR_SHOW: ;使用我的5644遙控器。
MOV A,50H ;
XRL A,#40H ;判斷遙控器低8位地址是否正確(40H)
JNZ IR_SHOW1 ;
MOV A,51H
XRL A,#3FH ;再判斷遙控器高8位地址是否正確(3FH)
JNZ IR_SHOW1
MOV A,52H
CPL A ;將52H 取反后和53H 比較
CJNE A,53H,IR_SHOW1 ;如果不等表示接收數(shù)據(jù)發(fā)生錯誤,放棄。
CALL D1;解碼成功則調(diào)用相應(yīng)按鍵的處理程序+++++++++++++++++++++++++
;MOV A,IR_NEW
;CJNE A,#0FFH,IR_PWM;不是數(shù)字鍵則退出
;JMP IR_SHOW1
IR_PWM:
MOV DPTR,#IR_ASC
MOV A,IR_NEW
MOVC A,@A+DPTR
MOV PWM,A
IR_SHOW1:
POP PSW
POP ACC
SETB IRIN
SETB EA
RETI
D1:MOV A,52H
CJNE A,#01H,D2 ;是數(shù)字鍵1嗎?
MOV IR_NEW,#01H;是則送數(shù)據(jù)01H
CALL BEEP_BL ;蜂鳴器報(bào)警。
RET
D2:CJNE A,#02H,D3 ;是數(shù)字鍵2嗎?
MOV IR_NEW,#02H;是則送數(shù)據(jù)02H
CALL BEEP_BL ;蜂鳴器報(bào)警。
RET
D3:CJNE A,#03H,D4 ;是數(shù)字鍵3嗎?
MOV IR_NEW,#03H;是則送數(shù)據(jù)03H
CALL BEEP_BL ;蜂鳴器報(bào)警。
RET
D4:CJNE A,#04H,D5 ;是數(shù)字鍵4嗎?
MOV IR_NEW,#04H;是則送數(shù)據(jù)04H
CALL BEEP_BL ;蜂鳴器報(bào)警。
RET
D5:CJNE A,#05H,D6 ;是數(shù)字鍵5嗎?
MOV IR_NEW,#05H;是則送數(shù)據(jù)05H
CALL BEEP_BL ;蜂鳴器報(bào)警。
RET
D6:CJNE A,#06H,D7 ;是數(shù)字鍵6嗎?
MOV IR_NEW,#06H;是則送數(shù)據(jù)06H
CALL BEEP_BL ;蜂鳴器報(bào)警。
RET
D7:CJNE A,#07H,D8 ;是數(shù)字鍵7嗎?
MOV IR_NEW,#07H;是則送數(shù)據(jù)07H
CALL BEEP_BL ;蜂鳴器報(bào)警。
RET
D8:CJNE A,#08H,D9 ;是數(shù)字鍵8嗎?
MOV IR_NEW,#08H;是則送數(shù)據(jù)08H
CALL BEEP_BL ;蜂鳴器報(bào)警。
RET
D9:CJNE A,#09H,D0 ;是數(shù)字鍵9嗎?
MOV IR_NEW,#09H;是則送數(shù)據(jù)09H
CALL BEEP_BL ;蜂鳴器報(bào)警。
RET
D0:CJNE A,#00H,D15;是數(shù)字鍵0嗎?
MOV IR_NEW,#00H;是則送數(shù)據(jù)00H
CALL BEEP_BL ;蜂鳴器報(bào)警。
RET
D13:CJNE A,#11H,D14;是音量加鍵嗎?實(shí)現(xiàn)速度加
MOV IR_NEW,#0FFH;非數(shù)字鍵標(biāo)示為0FFH
INC PWM
MOV A,PWM
CJNE A,#00H,D13_OUT
CALL BEEP_BL ;蜂鳴器報(bào)警。
MOV PWM,#0FFH
D13_OUT:
RET
D14:CJNE A,#10H,D15;是音量減鍵嗎?實(shí)現(xiàn)速度減
MOV IR_NEW,#0FFH;非數(shù)字鍵標(biāo)示為0FFH
DEC PWM
MOV A,PWM
CJNE A,#0FFH,D14_OUT;9
CALL BEEP_BL ;蜂鳴器報(bào)警。
MOV PWM,#01H
D14_OUT:
RET
D15:
;MOV IR_NEW,#0FFH;非數(shù)字鍵標(biāo)示為0FFH
RET
;**********************************************
;判斷顯示程序
;-------------
DISPLAY:
DIS0:
MOV A,PWM
SUBB A,#LEVEL0
JNC DIS1
MOV LED_RAM,#9
JMP LED_DISP
DIS1:
MOV A,PWM
SUBB A,#LEVEL1
JNC DIS2
MOV LED_RAM,#8
JMP LED_DISP
DIS2:
MOV A,PWM
SUBB A,#LEVEL2
JNC DIS3
MOV LED_RAM,#7
JMP LED_DISP
DIS3:
MOV A,PWM
SUBB A,#LEVEL3
JNC DIS4
MOV LED_RAM,#6
JMP LED_DISP
DIS4:
MOV A,PWM
SUBB A,#LEVEL4
JNC DIS5
MOV LED_RAM,#5
JMP LED_DISP
DIS5:
MOV A,PWM
SUBB A,#LEVEL5
JNC DIS6
MOV LED_RAM,#4
JMP LED_DISP
DIS6:
MOV A,PWM
SUBB A,#LEVEL6
JNC DIS7
MOV LED_RAM,#3
JMP LED_DISP
DIS7:
MOV A,PWM
SUBB A,#LEVEL7
JNC DIS8
MOV LED_RAM,#2
JMP LED_DISP
DIS8:
MOV A,PWM
SUBB A,#LEVEL8
JNC DIS9
MOV LED_RAM,#1
JMP LED_DISP
DIS9:
MOV A,PWM
SUBB A,#LEVEL9
JNC LED_DISP
MOV LED_RAM,#0
LED_DISP:
MOV DPTR,#LED_ASC
MOV A,LED_RAM
MOVC A,@A+DPTR
MOV LED_PORT,A
RET
LED_ASC:;共陰極LED代碼
DB 3FH,06H,5BH,4FH,66H;0~F代碼
DB 6DH,7DH,07H,7FH,6FH
DB 77H,7CH,39H,5EH,79H
DB 71H
DB 0BFH,086H,0DBH,0CFH,0E6H;0.~9.(帶小數(shù)點(diǎn))代碼
DB 0EDH,0FDH,087H,0FFH,0EFH
DB 039H;字符“C”
;****************************************************
IR_ASC:
DB 0FAH,0EAH,0DAH,0CAH,0BAH
DB 0A0H, 80H, 60H, 40H, 02H
;------------------------------------------------
; DELAY R5*0.14MS
DEL:MOV R5,#1 ;IR 解碼使用
DEL0: MOV R6,#2
DEL1: MOV R7,#32
DEL2: DJNZ R7,DEL2
DJNZ R6,DEL1
DJNZ R5,DEL0
RET
;------------------------
;10ms 延時子程序,按鍵去抖動用
DELAY:
MOV R5,#50
DELAY1:
MOV R6,#100
DJNZ R6,$
DJNZ R5,DELAY1
RET
;-----------------------------------------------
;蜂鳴器響一聲子程序
BEEP_BL:MOV R6,#100
BL1:CALL BL2
CPL BEEP
DJNZ R6,BL1
MOV R5,#25
CALL DELAY2
RET
BL2:MOV R7,#180
BL3:NOP
DJNZ R7,BL3
RET
DELAY2: MOV R6,#50;延時R5×10MS
BL4: MOV R7,#100
BL5: DJNZ R7,BL5
DJNZ R6,BL4
DJNZ R5,DELAY2
RET
;---------------------------------------------------
END
pwm相關(guān)文章:pwm原理
蜂鳴器相關(guān)文章:蜂鳴器原理
評論