基于DS1302+AT89C2051制作的紅外遙控LED電子鐘
自制LED電子鐘在很多電子報(bào)刊雜志上都可以見(jiàn)到,但大多數(shù)在斷電后都要重新設(shè)置時(shí)間等
參數(shù),給使用帶來(lái)很多不便。也有用后備電池作為備用電源的,但往往體積較大。本文介紹
的LED電子鐘克服了以往的弊端,而且采用了家電通用的紅外遙控器進(jìn)行控制,方便使用。
有一路鬧鈴輸出,可以通過(guò)遙控器設(shè)置鬧鈴時(shí)間及允許與否。
電子鐘的正面
電子鐘的背面
一.工作原理
DS1302為達(dá)拉斯公司的一種實(shí)時(shí)時(shí)鐘芯片,主要特點(diǎn)是采用串行數(shù)據(jù)傳輸,可為掉電保護(hù)電
源提供可編程的充電功能,并且可以關(guān)閉充電功能。采用普通32768Hz晶振。
AT89C2051作為主控芯片,一是對(duì)接收到的紅外遙控編碼進(jìn)行判斷識(shí)別,并執(zhí)行相應(yīng)的處
理;第二就是定期的讀取時(shí)鐘芯片DS1302中的時(shí)間并把小時(shí)和肥以示在4位LED中;第三就是
對(duì)設(shè)置的鬧鈴時(shí)間與實(shí)時(shí)時(shí)間進(jìn)行比較,如果時(shí)間相同且鬧鈴允許,那么蜂鳴器就會(huì)以1秒
的周期鳴響一分鐘,提醒使用者。如果要停止鳴鬧,只要按遙控器相應(yīng)鍵就可以關(guān)閉鬧鈴。
鬧鈴時(shí)間保存在DS1302自帶的RAM中,不需要單獨(dú)的EEPROM。
二.硬件電路
圖一為電子鐘的原理圖,IC2為DS1302,電子愛(ài)好者可以向MAXIM公司索取免費(fèi)樣品。Y2為
32768 Hz石英晶振,可以用普通電子表里的。IC3為三腳的塑封一體化紅外接收頭。LED1-4
為高亮度共陽(yáng)數(shù)碼管。89C2051所用的晶振Y1如果沒(méi)有10MHz也可以用其他12M以?xún)?nèi)的代替,
只要修改程序中YS1和YS2的延時(shí)參數(shù),讓其保持延時(shí)長(zhǎng)度不變就行。調(diào)整R2可以改變數(shù)碼管
亮度。P1口接數(shù)碼管的八字段。數(shù)碼管左兩位顯示小時(shí),右兩位顯示分,當(dāng)顯示的是鬧鈴時(shí)
間時(shí)閃動(dòng)。第二位和第三位的小數(shù)點(diǎn)作為秒閃動(dòng),注意第三位數(shù)碼管按圖一布好印制版后安
裝時(shí)要旋轉(zhuǎn)180°,以便讓時(shí)和分之間出現(xiàn)“:”,最后一位小數(shù)點(diǎn)作為鬧鈴開(kāi)關(guān)標(biāo)志,亮表
示鬧鈴開(kāi)啟。蜂鳴器B2采用小型自帶音源的。
要特別說(shuō)明的是備用電源B1,可以用電池或者超級(jí)電容(10萬(wàn)uF以上)。雖然DS1302在主電
源掉電后,耗電很小,但如果要長(zhǎng)時(shí)間保證時(shí)鐘正常,最好選用小型充電電池。可以用老式
電腦主板上的那種3.6V充電電池。如果斷電時(shí)間較短(幾小時(shí)或幾天)時(shí),就可以用漏電較
小的普通電解電容代替。100uF就可以保證1小時(shí)的正常走時(shí)。DS1302在第一次加電后,須進(jìn)
行初始化操作。初始化后就可以按正常方法調(diào)整時(shí)間及鬧鈴。
三.軟件
軟件部分的重點(diǎn)是對(duì)DS1302的操作以及紅外遙控的解碼。單片機(jī)解碼可參看其他文章,這里
主要對(duì)設(shè)置部分作一些說(shuō)明:
遙控器采用長(zhǎng)虹彩電K11F型遙控器,遙控器按照16位地址碼,8位數(shù)據(jù)碼以及8位數(shù)據(jù)碼的反
碼發(fā)送。表一列出了各按鍵的編碼及本電子鐘對(duì)應(yīng)的動(dòng)作。如果采用其他遙控器,需對(duì)程序
相應(yīng)部分的編碼作修改。
操作方法中,任意是指該鍵第一次按后,進(jìn)入該狀態(tài),再次按后退出該狀態(tài)。
時(shí)間設(shè)置:按“菜單”鍵進(jìn)入設(shè)置狀態(tài),LED只顯示正常時(shí)間的小時(shí),按“↑↓”鍵調(diào)整數(shù)
值,按“←“、”→”鍵可在鬧鈴與正常時(shí)間之間移動(dòng)。任意時(shí)刻再次按“菜單”鍵就退出
設(shè)置。
鬧鈴設(shè)置:鬧鈴時(shí)間在時(shí)間設(shè)置中進(jìn)行。鬧鈴允許和取消可在任意時(shí)刻按“靜音”鍵。
顯示開(kāi)關(guān):可在任意時(shí)刻按“顯示”鍵開(kāi)啟和關(guān)閉顯示器。
初始化:在按“菜單”鍵進(jìn)入設(shè)置狀態(tài)后任意時(shí)刻按“日歷”鍵,初始化后的時(shí)間為
2002/12/1/12:00:00
點(diǎn)擊文件名下載 代碼.rar
;DS1302+AT89C2051的LED鐘
;遙控器各按鍵數(shù)據(jù)碼,可根據(jù)不同的遙控器修改對(duì)應(yīng)的鍵碼
muteM?? EQU 10h???????????????? ;靜音鍵??????????? 鬧鈴開(kāi)/關(guān)
timerT? EQU 0Ch???????????????? ;菜單鍵??????????? 進(jìn)入/退出設(shè)置狀態(tài)
leftL?? EQU 46h???????????????? ;左移鍵?????
rightR? EQU 47h???????????????? ;右移鍵
upU???? EQU 19h???????????????? ;增加鍵
downD?? EQU 1dh???????????????? ;減少鍵
d_off?? EQU 16H???????????????? ;顯示鍵??????????? LED數(shù)碼管顯示/關(guān)閉
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? 時(shí)
;63h? 日
;64h? 月
;65h? DAY
;66h? 年
;6Ah? 鬧分??? from 00(1302)
;6BH? 鬧時(shí)??? 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í)參數(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????????? ;定時(shí)到時(shí),顯示閃爍
???????? 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???????????? ;顯示設(shè)置小時(shí)
???????? 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????????????? ;顯示設(shè)置分
???????? 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?????????? ;顯示設(shè)置鬧時(shí)
???????? JNB?? 07H,D4_OUT??????????? ;顯示時(shí)閃爍
???????? 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????????????? ;顯示時(shí)閃爍
???????? MOV?? A,6AH?????????????????? ;顯示設(shè)置鬧分
???????? 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
;************************定時(shí)讀取1302時(shí)間及判斷鬧鈴時(shí)間是否到*******
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?????????????? ;定時(shí)到標(biāo)志
???????? 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
;************************有接收到遙控器信號(hào)*******
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比較 不同則無(wú)效丟棄(核對(duì)數(shù)據(jù)是否準(zhǔn)確)
????? JNZ? EXIT
????? ACALL DO??????? ;相應(yīng)按鍵的處理
EXIT: SETB EA
????? POP? 03H
????? POP? 02H
????? POP? DPL
????? POP? DPH
????? POP? PSW
????? POP? ACC
????? RETI
;--------------------delay-----------------------
YS1:? MOV??? 70H,#16D?? ;延時(shí)1
D1:?? MOV??? 71H,#21D
????? DJNZ?? 71H,$
????? DJNZ?? 70H,D1
????? RET
YS2:? MOV??? 70H,#09D?? ;延時(shí)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 為設(shè)置標(biāo)志,0DH為全顯示標(biāo)志,0EH為顯示設(shè)置小時(shí)標(biāo)志,0FH為顯示設(shè)置分標(biāo)志
;10H 為顯示設(shè)置鬧時(shí)標(biāo)志,11H為顯示設(shè)置鬧分標(biāo)志
;增加鬧時(shí)靜音功能
;mute-10h,timer-0eh,left-46h,right-47h,up-19h,down-1dh
D???? MOV???? A,1CH
??????? CJNE??? A,#TIMERT,REDO? ;代碼不是設(shè)置/退出鍵
??????? JNB???? 0CH,SET1??????? ;是,則進(jìn)入
??????? CLR???? 0CH???????????? ;是,已經(jīng)進(jìn)入,則退出
??????? SETB??? 0DH???????????? ;恢復(fù)正常顯示
??????? 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? ;不是設(shè)置鍵的處理REDO1,2,3,4...
??????? LJMP??? MUTE??????????? ;MUTE?
REDO1:? CJNE??? A,#D_OFF,DO_SET2
??????? LJMP??? DIS_OFF???????? ;關(guān)閉顯示
DO_SET2:JB????? 0CH,SET2??????? ;時(shí)間設(shè)置的處理
??????? 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?????????????? ;鬧鐘小時(shí)增加
??????? MOV???? A,6BH
??????? CJNE??? A,#24D,INCH3
??????? MOV???? 6BH,#0
INCH3:? MOV???? R1,#0C2H
??????? MOV???? R0,6BH
??????? ACALL?? SETONE??????????? ;寫(xiě)入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???????? ;充電器設(shè)置
???????? 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
;-----寫(xiě)一地址---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
評(píng)論
查看更多