基于DS1302+AT89C2051制作的紅外遙控LED電子鐘
muteM EQU 10h ;靜音鍵 鬧鈴開/關
timerT EQU 0Ch ;菜單鍵 進入/退出設置狀態(tài)
leftL EQU 46h ;左移鍵
rightR EQU 47h ;右移鍵
upU EQU 19h ;增加鍵
downD EQU 1dh ;減少鍵
d_off EQU 16H ;顯示鍵 LED數(shù)碼管顯示/關閉
recall EQU 44H ;日歷鍵 DS1302初始化操作
K_on BIT P3.0 ;鬧鈴輸出
LED1 BIT P3.3
LED2 BIT P3.4
LED3CLK BIT P3.5 ;DS1302
LED4IO BIT P3.7
RST BIT P3.1
SECOND EQU 60H
;60H 秒
;61h 分
;62h 時
;63h 日
;64h 月
;65h DAY
;66h 年
;6Ah 鬧分 from 00(1302)
;6BH 鬧時 from 01(1302)
;***************************
ORG 0000H
AJMP START
ORG 0003H
LJMP S_INT ;IRF
ORG 000BH ;200Us
LJMP P_INT ;
ORG 001BH ;display LED
LJMP DISPLAY
;**************************** ;main program
ORG 0030H
START: CLR RST
MOV SP,#2AH
SETB 05H
CLR 06H
SETB 07H;CLR 07H
CLR 08H
CLR 09H
CLR 0AH
CLR 0BH
CLR 0CH
SETB 0DH
CLR 0EH
CLR 0FH
CLR 10H
CLR 11H
MOV R2,#00H ;
MOV R3,#00H ;
MOV TMOD,#12H
MOV TL1,#0e5H ;wait
MOV TH1,#0BeH
MOV TH0,#3FH ;200uS 3f
MOV TL0,#3FH
SETB ET0
SETB ET1
setb pt0
SETB TR0
SETB TR1
SETB IT0 ;
SETB EX0 ;
CLR PX0
;LCALL SET1302 ;初始化
MOV R1,#0C1H ;取定時參數(shù)從1302中
acall T_6061
MOV 6AH,A ;M
MOV R1,#0C3H
ACALL T_6061
MOV 6BH,A ;H
MOV 61H,#0
MOV 62H,#0
SETB EA
sjmp $
;********************************
DISPLAY: PUSH ACC
PUSH PSW
MOV TL1,#0e0H ;wait how long to display (20ms)
MOV TH1,#0b0H
mov dptr,#tab1
JB 0EH,DIS2
JB 0FH,DIS3
JB 10H,DIS4
JB 11H,DIS5
JNB 0DH,D_OUT
JNB 08H,D_GO ;定時到時,顯示閃爍
JNB 07H,D_OUT
D_G MOV DPTR,#TAB1
MOV A,62H
ANL A,#0FH
MOV B,A
MOV A,62H
SWAP A
ANL A,#07H
MOVC A,@A+DPTR
MOV P1,A
CLR LED1
LCALL DL2M
SETB LED1
MOV A,B
MOVC A,@A+DPTR
MOV C,07H
MOV acc.7,C ;秒燈閃爍
MOV P1,A
CLR LED2
LCALL DL2M
SETB LED2
mov dptr,#tab2 ;倒裝LED字段表
MOV A,61H
ANL A,#0FH
MOV B,A
MOV A,61H
SWAP A
ANL A,#0FH
MOVC A,@A+DPTR
MOV C,07H
MOV acc.6,C ;秒燈閃爍
MOV P1,A
CLR LED3CLK
LCALL DL2M
SETB LED3CLK
mov dptr,#tab1
MOV A,B
MOVC A,@A+DPTR
MOV C,06H
cpl c
MOV acc.7,C ;鬧鈴指示燈
MOV P1,A
CLR LED4IO
LCALL DL2M
SETB LED4IO
D_OUT: SETB TR1
POP PSW
POP ACC
RETI
;*********************
DIS2: AJMP DIS_2
DIS3: AJMP DIS_3
DIS4: AJMP DIS_4
DIS5: AJMP DIS_5
;********************
DIS_2: mov dptr,#tab1 ;顯示設置小時
MOV 6FH,62H
ACALL BCD_HEX
MOV B,#10
DIV AB
MOVC A,@A+DPTR
MOV P1,A
CLR LED1
LCALL DL2M
SETB LED1
MOV A,B
MOVC A,@A+DPTR
MOV P1,A
CLR LED2
LCALL DL2M
SETB LED2
SETB TR1
POP PSW
POP ACC
RETI
;*****************
DIS_3: MOV DPTR,#TAB2 ;顯示設置分
MOV 6FH,61H
ACALL BCD_HEX
MOV B,#10
DIV AB
MOVC A,@A+DPTR
MOV P1,A
CLR LED3CLK
LCALL DL2M
SETB LED3CLK
MOV A,B
MOV DPTR,#TAB1
MOVC A,@A+DPTR
MOV P1,A
CLR LED4IO
LCALL DL2M
SETB LED4IO
SETB TR1
POP PSW
POP ACC
RETI
;*****************
DIS_4: mov dptr,#tab1 ;顯示設置鬧時
JNB 07H,D4_OUT ;顯示時閃爍
MOV A,6BH
MOV B,#0AH
DIV AB
MOVC A,@A+DPTR
MOV P1,A
CLR LED1
LCALL DL2M
SETB LED1
MOV A,B
MOVC A,@A+DPTR
MOV P1,A
CLR LED2
LCALL DL2M
SETB LED2
D4_OUT: SETB TR1
POP PSW
POP ACC
RETI
;***********************
DIS_5: MOV DPTR,#TAB2
JNB 07H,D5_OUT ;顯示時閃爍
MOV A,6AH ;顯示設置鬧分
MOV B,#0AH
DIV AB
MOVC A,@A+DPTR
MOV P1,A
CLR LED3CLK
LCALL DL2M
SETB LED3CLK
MOV DPTR,#TAB1
MOV A,B
MOVC A,@A+DPTR
MOV P1,A
CLR LED4IO
LCALL DL2M
SETB LED4IO
D5_OUT: SETB TR1
POP PSW
POP ACC
RETI
;*****************************
DL2M: MOV 43H,#14H ; every LED(2ms)
DL2: MOV 44H,#14H
DL1: NOP
NOP
DJNZ 44H,DL1
DJNZ 43H,DL2
RET
;************************定時讀取1302時間及判斷鬧鈴時間是否到*******
P_INT: PUSH ACC
PUSH PSW
INC R2
CJNE R2,#250D,P_OUT
MOV R2,#00H
INC R3
CJNE R3,#10D,P_OUT
MOV R3,#00H
CPL 07H
MOV P1,#0FFH
ACALL R_1302
OUT: JNB 06H,P_OUT
MOV A,6BH
MOV B,#10
DIV AB
SWAP A
ADD A,B
CJNE A,62H,PP_OUT
MOV A,6AH
MOV B,#10
DIV AB
SWAP A
ADD A,B
CJNE A,61H,PP_OUT
SETB 08H ;定時到標志
MOV C,07H
cpl c
MOV K_ON,C
P_OUT: POP PSW
POP ACC
RETI
PP_OUT: SETB K_ON
CLR 08H
POP PSW
POP ACC
RETI
;************************有接收到遙控器信號*******
S_INT:CLR EA
PUSH ACC
PUSH PSW
PUSH DPH
PUSH DPL
PUSH 02H
PUSH 03H
MOV R6,#10D ;
SB: ACALL YS1
JB P3.2,EXIT
DJNZ R6, SB
JNB P3.2, $ ;
ACALL YS2 ;
JB P3.2,EXIT
MOV R1,#1AH ;
MOV R2,#4D
PP: MOV R3,#8D
JJJJ: JNB P3.2,$
ACALL YS1
MOV C,P3.2
JNC UUU
JB P3.2,$
UUU: MOV A,@R1
RRC A
MOV @R1,A
DJNZ R3,JJJJ
INC R1
DJNZ R2,PP
;-------------------------------------
MOV A,1AH ;
XRL A,#40h ;判斷1AH的值是否等于遙控器低8位地址(40h)
JNZ EXIT ;
MOV A,1bH
XRL A,#0bfh ;再判斷高8位地址是否正確(0bfh)
JNZ EXIT
MOV A,1CH
CPL A
XRL A,1DH ;將1CH的值取反后和1DH比較 不同則無效丟棄(核對數(shù)據(jù)是否準確)
JNZ EXIT
ACALL DO ;相應按鍵的處理
EXIT: SETB EA
POP 03H
POP 02H
POP DPL
POP DPH
POP PSW
POP ACC
RETI
;--------------------delay-----------------------
YS1: MOV 70H,#16D ;延時1
D1: MOV 71H,#21D
DJNZ 71H,$
DJNZ 70H,D1
RET
YS2: MOV 70H,#09D ;延時2
D2: MOV 71H,#220D
DJNZ 71H,$
DJNZ 70H,D2
RET
;---------------------------------------------------------
TAB: DB 00H,01H,02H,03H,04H,05H,06H,07H,08H,09H ;TAB1 LED數(shù)碼管顯示表 TAB遙控器鍵值表(未用)
;TAB1: DB 3FH,11H,5EH,5BH,71H,6BH,6FH,19H,7FH,7bH,77H,7CH,39H,5EH,79H,71H
tab1: DB 0C0H,0F9H,0a4h,0b0h,99h,92h,82h,0f8h,80h,90h,88h,83h,0a7h,0a1h,86h,8EH
TAB2: DB 0c0H,0f9H,64H,70H,59H,52H,42H ;倒裝LED段碼表
;0CH 為設置標志,0DH為全顯示標志,0EH為顯示設置小時標志,0FH為顯示設置分標志
;10H 為顯示設置鬧時標志,11H為顯示設置鬧分標志
;增加鬧時靜音功能
;mute-10h,timer-0eh,left-46h,right-47h,up-19h,down-1dh
D MOV A,1CH
CJNE A,#TIMERT,REDO ;代碼不是設置/退出鍵
JNB 0CH,SET1 ;是,則進入
CLR 0CH ;是,已經進入,則退出
SETB 0DH ;恢復正常顯示
CLR 0EH
CLR 0FH
CLR 10H
CLR 11H
RET
SET1: SETB 0CH
SETB 0EH
CLR 0DH
CLR 0FH
CLR 10H
CLR 11H
RET
RED CJNE A,#MUTEM,REDO1 ;不是設置鍵的處理REDO1,2,3,4...
LJMP MUTE ;MUTE?
REDO1: CJNE A,#D_OFF,DO_SET2
LJMP DIS_OFF ;關閉顯示
DO_SET2:JB 0CH,SET2 ;時間設置的處理
RET
SET2: CJNE A,#UPU,SET2A
LJMP INC1 ;+加(^)
SET2A: CJNE A,#DOWND,SET2B
LJMP DEC2 ;- 減
SET2B: CJNE A,#RIGHTR,SET2C
LJMP RIGHT ;RIGHT右移(>)
SET2C: CJNE A,#LEFTL,SET2D
LJMP LEFT ;LEFT左移()
SET2D: CJNE A,#RECALL,SET2EXT ;DS1302初始化
LJMP SET1302
SET2EXT:RET
;--------------------------------INC------------------------
INC1: JB 0EH,INCH
JB 0FH,INCM
JB 10H,INC_H
JB 11H,INC_M
RET
INC_H: INC 6BH ;鬧鐘小時增加
MOV A,6BH
CJNE A,#24D,INCH3
MOV 6BH,#0
INCH3: MOV R1,#0C2H
MOV R0,6BH
ACALL SETONE ;寫入DS1302
RET
INC_M: INC 6AH ;鬧鐘分增加
MOV A,6AH
CJNE A,#60D,INCH4
MOV 6AH,#0
INCH4: MOV R1,#0C0H
MOV R0,6AH
ACALL SETONE ;
RET
INCH: ;INC 62H ;
MOV 6FH,62H
ACALL BCD_HEX
INC A
CJNE A,#24D,INCH1
MOV A,#0
INCH1: MOV 6FH,A
ACALL HEX_BCD
MOV 62H,A
MOV R1,#84H
MOV R0,62H
ACALL SETONE ;
RET
INCM: ;INC 61H ;
MOV 6FH,61H
ACALL BCD_HEX
INC A
CJNE A,#60D,INCH2
MOV A,#0
INCH2: MOV 6FH,A
ACALL HEX_BCD
MOV 61H,A
MOV R1,#82H
MOV R0,61H
ACALL SETONE ;
RET
;----------------------------------DEC----------------------
DEC2: JB 0EH,DECH
JB 0FH,DECM
JB 10H,DEC_H
JB 11H,DEC_M
RET
DECH: MOV 6FH,62H
ACALL BCD_HEX
DEC A
CJNE A,#0FFH,DECH1
MOV A,#23
DECH1: MOV 6FH,A
ACALL HEX_BCD
MOV 62H,A
MOV R1,#84H
MOV R0,62H
ACALL SETONE
RET
DECM: MOV 6FH,61H
ACALL BCD_HEX
DEC A
CJNE A,#0FFH,DECM1
MOV A,#59
DECM1: MOV 6FH,A
ACALL HEX_BCD
MOV 61H,A
MOV R1,#82H
MOV R0,61H
ACALL SETONE
RET
DEC_H: DEC 6BH
MOV A,6BH
CJNE A,#0FFH,DECH3
MOV 6BH,#23D
DECH3: MOV R1,#0C2H
MOV R0,6BH
ACALL SETONE
RET
DEC_M: DEC 6AH
MOV A,6AH
CJNE A,#0FFH,DECH4
MOV 6AH,#59D
DECH4: MOV R1,#0C0H
MOV R0,6AH
ACALL SETONE
RET
;--------------------------------RIGHT----------------------
RIGHT: JB 0EH,RIGHT1
JB 0FH,RIGHT2
JB 10H,RIGHT3
JB 11H,RIGHT4
RET ;右移
RIGHT1: CLR 0EH
SETB 0FH
RET
RIGHT2: CLR 0FH
SETB 10H
RET
RIGHT3: CLR 10H
SETB 11H
RET
RIGHT4: CLR 11H
SETB 0EH
RET
;--------------------------------LEFT-----------------------
LEFT: JB 0EH,LEFT1
JB 0FH,LEFT2
JB 10H,LEFT3
JB 11H,LEFT4
RET ;左移
LEFT1: SETB 11H
CLR 0EH
RET
LEFT2: SETB 0EH
CLR 0FH
RET
LEFT3: SETB 0FH
CLR 10H
RET
LEFT4: SETB 10H
CLR 11H
RET
;------------------------------MUTE--------------
MUTE: setb k_ON
CPL 06H ;靜音
CLR 08H
RET
;-----------------------------DISPLAY OFF--------
DIS_OFF:CLR ET1
CPL 05H
JNB 05H,REDORE
SETB ET1
REDORE: RET
;------------------------------------初始化1302-------------------------
SET1302: CLR RST ;2002年1月1日12:00:00
CLR LED3CLK
MOV SECOND,#0
MOV 61H,#0
MOV 62H,#18 ;
MOV 63H,#1
MOV 64H,#1
MOV 65H,#1
MOV 66H,#2
SETB RST
MOV A,#8EH
LCALL R_BIT
MOV A,#00H
LCALL R_BIT
SETB LED3CLK
CLR RST
MOV R0,#SECOND
MOV R7,#7
MOV R1,#80H
SET1302A:CLR RST
CLR LED3CLK
SETB RST
MOV A,R1
LCALL R_BIT
MOV A,@R0
LCALL R_BIT
INC R0
INC R1
INC R1
SETB LED3CLK
CLR RST
DJNZ R7,SET1302A
CLR RST
CLR LED3CLK
sETB LED3CLK
nop
CLR RST
nop
clr led3clk
SETB RST
MOV A,#90H
LCALL R_BIT
MOV A,#10100101B ;充電器設置
LCALL R_BIT
SETB LED3CLK
CLR RST
CLR LED3CLK
SETB RST
MOV A,#8EH
LCALL R_BIT
MOV A,#80H
LCALL R_BIT
SETB LED3CLK
CLR RST
RET
;----------------------讀取一RAM ------
T_6061: CLR RST
CLR LED3CLK
SETB RST
MOV A,R1
LCALL R_BIT
LCALL W_BIT
SETB LED3CLK
CLR RST
RET
;-----------------------------
R_1302: MOV R0,#SECOND
MOV R7,#7
MOV R1,#81H
R_1302A: CLR RST
CLR LED3CLK
SETB RST
MOV A,R1
LCALL R_BIT
LCALL W_BIT
MOV @R0,A
INC R0
INC R1
INC R1
SETB LED3CLK
CLR RST
DJNZ R7,R_1302A
RET
;------------------R_BIT------------------
R_BIT: MOV R4,#8
R_BIT1: RRC A
MOV LED4IO,C
SETB LED3CLK
CLR LED3CLK
DJNZ R4,R_BIT1
RET
;-------------------W_BIT-----------------------
W_BIT: MOV R4,#8
W_BIT1: MOV C,LED4IO
RRC A
SETB LED3CLK
CLR LED3CLK
DJNZ R4,W_BIT1
RET
;--------------------------------------------------
BCD_HEX:
MOV A,6FH
ANL A,#0FH
MOV B,A
MOV A,6FH
MOV 6FH,B
SWAP A
ANL A,#0FH
MOV B,#0AH
MUL AB
ADD A,6FH
;MOV 6FH,A
RET
HEX_BCD:
MOV A,6FH
MOV B,#10
DIV AB
SWAP A
ADD A,B
;MOV 6FH,A
RET
;-----寫一地址---R1 為地址,R0 為數(shù)據(jù)----------
SETONE: CLR LED3CLK
CLR RST
CLR LED3CLK
NOP
SETB RST
MOV A,#8EH
LCALL R_BIT
MOV A,#00H
LCALL R_BIT
SETB LED3CLK
CLR RST
CLR LED3CLK
NOP
CLR RST
CLR LED3CLK
SETB RST
MOV A,R1
LCALL R_BIT
MOV A,R0
LCALL R_BIT
NOP
SETB LED3CLK
CLR RST
NOP
NOP
CLR RST
CLR LED3CLK
SETB RST
MOV A,#8EH
LCALL R_BIT
MOV A,#80H
LCALL R_BIT
SETB LED3CLK
CLR RST
RET
評論