;*****************************************************************************
;完成功用:守时功用,参数是0.00s~99H,最多能够一起守时11个数(最早输入的;守时应为最大的守时时刻)整点报时,闹钟,计分器,省电形式,显现星期;红外遥控;秒表功用:参数是0.00s~24H,最多能够存储11个瞬间时刻。;显现当时时刻;键盘功用:(平面图);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%;%% 0 %% 1 %% 2 %% 3 %% ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ;%% 4 %% 5 %% 6 %% 7 %%;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%;%% 8 %% 9 %% 秒表 %% 守时 %% ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ;%% 存储 %% 检查 %%显现转化 %% 清零 %% ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%;*****************************************************************************P_KEY EQU P1 ;宏界说键盘的接口是P1P2_KEY EQU P2 ;宏界说led位选的接口为P1P0_KEY EQU P0 ;宏界说要显现的数据的接口为P0BUZZ EQU P3.0 ;蜂鸣器NO_OUT EQU 24H ;红外遥控终究操控号码寄存单元NUMBER_A DATA 40H ;记载守时/秒表实践时刻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 ;记载时钟当时时刻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 ;多个守时比较时刻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 ;设置计时0中止进口秒表ORG 0013HLJMP INTOUT1ORG 001BHLJMP COUNT1ORG 0030H ;程序存储从该位开端;数据初始化 MAIN: MOV SP, #50HCLR 20H.0 ;判别是否能够改动守时的时刻,0能够,1不能够CLR 20H.1 ;发动闹钟标志位0关,1开CLR 20H.2 ;关闹钟铃声标志CLR 20H.3 ;计分器标志位CLR 20H.4 ;是否有键按下标志位MOV 30H,#0AH ;记载时钟实践时刻MOV 31H,#0AHMOV 32H,#0AHMOV 33H,#0AHMOV 34H,#0AHMOV 35H,#0AH MOV 36H,#0AH MOV 37H,#0AHMOV R0,#0D0H ;存储秒表瞬间时刻的区域,D0~D8是存储闹钟资源BACK_0: MOV @R0,#0BH ;D0~D8是存储闹钟空间,只能在初始化时清0INC R0CJNE R0,#0D8H,BACK_0MOV R0,#0D8H ;D8H~DFH为计分器的存储地址,其初始化为; 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 ;封闭蜂鸣器MOV 39H,#5 ;显现挑选功用,为0时显现40~47H的内容,为5时显现30~37的内容MAIN0: MOV 40H,#00H ;记载时钟/秒表时刻MOV 41H,#00HMOV 42H,#00HMOV 43H,#00HMOV 44H,#00HMOV 45H,#00H MOV 46H,#00H MOV 47H,#00HMOV 28H,#00H ;记载多个守时时刻MOV 29H,#00HMOV 2AH,#00HMOV 2BH,#00HMOV 2CH,#00HMOV 2DH,#00H MOV 2EH,#00H MOV 2FH,#00HMOV 48H,#55H ;暂停/持续功用MOV 4AH,#55H ;显现切换功用,显现当时时刻/秒表守时时刻MOV 4BH,#55H ;闹钟开关转化功用MOV 4CH,#55H ;计分器挑选功用,调整甲乙中一方的分数MOV 49H,#0 ;计数器中止挑选功用,为#1时履行秒表程序,#2时履行守时程序MOV 3AH,#0 ;存储秒表时刻的出进口资源MOV 3BH,#0 ;同3AHMOV 3CH,#0 ;存储守时的出进口资源MOV 3DH,#0 ;;挑选守时/秒表的出进口资源。为0时能够选其一,为1时不能挑选MOV 3EH,#0 ;整点报时出进口资源,为1时封闭音乐MOV NO_OUT,#0H ;红外遥控终究操控号码寄存单元清0MOV R0,#80H ;存储秒表瞬间时刻的区域,D0~D8是存储闹钟资源BACK_1: MOV @R0,#0BHINC R0CJNE R0,#0D0H,BACK_1CLR P3.6 ;秒表状况CLR P3.7 ;守时状况SETB 20H.4MOV R2,#9H ;一次最多只能按8次MOV R1,#30HMOV R5,#1MOV R4,#0MOV TMOD , #99H MOV TL1 ,#00H MOV TH1 ,#0DCH SETB ET1 ;答应守时器1中止SETB EX1 ;开外部中止SETB IT1 ;挑选边缘触发方法SETB EASETB PT0SETB PT1SETB PX0 MAIN1:ACALL KEYBOARD ;扫描键盘 ACALL DISPLAY ;显现程序ACALL RING ;整点报时 ACALL ALARMCLOCK ;闹钟程序ACALL TELECONTROL ;红外遥控模块MOV A,49H ;只要挑选了守时程序时才扫描Buzzer程序CJNE A,#02H,MAIN1ACALL BUZZER ;调用蜂鸣器程序;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 ;挑选了秒表之后就不能再挑选守时SETB P3.6 ;P3.6为秒表的状况灯MOV R0,#80H ;存储秒表瞬间时刻的区域悉数显现0MOV TMOD , #99H MOV TL0 , #00H MOV TH0 , #0DCH SETB EX0 ;开外部中止SETB IT0 ;挑选边缘触发方法SETB ET0 ;开计数器中止MOV 49H, #1HSETB EA ;开总中止TIMEOVER:RET;********************;守时程序;********************STOPWATCH: MOV A,3DHCJNE A,#0,STOPOVERMOV R1,#40HMOV R2,#9H ;一次最多只能按8次MOV 39H,#0MOV 3AH,#10MOV 3DH,#1 ;挑选了守时之后就不能再挑选秒表MOV 40H,#0AH ;初始化显现时刻,悉数显现"_"MOV 41H,#0AHMOV 42H,#0AHMOV 43H,#0AHMOV 44H,#0AHMOV 45H,#0AH MOV 46H,#0AH MOV 47H,#0AH SETB P3.7 ;P3.7为守时的状况灯MOV TMOD , #99H MOV TL0 ,#00H MOV TH0 ,#0DCH SETB EX0 ;开外部中止SETB IT0 ;挑选边缘触发方法SETB ET0 ;开外部中止MOV 49H, #2HSETB EA ;开总中止STOPOVER:RET;********************** ;扫描键盘 ;********************** KEYBOARD:CJNE R5,#1,NOKEYLJMP READ_KEYNOKEY: DJNZ R5, KEYOUT KEYOUT: RETREAD_KEY: ;按键扫描函数MOV P_KEY,#0ffHMOV P_KEY,#0f0HMOV A,P_KEY;判别是否有键按下cjne A,#0f0H,RK1AJMP NO_KEY;有按键按下,延时去抖RK1: CALL delAy_time ;延时5ms 还没有写出来MOV P_KEY,#0f0HMOV A,P_KEY;承认是否有键按下CJNE A,#0f0H,RK2AJMP NO_KEY;承认是有按键按下, 判别哪行按键按下RK2:JNB ACC.4,RK4JNB ACC.5,RK5JNB ACC.6,RK6JNB ACC.7,RK7;没有检测到按键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;没有检测到按键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;回来检测到的按键编号GET_KEY: CLR 20H.4ADD A,BLJMP IFKEY;没检测到按键,回来0xffNO_KEY:MOV A,#0HIFKEY: JNB 20H.4,KEY_0 ;假如20H.4为0时证明有键按下LJMP KEY_1 ;不然跳出KEY_0: DJNZ R2, KEY_2 ; 当R2不为0时,运转8次,直到显现的8位都给定初值 MOV R2, #1H ;运转8次后TIAO_2后的程序不再运转,内存不再赋值CLR ASETB 20H.4RETKEY_2: MOV @R1,AINC R1MOV R5, #70KEY_1: CLR ASETB 20H.4RET;//******************时刻延迟函数DELAY_TIME: ;延时10msPUSH PSWPUSH ACC LOOP: MOV R7,#100 LOOP_1: MOV R6,#50 LOOP_2: DJNZ R6,LOOP_2DJNZ R7,LOOP_1POP ACCPOP PSWRET;****************************;显现所记载的秒表瞬间/守时的时刻;****************************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;***********************;守时/秒表清零;*&*********************CLEAR:MOV R5,#60SETB BUZZ CLR TR0MOV R1,#40HMOV R2,#9H ;按键后 MOV 3AH,#0MOV 3BH,#0MOV 3DH,#0 MOV 39H,#5MOV 48H,#55H ;暂停/持续功用MOV 49H,#0 ;计数器中止挑选功用,为#1时履行秒表程序,#2时履行守时程序MOV 40H,#00H ;记载译码后的显现时刻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为计分器的存储地址,其初始化为; 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 ;开外部中止CLR P3.1CLR P3.5CLR P3.6CLR P3.7CLEAR_1: RET ;************************************;检查当时时刻/守时秒表当时时刻/关音乐;************************************CHANGE_DIS:MOV R5,#60SETB ET1SETB TR1 SETB BUZZMOV A,4AH ; RL A MOV 4AH,AJNB ACC.1,CHANGE_1 ;查询,A最低位为0时暂停计时,为1时持续计时 MOV 39H,#5 LJMP CHANGE_2CHANGE_1: MOV 39H,#0CHANGE_2: RET ;*****************************;挑选程序:存储秒表瞬间/多个守时;*****************************SAVE_T_S: MOV R5,#60MOV A,49H JB ACC.0,SAVETIMEJB ACC.1,SAVESTOPLJMP STOPOUT;****************************;存储十个守时时刻;****************************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