;*****************************************************************************;實(shí)現(xiàn)功能:定時(shí)功能,參數(shù)是0.00s~99H,最多可以同時(shí)定時(shí)11個(gè)數(shù)(最先輸入的;定時(shí)應(yīng)為最大的定時(shí)時(shí)間)整點(diǎn)報(bào)時(shí),鬧鐘,計(jì)分器,省電模式,顯示星期;紅外遙控;秒表功能:參數(shù)是0.00s~24H,最多可以存儲(chǔ)11個(gè)瞬間時(shí)間。;顯示當(dāng)前時(shí)間;鍵盤(pán)功能:(平面圖);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%;%% 0 %% 1 %% 2 %% 3 %% ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ;%% 4 %% 5 %% 6 %% 7 %%;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%;%% 8 %% 9 %% 秒表 %% 定時(shí) %% ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ;%% 存儲(chǔ) %% 查看 %%顯示轉(zhuǎn)換 %% 清零 %% ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%;*****************************************************************************P_KEY EQU P1 ;宏定義鍵盤(pán)的接口是P1P2_KEY EQU P2 ;宏定義led位選的接口為P1P0_KEY EQU P0 ;宏定義要顯示的數(shù)據(jù)的接口為P0BUZZ EQU P3.0 ;蜂鳴器NO_OUT EQU 24H ;紅外遙控最終控制號(hào)碼存放單元NUMBER_A DATA 40H ;記錄定時(shí)/秒表實(shí)際時(shí)間NUMBER_B DATA 41HNUMBER_C DATA 42HNUMBER_D DATA 43HNUMBER_E DATA 44HNUMBER_F DATA 45HNUMBER_G DATA 46HNUMBER_H DATA 47HNUMBER_A6 DATA 30H ;記錄時(shí)鐘當(dāng)前時(shí)間NUMBER_B6 DATA 31HNUMBER_C6 DATA 32HNUMBER_D6 DATA 33HNUMBER_E6 DATA 34HNUMBER_F6 DATA 35HNUMBER_G6 DATA 36HNUMBER_H6 DATA 37HNUMBER_A2 DATA 28H ;多個(gè)定時(shí)比較時(shí)間NUMBER_B2 DATA 29HNUMBER_C2 DATA 2AHNUMBER_D2 DATA 2BHNUMBER_E2 DATA 2CHNUMBER_F2 DATA 2DHNUMBER_G2 DATA 2EHNUMBER_H2 DATA 2FHORG 0000HLJMP MAINORG 0003HLJMP INTOUT0 ;外部中斷0秒表ORG 000BH LJMP COUNT0 ;設(shè)置計(jì)時(shí)0中斷入口秒表ORG 0013HLJMP INTOUT1ORG 001BHLJMP COUNT1ORG 0030H ;程序存儲(chǔ)從該位開(kāi)始;數(shù)據(jù)初始化 MAIN: MOV SP, #50HCLR 20H.0 ;判斷是否可以改變定時(shí)的時(shí)間,0可以,1不可以CLR 20H.1 ;啟動(dòng)鬧鐘標(biāo)志位0關(guān),1開(kāi)CLR 20H.2 ;關(guān)鬧鐘鈴聲標(biāo)志CLR 20H.3 ;計(jì)分器標(biāo)志位CLR 20H.4 ;是否有鍵按下標(biāo)志位MOV 30H,#0AH ;記錄時(shí)鐘實(shí)際時(shí)間MOV 31H,#0AHMOV 32H,#0AHMOV 33H,#0AHMOV 34H,#0AHMOV 35H,#0AH MOV 36H,#0AH MOV 37H,#0AHMOV R0,#0D0H ;存儲(chǔ)秒表瞬間時(shí)間的區(qū)域,D0~D8是存儲(chǔ)鬧鐘資源BACK_0: MOV @R0,#0BH ;D0~D8是存儲(chǔ)鬧鐘空間,只能在初始化時(shí)清0INC R0CJNE R0,#0D8H,BACK_0MOV R0,#0D8H ;D8H~DFH為計(jì)分器的存儲(chǔ)地址,其初始化為; 0 VS 0MOV @R0,#0DH MOV R0,#0D9HMOV @R0,#0DHMOV R0,#0DAHMOV @R0,#00HMOV R0,#0DBHMOV @R0,#0CHMOV R0,#0DCHMOV @R0,#0CHMOV R0,#0DDHMOV @R0,#0DHMOV R0,#0DEHMOV @R0,#0DHMOV R0,#0DFHMOV @R0,#00HSETB BUZZ ;關(guān)閉蜂鳴器MOV 39H,#5 ;顯示選擇功能,為0時(shí)顯示40~47H的內(nèi)容,為5時(shí)顯示30~37的內(nèi)容MAIN0: MOV 40H,#00H ;記錄時(shí)鐘/秒表時(shí)間MOV 41H,#00HMOV 42H,#00HMOV 43H,#00HMOV 44H,#00HMOV 45H,#00H MOV 46H,#00H MOV 47H,#00HMOV 28H,#00H ;記錄多個(gè)定時(shí)時(shí)間MOV 29H,#00HMOV 2AH,#00HMOV 2BH,#00HMOV 2CH,#00HMOV 2DH,#00H MOV 2EH,#00H MOV 2FH,#00HMOV 48H,#55H ;暫停/繼續(xù)功能MOV 4AH,#55H ;顯示切換功能,顯示當(dāng)前時(shí)間/秒表定時(shí)時(shí)間MOV 4BH,#55H ;鬧鐘開(kāi)關(guān)轉(zhuǎn)換功能MOV 4CH,#55H ;計(jì)分器選擇功能,調(diào)整甲乙中一方的分?jǐn)?shù)MOV 49H,#0 ;計(jì)數(shù)器中斷選擇功能,為#1時(shí)執(zhí)行秒表程序,#2時(shí)執(zhí)行定時(shí)程序MOV 3AH,#0 ;存儲(chǔ)秒表時(shí)間的出入口資源MOV 3BH,#0 ;同3AHMOV 3CH,#0 ;存儲(chǔ)定時(shí)的出入口資源MOV 3DH,#0 ;;選擇定時(shí)/秒表的出入口資源。為0時(shí)可以選其一,為1時(shí)不能選擇MOV 3EH,#0 ;整點(diǎn)報(bào)時(shí)出入口資源,為1時(shí)關(guān)閉音樂(lè)MOV NO_OUT,#0H ;紅外遙控最終控制號(hào)碼存放單元清0MOV R0,#80H ;存儲(chǔ)秒表瞬間時(shí)間的區(qū)域,D0~D8是存儲(chǔ)鬧鐘資源BACK_1: MOV @R0,#0BHINC R0CJNE R0,#0D0H,BACK_1CLR P3.6 ;秒表狀態(tài)CLR P3.7 ;定時(shí)狀態(tài)SETB 20H.4MOV R2,#9H ;一次最多只能按8次MOV R1,#30HMOV R5,#1MOV R4,#0MOV TMOD , #99H MOV TL1 ,#00H MOV TH1 ,#0DCH SETB ET1 ;允許定時(shí)器1中斷SETB EX1 ;開(kāi)外部中斷SETB IT1 ;選擇邊沿觸發(fā)方式SETB EASETB PT0SETB PT1SETB PX0 MAIN1:ACALL KEYBOARD ;掃描鍵盤(pán) ACALL DISPLAY ;顯示程序ACALL RING ;整點(diǎn)報(bào)時(shí) ACALL ALARMCLOCK ;鬧鐘程序ACALL TELECONTROL ;紅外遙控模塊MOV A,49H ;只有選擇了定時(shí)程序時(shí)才掃描Buzzer程序CJNE A,#02H,MAIN1ACALL BUZZER ;調(diào)用蜂鳴器程序;MAIN2: ;DJNZ 3DH,MAIN1;MOV 3DH,#1;SETB EX1LJMP MAIN1;********************;秒表程序;********************TIME: MOV A,3DHCJNE A,#0,TIMEOVERMOV R2, #1H ;屏蔽0~9按鍵MOV 39H,#0 MOV 3DH,#1 ;選擇了秒表之后就不能再選擇定時(shí)SETB P3.6 ;P3.6為秒表的狀態(tài)燈MOV R0,#80H ;存儲(chǔ)秒表瞬間時(shí)間的區(qū)域全部顯示0MOV TMOD , #99H MOV TL0 , #00H MOV TH0 , #0DCH SETB EX0 ;開(kāi)外部中斷SETB IT0 ;選擇邊沿觸發(fā)方式SETB ET0 ;開(kāi)計(jì)數(shù)器中斷MOV 49H, #1HSETB EA ;開(kāi)總中斷TIMEOVER:RET;********************;定時(shí)程序;********************STOPWATCH: MOV A,3DHCJNE A,#0,STOPOVERMOV R1,#40HMOV R2,#9H ;一次最多只能按8次MOV 39H,#0MOV 3AH,#10MOV 3DH,#1 ;選擇了定時(shí)之后就不能再選擇秒表MOV 40H,#0AH ;初始化顯示時(shí)間,全部顯示"_"MOV 41H,#0AHMOV 42H,#0AHMOV 43H,#0AHMOV 44H,#0AHMOV 45H,#0AH MOV 46H,#0AH MOV 47H,#0AH SETB P3.7 ;P3.7為定時(shí)的狀態(tài)燈MOV TMOD , #99H MOV TL0 ,#00H MOV TH0 ,#0DCH SETB EX0 ;開(kāi)外部中斷SETB IT0 ;選擇邊沿觸發(fā)方式SETB ET0 ;開(kāi)外部中斷MOV 49H, #2HSETB EA ;開(kāi)總中斷STOPOVER:RET;********************** ;掃描鍵盤(pán) ;********************** KEYBOARD:CJNE R5,#1,NOKEYLJMP READ_KEYNOKEY: DJNZ R5, KEYOUT KEYOUT: RETREAD_KEY: ;按鍵掃描函數(shù)MOV P_KEY,#0ffHMOV P_KEY,#0f0HMOV A,P_KEY;判斷是否有鍵按下cjne A,#0f0H,RK1AJMP NO_KEY;有按鍵按下,延時(shí)去抖RK1: CALL delAy_time ;延時(shí)5ms 還沒(méi)有寫(xiě)出來(lái)MOV P_KEY,#0f0HMOV A,P_KEY;確認(rèn)是否有鍵按下CJNE A,#0f0H,RK2AJMP NO_KEY;確認(rèn)是有按鍵按下, 判斷哪行按鍵按下RK2:JNB ACC.4,RK4JNB ACC.5,RK5JNB ACC.6,RK6JNB ACC.7,RK7;沒(méi)有檢測(cè)到按鍵AJMP NO_KEYRK4:MOV B,#0MOV P_KEY,#0efHAJMP RK_NEXTRK5:MOV B,#4MOV P_KEY,#0dfHAJMP RK_NEXTRK6:MOV B,#8MOV P_KEY,#0BfHAJMP RK_NEXT0RK7:MOV B,#12MOV P_KEY,#07fHAJMP RK_NEXT1RK_next:MOV A,P_KEYJNB ACC.0,RK_NEXT_0JNB ACC.1,RK_NEXT_1JNB ACC.2,RK_NEXT_2JNB ACC.3,RK_NEXT_3;沒(méi)有檢測(cè)到按鍵AJMP NO_KEYLJMP NO_KEYSAVE_T_S_0:LJMP SAVE_T_SDISPLAY_T_S_0:LJMP DISPLAY_T_SCHANGE_0:LJMP CHANGE_DISRK_NEXT_0:MOV A,#0AJMP GET_KEYRK_NEXT_1:MOV A,#1AJMP GET_KEYRK_NEXT_2:MOV A,#2AJMP GET_KEYRK_NEXT_3:MOV A,#3;返回檢測(cè)到的按鍵編號(hào)GET_KEY: CLR 20H.4ADD A,BLJMP IFKEY;沒(méi)檢測(cè)到按鍵,返回0xffNO_KEY:MOV A,#0HIFKEY: JNB 20H.4,KEY_0 ;如果20H.4為0時(shí)證明有鍵按下LJMP KEY_1 ;否則跳出KEY_0: DJNZ R2, KEY_2 ; 當(dāng)R2不為0時(shí),運(yùn)行8次,直到顯示的8位都給定初值 MOV R2, #1H ;運(yùn)行8次后TIAO_2后的程序不再運(yùn)行,內(nèi)存不再賦值CLR ASETB 20H.4RETKEY_2: MOV @R1,AINC R1MOV R5, #70KEY_1: CLR ASETB 20H.4RET;//******************時(shí)間延遲函數(shù)DELAY_TIME: ;延時(shí)10msPUSH PSWPUSH ACC LOOP: MOV R7,#100 LOOP_1: MOV R6,#50 LOOP_2: DJNZ R6,LOOP_2DJNZ R7,LOOP_1POP ACCPOP PSWRET;****************************;顯示所記錄的秒表瞬間/定時(shí)的時(shí)間;****************************DISPLAY_T_S:MOV R5,#60MOV A, 49HJB ACC.0,MIAOBIAOJB ACC.1,DINGSHILJMP DISTIME_0DINGSHI:MOV 3AH,3CHMOV R4,3AHMOV 39H,#1DEC R4MOV 3AH,R4MOV 3CH,R4CJNE R4,#0FFH,DISTIME_0MOV 3CH,3BHLJMP DISTIME_0MIAOBIAO:MOV R4,3AHMOV 39H,#1DEC R4MOV 3AH,R4CJNE R4,#0FFH,DISTIME_0MOV 3AH,3BHDISTIME_0:RET;***********************;定時(shí)/秒表清零;*&*********************CLEAR:MOV R5,#60SETB BUZZ CLR TR0MOV R1,#40HMOV R2,#9H ;按鍵后 MOV 3AH,#0MOV 3BH,#0MOV 3DH,#0 MOV 39H,#5MOV 48H,#55H ;暫停/繼續(xù)功能MOV 49H,#0 ;計(jì)數(shù)器中斷選擇功能,為#1時(shí)執(zhí)行秒表程序,#2時(shí)執(zhí)行定時(shí)程序MOV 40H,#00H ;記錄譯碼后的顯示時(shí)間MOV 41H,#00HMOV 42H,#00HMOV 43H,#00HMOV 44H,#00HMOV 45H,#00H MOV 46H,#00H MOV 47H,#00HMOV 28H, #00H ;清0MOV 29H,#00HMOV 2AH,#00HMOV 2BH,#00HMOV 2CH,#00HMOV 2DH,#00H MOV 2EH,#00H MOV 2FH,#00HMOV R0,#0D8H ;D8H~DFH為計(jì)分器的存儲(chǔ)地址,其初始化為; 0 VS 0MOV @R0,#0DH MOV R0,#0D9HMOV @R0,#0DHMOV R0,#0DAHMOV @R0,#00HMOV R0,#0DBHMOV @R0,#0CHMOV TMOD , #99H ;t0模式1 MOV TL0 ,#00H MOV TH0 ,#0DCH CLR ET0 CLR EX0 ;開(kāi)外部中斷CLR P3.1CLR P3.5CLR P3.6CLR P3.7CLEAR_1: RET ;************************************;查看當(dāng)前時(shí)間/定時(shí)秒表當(dāng)前時(shí)間/關(guān)音樂(lè);************************************CHANGE_DIS:MOV R5,#60SETB ET1SETB TR1 SETB BUZZMOV A,4AH ; RL A MOV 4AH,AJNB ACC.1,CHANGE_1 ;查詢,A最低位為0時(shí)暫停計(jì)時(shí),為1時(shí)繼續(xù)計(jì)時(shí) MOV 39H,#5 LJMP CHANGE_2CHANGE_1: MOV 39H,#0CHANGE_2: RET ;*****************************;選擇程序:存儲(chǔ)秒表瞬間/多個(gè)定時(shí);*****************************SAVE_T_S: MOV R5,#60MOV A,49H JB ACC.0,SAVETIMEJB ACC.1,SAVESTOPLJMP STOPOUT;****************************;存儲(chǔ)十個(gè)定時(shí)時(shí)間;****************************SAVESTOP: MOV 39H,#1MOV 3BH,#10MOV R4,3AHCJNE R4,#0H,STOP10_0MOV R2,#1MOV 39H,#0LJMP STOPOUTSTOP10_0: MOV R2,#09HCJNE R4,#01H,STOP1MOV R1,#80HLJMP STOP10STOP1: CJNE R4,#02H,STOP2MOV R1,#88HLJMP STOP10STOP2: CJNE R4,#03H,STOP3MOV R1,#90HLJMP STOP10STOP3: CJNE R4,#04H,STOP4MOV R1,#98HLJMP STOP10STOP4: CJNE R4,#05H,STOP5MOV R1,#0A0HLJMP STOP10STOP5: CJNE R4,#06H,STOP6MOV R1,#0A8HLJMP STOP10STOP6: CJNE R4,#07H,STOP7MOV R1,#0B0HLJMP STOP10STOP7: CJNE R4,#08H,STOP8MOV R1,#0B8HLJMP STOP10STOP8: CJNE R4,#09H,STOP9MOV R1,#0C0HLJMP STOP10STOP9: CJNE R4,#0AH,STOP10MOV R1,#0C8HSTOP10: MOV 3CH,R4DEC R4MOV 3AH,R4STOPOUT: RET
評(píng)論