超强多功能电子钟程序
时间:11-29
来源:互联网
点击:
;*****************************************************************************
;实现功能:定时功能,参数是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 ;************************;秒表存储功能;************************SAVETIME: MOV R4,3AHMOV A, 3BHCJNE A,#0AH,SAVEMIDRETSAVEMID: INC R4MOV 3AH,R4MOV 3BH,R4CJNE R4,#01H,SAVE1MOV R0,#80HLJMP SAVE10SAVE1: CJNE R4,#02H,SAVE2MOV R0,#88HLJMP SAVE10SAVE2: CJNE R4,#03H,SAVE3MOV R0,#90HLJMP SAVE10SAVE3: CJNE R4,#04H,SAVE4MOV R0,#98HLJMP SAVE10SAVE4: CJNE R4,#05H,SAVE5MOV R0,#0A0HLJMP SAVE10SAVE5: CJNE R4,#06H,SAVE6MOV R0,#0A8HLJMP SAVE10SAVE6: CJNE R4,#07H,SAVE7MOV R0,#0B0HLJMP SAVE10SAVE7: CJNE R4,#08H,SAVE8MOV R0,#0B8HLJMP SAVE10SAVE8: CJNE R4,#09H,SAVE9MOV R0,#0C0HLJMP SAVE10SAVE9: CJNE R4,#0AH,SAVE10MOV R0,#0C8HSAVE10: MOV @R0,40HINC R0MOV @R0,41HINC R0MOV @R0,42HINC R0MOV @R0,43HINC R0MOV @R0,44HINC R0MOV @R0,45HINC R0MOV @R0,46HINC R0MOV @R0,47HRET;****************************;蜂鸣器程序,查询是否全部为0;***************************BUZZER: PUSH ACCPUSH BPUSH PSWMOV R4,#00HMOV R6,#7FHBUZZTURN: MOV A,#8HADD A,R6MOV R0,AMOV R6,AMOV A,@R0 CJNE A,NUMBER_H2,BUZZER_1DEC R0MOV A,@R0 CJNE A,NUMBER_G2,BUZZER_1DEC R0MOV A,@R0 CJNE A,NUMBER_F2,BUZZER_1DEC R0MOV A,@R0 CJNE A,NUMBER_E2,BUZZER_1DEC R0MOV A,@R0 CJNE A,NUMBER_D2,BUZZER_1DEC R0MOV A,@R0 CJNE A,NUMBER_C2,BUZZER_1DEC R0MOV A,@R0 CJNE A,NUMBER_B2,BUZZER_1DEC R0MOV A,@R0 CJNE A,NUMBER_A2,BUZZER_1 MOV 3AH,R4CLR BUZZMOV 39H,#1BUZZER_1: INC R4CJNE R4,#0AH,BUZZTURNBUZZER_2:MOV A,NUMBER_A ;时十位CJNE A,#0H,RETURN3MOV A,NUMBER_B ;时个位CJNE A,#0H,RETURN3MOV A,NUMBER_C ;分十位CJNE A,#0H,RETURN3MOV A,NUMBER_D ;分个位CJNE A,#0H,RETURN3MOV A,NUMBER_E ;秒十位CJNE A,#0H,RETURN3MOV A,NUMBER_F ;秒个位CJNE A,#0H,RETURN3MOV A,NUMBER_G ;秒十分位CJNE A,#0H,RETURN3MOV A,NUMBER_H ;秒百分位CJNE A,#0H,RETURN3CLR BUZZ ;开蜂鸣器CLR TR0 ;关计数器0CLR EX0 ;关外部中断0 MOV 39H,#0 CLR P3.7POP PSWPOP BPOP ACCHERE: LJMP MAIN0 RETURN3:POP PSWPOP BPOP ACCRET ;**********************************;整点报时;**********************************RING: PUSH ACCPUSH BPUSH PSWMOV A,NUMBER_C6 ;分十位CJNE A,#0H,RINGOUTMOV A,NUMBER_D6 ;分个位CJNE A,#0H,RINGOUTMOV A,NUMBER_E6 ;秒十位CJNE A,#0H,RINGOUTMOV A,NUMBER_F6 ;秒个位CJNE A,#0H,RINGOUTMOV A,NUMBER_G6 ;秒十分位CJNE A,#0H,RINGOUTMOV A,NUMBER_H6 ;秒百分位CJNE A,#0H,RINGOUTCLR BUZZMOV 3EH, #1RINGOUT: MOV A,3EHCJNE A,#1,RING_OUTMOV A,NUMBER_E6 ;秒十位CJNE A,#1H,RING_OUTSETB BUZZMOV 3EH, #0RING_OUT:POP PSWPOP BPOP ACCRET;**********************************;闹钟程序;**********************************ALARMCLOCK:PUSH ACCPUSH BPUSH PSW;SETB 20H.1JNB 20H.1,ALARM_OUT1 ;启动闹钟标志位0关,1开MOV R0,#0D0HMOV A,@R0 ;时十位CJNE A,NUMBER_A6,ALARM_OUTMOV R0,#0D1HMOV A,@R0 ;时个位CJNE A,NUMBER_B6,ALARM_OUTMOV R0,#0D2HMOV A,@R0 ;分十位CJNE A,NUMBER_C6,ALARM_OUTMOV R0,#0D3HMOV A,@R0 ;分个位CJNE A,NUMBER_D6,ALARM_OUTMOV R0,#0D4HMOV A,@R0 ;秒十位CJNE A,NUMBER_E6,ALARM_OUTMOV R0,#0D5HMOV A,@R0 ;秒个位CJNE A,NUMBER_F6,ALARM_OUTMOV R0,#0D6HMOV A,@R0 ;秒十分位CJNE A,NUMBER_G6,ALARM_OUTMOV R0,#0D7HMOV A,@R0 ;秒百分位CJNE A,NUMBER_H6,ALARM_OUTCLR BUZZSETB 20H.2ALARM_OUT:JNB 20H.2,ALARM_OUT1 ;关闹钟铃声标志MOV R0,#0D3H ;分个位MOV A,@R0INC ACJNE A,NUMBER_D6,ALARM_OUT1MOV R0,#0D4HMOV A,@R0 ;秒十位CJNE A,NUMBER_E6,ALARM_OUT1MOV R0,#0D5HMOV A,@R0 ;秒个位CJNE A,NUMBER_F6,ALARM_OUT1MOV R0,#0D6HMOV A,@R0 ;秒十分位CJNE A,NUMBER_G6,ALARM_OUT1MOV R0,#0D7HMOV A,@R0 ;秒百分位CJNE A,NUMBER_H6,ALARM_OUT1SETB BUZZCLR 20H.2 ;关闹钟铃声标志ALARM_OUT1:POP PSWPOP BPOP ACCRET;**********************************;闹钟赋初值程序;**********************************ALARMC: PUSH ACCPUSH BPUSH PSWJB 20H.0,ALARMCOUT ;判断是否可以改变定时的时间,0可以,1不可以MOV R2,#09HMOV R1,#0D0HSETB 20H.0 ;判断是否可以改变定时的时间,0可以,1不可以ALARMCOUT:POP PSWPOP BPOP ACCRET;**********************************;更改闹钟时间程序;**********************************ACKCHANGE:PUSH ACCPUSH BPUSH PSWMOV R2,#09HMOV R1,#0D0HMOV R0,#0D0HBACK_2: MOV @R0,#0AH ;D0~D8是存储闹钟空间,只能在初始化时清0INC R0CJNE R0,#0D8H,BACK_2;CLR 20H.0POP PSWPOP BPOP ACCRET;**********************************;启动/关闭闹钟;**********************************ACKSTART: PUSH ACCPUSH BPUSH PSWMOV A,4BH ; RL A MOV 4BH,AJNB ACC.1,ACK_OUT ;查询,A最低位为0时暂停计时,为1继续计时SETB 20H.1 ;启动闹钟标志位0关,1开SETB P3.4LJMP ACKOUTACK_OUT: CLR 20H.1 ;启动闹钟标志位0关,1开CLR P3.4ACKOUT: POP PSWPOP BPOP ACCRET;**********************************;显示程序;**********************************DISPLAY: PUSH ACCPUSH BPUSH PSWMOV R3,#0FEHMOV A,39HCJNE A,#5,YU_0MOV R0,#37HLJMP DISPLAY_AYU_0: CJNE A,#1,YU_1MOV R4,3AHINC R4CJNE R4,#01H,SAVE_1MOV R0,#87HLJMP DISPLAY_ASAVE_1: CJNE R4,#02H,SAVE_2MOV R0,#8FHLJMP DISPLAY_ASAVE_2: CJNE R4,#03H,SAVE_3MOV R0,#97HLJMP DISPLAY_ASAVE_3: CJNE R4,#04H,SAVE_4MOV R0,#9FHLJMP DISPLAY_ASAVE_4: CJNE R4,#05H,SAVE_5MOV R0,#0A7HLJMP DISPLAY_ASAVE_5: CJNE R4,#06H,SAVE_6MOV R0,#0AFHLJMP DISPLAY_ASAVE_6: CJNE R4,#07H,SAVE_7MOV R0,#0B7HLJMP DISPLAY_ASAVE_7: CJNE R4,#08H,SAVE_8MOV R0,#0BFHLJMP DISPLAY_ASAVE_8: CJNE R4,#09H,SAVE_9MOV R0,#0C7HLJMP DISPLAY_ASAVE_9: CJNE R4,#0AH,YU_1MOV R0,#0CFH ;动态显示初始化,使r0指向缓冲区首地址LJMP DISPLAY_AYU_1: CJNE A,#2,YU_2MOV R0,#0D7HLJMP DISPLAY_AYU_2: CJNE A,#3,YU_3MOV R0,#0DFHLJMP DISPLAY_AYU_3: CJNE A,#4,YU_4MOV R0,#0EFHLJMP DISPLAY_AYU_4: MOV R0,#47HDISPLAY_A:MOV DPTR,#TABLEMOV A,@R0MOVC A,@A+DPTR MOV P2,R3 MOV P0,A ACALL DELAYDISDEC R0MOV A,R3JNB ACC.7,LD1RL AMOV R3,ALJMP DISPLAY_ALD1: POP PSWPOP BPOP ACCRET; *********************;查表程序;*********************TABLE: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H,0F7H,0FEH,0BFH,0FFH; 0 1 2 3 4 5 6 7 8 9 A B C DRET DELAYDIS: MOV R7,#250 ;04HDELDIS: DJNZ R7,DELDISRET;************************************;计分器选择程序A/B;************************************SCOREAB: PUSH ACCPUSH BPUSH PSWMOV A,4CH ; RL A MOV 4CH,AJNB ACC.1,SCO_B ;查询,调整分数SETB 20H.3SETB P3.1CLR P3.7 ;计分器标志位,甲A调整LJMP SCOOUT SCO_B:CLR 20H.3 ;计分器标志位,乙B调整SETB P3.7CLR P3.1SCOOUT: POP PSWPOP BPOP ACCRET;************************************;计分器分数调整:加1;************************************SCOREINC: PUSH ACCPUSH BPUSH PSWJNB 20H.3,INCB ;计分器标志位,0时乙B调整MOV R0,#0DAH ;1时甲A乙B调整LJMP SCOMID_0INCB: MOV R0,#0DFHSCOMID_0: MOV A,@R0INC AMOV @R0,ACJNE A,#0AH,INCAB_0MOV A,#0MOV @R0,ADEC R0MOV A,@R0CJNE A,#0DH,SCOYUMOV A,#0SCOYU: INC AMOV @R0,ACJNE A,#0AH,INCAB_0MOV A,#0MOV @R0,ADEC R0MOV A,@R0CJNE A,#0DH,SCOWEIMOV A,#0SCOWEI: INC AMOV @R0,AINCAB_0: POP PSWPOP BPOP ACCRET;************************************;计分器分数调整:减1;************************************SCOREDEC: PUSH ACCPUSH BPUSH PSWSETB PSW.3CLR PSW.4JNB 20H.3,DECB ;计分器标志位,0时乙B调整MOV R0,#0DAH ;1时甲A乙B调整LJMP SCOMID_1DECB: MOV R0,#0DFH ;个位SCOMID_1: MOV A,@R0DEC AMOV @R0,ACJNE A,#0FFH,DECAB_5MOV R1,#0DEHMOV A,@R1CJNE A,#00H,DECABPENGMOV R1,#0DDHMOV A,@R1CJNE A,#0DH,DECAB_1MOV A,#0MOV @R0,ALJMP DECAB_5DECABPENG:CJNE A,#0DH,DECAB_1MOV A,#0MOV @R0,ALJMP DECAB_5LJMP DECAB_2 DECAB_1: MOV A,#9DECAB_2: MOV @R0,ADEC R0 ;十位MOV A,@R0DEC AMOV @R0,ACJNE A,#0FFH,DECAB_6MOV R1,#0DDHMOV A,@R1CJNE A,#00H,DECAB_YUMOV A,#0DHMOV @R0,ALJMP DECAB_5DECAB_6: CJNE A,#00H,DECAB_5MOV R1,#0DDHMOV A,@R1CJNE A,#0DH,DECAB_YUMOV A,#0DHMOV @R0,ALJMP DECAB_5DECAB_YU: CJNE A,#0DH,DECAB_3MOV A,#0DHLJMP DECAB_4DECAB_3: MOV A,#9DECAB_4: MOV @R0,ADEC R0 ;百位MOV A,@R0DEC AMOV @R0,ACJNE A,#00H,DECAB_5MOV A,#0DHMOV @R0,ADECAB_5: CLR PSW.3CLR PSW.4POP PSWPOP BPOP ACCRET ;*************************************;红外遥控模块;*************************************;// 8 192 128 96;//144 184 248 176;//152 216 136 168;//232 72 104 50;// 2 18 32 0;// 64 160 42 178;// 80 120 112 88 ;// 56 40 240 48TELECONTROL:CJNE R5,#1,NOCHLJMP CHINNOCH: DJNZ R5, CHOUT_0CHIN: MOV R4,NO_OUT CJNE R4,#0,CH0CHOUT_0:LJMP CHOUTCH0: ;0 码型 CJNE R4,#216,CH1MOV A,#0MOV NO_OUT,#0H ;红外遥控最终控制号码存放单元清0LJMP KEY_0CH1: ;1 码型 CJNE R4,#8,CH2MOV A,#1MOV NO_OUT,#0H ;红外遥控最终控制号码存放单元清0LJMP KEY_0CH2: ;2码型 CJNE R4,#192,CH3MOV A,#2MOV NO_OUT,#0H ;红外遥控最终控制号码存放单元清0LJMP KEY_0CH3: ;3 码型 CJNE R4,#128,CH4MOV A,#3MOV NO_OUT,#0H ;红外遥控最终控制号码存放单元清0LJMP KEY_0CH4: ;4 码型 CJNE R4,#96,CH5MOV A,#4MOV NO_OUT,#0H ;红外遥控最终控制号码存放单元清0LJMP KEY_0CH5: ;5 码型 CJNE R4,#144,CH6MOV A,#5MOV NO_OUT,#0H ;红外遥控最终控制号码存放单元清0LJMP KEY_0CH6: ;6 码型 CJNE R4,#184,CH7MOV A,#6MOV NO_OUT,#0H ;红外遥控最终控制号码存放单元清0LJMP KEY_0CH7: ;7 码型 CJNE R4,#248,CH8MOV A,#7MOV NO_OUT,#0H ;红外遥控最终控制号码存放单元清0LJMP KEY_0CH8: ;8 码型 CJNE R4,#176,CH9MOV A,#8MOV NO_OUT,#0H ;红外遥控最终控制号码存放单元清0LJMP KEY_0CH9: ;9 码型 CJNE R4,#152,CHKEYAMOV A,#9MOV NO_OUT,#0H ;红外遥控最终控制号码存放单元清0LJMP KEY_0CHKEYA: ;A 码型 CJNE R4,#136,CHKEYBMOV NO_OUT,#0H ;红外遥控最终控制号码存放单元清0LJMP TIMECHKEYB: ;B 码型 CJNE R4,#168,CHSAVEMOV NO_OUT,#0H ;红外遥控最终控制号码存放单元清0LJMP STOPWATCHCHSAVE: ;C 码型 CJNE R4,#232,CHDISMOV NO_OUT,#0H ;红外遥控最终控制号码存放单元清0LJMP SAVE_T_SCHDIS: ;D 码型 CJNE R4,#72,CHCHNMOV NO_OUT,#0H ;红外遥控最终控制号码存放单元清0LJMP DISPLAY_T_SCHCHN: ;E 码型 CJNE R4,#104,CHCLRMOV NO_OUT,#0H ;红外遥控最终控制号码存放单元清0LJMP CHANGE_DISCHCLR: ;F 码型 CJNE R4,#50,CHINTMOV NO_OUT,#0H ;红外遥控最终控制号码存放单元清0LJMP CLEARCHINT: ;G 码型 CJNE R4,#2, CHACK ;ALARM CLOCKMOV NO_OUT,#0H ;红外遥控最终控制号码存放单元清0CLR P3.2SETB P3.2CHACK:CJNE R4,#18, CHACKC ;ALARM CLOCK CHANGEMOV NO_OUT,#0H ;红外遥控最终控制号码存放单元清0MOV 39H,#2LJMP ALARMCCHACKC:CJNE R4,#32, CHACKST ;ALARM CLOCK STARTMOV NO_OUT,#0H ;红外遥控最终控制号码存放单元清0MOV 39H,#2LJMP ACKCHANGECHACKST:CJNE R4,#0, CHSCOREDISMOV NO_OUT,#0H ;红外遥控最终控制号码存放单元清0LJMP ACKSTARTCHSCOREDIS:CJNE R4,#64, CHSCOREABMOV NO_OUT,#0H ;红外遥控最终控制号码存放单元清0MOV 39H,#3LJMP CHOUTCHSCOREAB:CJNE R4,#160, CHSCOREINCMOV NO_OUT,#0H ;红外遥控最终控制号码存放单元清0LJMP SCOREABCHSCOREINC:CJNE R4,#42, CHSCOREDECMOV NO_OUT,#0H ;红外遥控最终控制号码存放单元清0LJMP SCOREINCCHSCOREDEC:CJNE R4,#178, CHDIANMOV NO_OUT,#0H ;红外遥控最终控制号码存放单元清0LJMP SCOREDECCHDIAN:CJNE R4,#48, CHOUTMOV NO_OUT,#0H ;红外遥控最终控制号码存放单元清0MOV R0,#0E7H BACK_DIAN:MOV @R0,#0DH INC R0CJNE R0,#0F0H,BACK_DIANMOV 39H,#4CHOUT: RET;*********************;时钟外部中断程序;*********************INTOUT1:PUSH ACCPUSH PSW MOV PSW,#18HCLR EX1 MOV R4,#10SB: LCALL DL865 JB P3.3,EXIT DJNZ R4, SB JNB P3.3, $ LCALL DL4737 MOV R5,#16 JJJJA: JNB P3.3,$ LCALL DL865 MOV C,P3.3 JNC UUUALCALL DL1000 UUUA: DJNZ R5,JJJJAMOV R1,#22H MOV R2,#2 PP: MOV R3,#8 JJJJ: JNB P3.3,$ LCALL DL865 MOV C,P3.3 JNC UUULCALL DL1000 UUU: MOV A,@R1RLC A MOV @R1,A DJNZ R3,JJJJ INC R1DJNZ R2,PP MOV A,22HCPL A CJNE A,23H,EXIT MOV A,22HMOV NO_OUT,AEXIT: SETB EX1;MOV 3DH,#40CLR PSW.3CLR PSW.4POP PSWPOP ACC RETI ;**********************<延时程序>>******************************;本程序完整版的下载地址:http://www.51hei.com/ziliao/file/dgndzz.rarDL865: MOV R7,#12 ; 1.09*(2R6+4)*R7+2 延时子程序1,精确延时865 微秒D1: MOV R6,#31DJNZ R6,$DJNZ R7,D1RETDL4737: MOV R7,#12 ;延时子程序2,精确延时4737 微秒D2: MOV R6,#179DJNZ R6,$DJNZ R7,D2RETDL1000: MOV R7,#17;延时程序3,精确延时1000 微秒D3: MOV R6,#25DJNZ R6,$DJNZ R7,D3RETDL40: MOV R7,#1;延时程序4,精确延时40/17 微秒D4: MOV R6,#1DJNZ R6,$DJNZ R7,D4RET ;*************************;秒表、定时器外部中断程序;**************************INTOUT0: PUSH ACCPUSH BPUSH PSW CLR TR0 ;停止计数MOV 39H,#0MOV A,48H ; RL A MOV 48H,AJNB ACC.1,OUT0 ;查询,A最低位为0时暂停计时,为1时继续计时MOV TH0,#0DCH ;#0FFHMOV TL0,#00H ;#00HSETB TR0 ;开始计数 OUT0: POP PSWPOP BPOP ACCRETI ;***************************; 时钟溢出中断程序;***************************COUNT1: PUSH ACCPUSH BPUSH PSW MOV TL1 ,#00H MOV TH1 ,#0DCH MOV A,NUMBER_H6 ;秒百分位INC AMOV NUMBER_H6,ACJNE A,#0AH,RETURN_1MOV NUMBER_H6,#00HMOV A,NUMBER_G6 ;秒十分位INC AMOV NUMBER_G6,ACJNE A,#0AH,RETURN_1MOV NUMBER_G6,#00HMOV A,NUMBER_F6 ;秒个位INC AMOV NUMBER_F6,ACJNE A,#0AH,RETURN_1MOV NUMBER_F6,#00HMOV A,NUMBER_E6 ;秒十位INC AMOV NUMBER_E6,ACJNE A,#06H,RETURN_1MOV NUMBER_E6,#00HMOV A,NUMBER_D6 ;分个位INC AMOV NUMBER_D6,ACJNE A,#0AH,RETURN_1MOV NUMBER_D6,#00HMOV A,NUMBER_C6 ;分十位INC AMOV NUMBER_C6,ACJNE A,#06H,RETURN_1MOV NUMBER_C6,#00HMOV A,NUMBER_A6CJNE A,#02H,GO_ON_1MOV A,NUMBER_B6 INC AMOV NUMBER_B6,ACJNE A,#04H,RETURN_1MOV NUMBER_B6,#00HMOV NUMBER_A6,#00HLJMP RETURN_1GO_ON_1: MOV A,NUMBER_B6 ;时个位INC AMOV NUMBER_B6,ACJNE A,#0AH,RETURN_1MOV NUMBER_B6,#00HMOV A,NUMBER_A6 ;时个位和时十位一同设置INC AMOV NUMBER_A6,ARETURN_1:POP PSWPOP BPOP ACCRETI ;散转;***************************; 秒表溢出中断程序;***************************COUNT0: PUSH ACCPUSH BPUSH PSW MOV TL0 ,#00H MOV TH0 ,#0DCH MOV A, 49HJB ACC.0,TIMER0JB ACC.1,PENGLJMP RETURN_0PENG: LJMP STOP_00TIMER0:MOV A,NUMBER_H ;秒百分位INC AMOV NUMBER_H,ACJNE A,#0AH,RETURN_0MOV NUMBER_H,#00HMOV A,NUMBER_G ;秒十分位INC AMOV NUMBER_G,ACJNE A,#0AH,RETURN_0MOV NUMBER_G,#00H;MOV A,NUMBER_F ;秒个位INC AMOV NUMBER_F,ACJNE A,#0AH,RETURN_0MOV NUMBER_F,#00H;MOV A,NUMBER_E ;秒十位INC AMOV NUMBER_E,ACJNE A,#06H,RETURN_0MOV NUMBER_E,#00HMOV A,NUMBER_D ;分个位INC AMOV NUMBER_D,ACJNE A,#0AH,RETURN_0MOV NUMBER_D,#00HMOV A,NUMBER_C ;分十位INC AMOV NUMBER_C,ACJNE A,#06H,RETURN_0MOV NUMBER_C,#00HMOV A,NUMBER_ACJNE A,#02H,GO_ON_0MOV A,NUMBER_B INC AMOV NUMBER_B,ACJNE A,#04H,RETURN_0MOV NUMBER_B,#00HMOV NUMBER_A,#00HLJMP RETURN_0GO_ON_0: MOV A,NUMBER_B ;时个位INC AMOV NUMBER_B,ACJNE A,#0AH,RETURN_0MOV NUMBER_B,#00H;MOV A,NUMBER_A ;时个位和时十位一同设置INC AMOV NUMBER_A,ARETURN_0:POP PSWPOP BPOP ACCRETI ;散转;**************************;定时器计时中断入口;****************************STOP_00:MOV A,NUMBER_H ;0.01秒位DEC AMOV NUMBER_H,ACJNE A,#0FFH,RETURN_00MOV A,NUMBER_ACJNE A,#0,REL_HMOV A,NUMBER_BCJNE A,#0,REL_HMOV A,NUMBER_CCJNE A,#0,REL_HMOV A,NUMBER_DCJNE A,#0,REL_HMOV A,NUMBER_ECJNE A,#0,REL_HMOV A,NUMBER_FCJNE A,#0,REL_HMOV A,NUMBER_GCJNE A,#0,REL_HMOV NUMBER_H,#00H LJMP RETURN_00 REL_H: MOV NUMBER_H,#09HLJMP WEI_GRETURN_00:LJMP RETURN_02WEI_G: MOV A,NUMBER_G ;0.1秒位DEC AMOV NUMBER_G,ACJNE A,#0FFH,RETURN_01MOV A,NUMBER_ACJNE A,#0,REL_GMOV A,NUMBER_BCJNE A,#0,REL_GMOV A,NUMBER_CCJNE A,#0,REL_GMOV A,NUMBER_DCJNE A,#0,REL_GMOV A,NUMBER_ECJNE A,#0,REL_GMOV A,NUMBER_FCJNE A,#0,REL_GMOV NUMBER_G,#00H LJMP RETURN_01 REL_G: MOV NUMBER_G,#09H;WEI_F: MOV A,NUMBER_F ;秒个位DEC AMOV NUMBER_F,ACJNE A,#0FFH,RETURN_01MOV A,NUMBER_ACJNE A,#0,REL_FMOV A,NUMBER_BCJNE A,#0,REL_FMOV A,NUMBER_CCJNE A,#0,REL_FMOV A,NUMBER_DCJNE A,#0,REL_FMOV A,NUMBER_ECJNE A,#0,REL_FMOV NUMBER_F,#00H AJMP RETURN_01 REL_F: MOV NUMBER_F,#09HAJMP WEI_ERETURN_01:LJMP RETURN_02; WEI_E: MOV A,NUMBER_E ;秒十位DEC AMOV NUMBER_E,ACJNE A,#0FFH,RETURN_02MOV A,NUMBER_ACJNE A,#0,REL_EMOV A,NUMBER_BCJNE A,#0,REL_EMOV A,NUMBER_CCJNE A,#0,REL_EMOV A,NUMBER_DCJNE A,#0,REL_EMOV NUMBER_E,#00H LJMP RETURN_02 REL_E: MOV NUMBER_E,#05H;WEI_D: MOV A,NUMBER_D ;分个位DEC AMOV NUMBER_D,ACJNE A,#0FFH,RETURN_02MOV A,NUMBER_ACJNE A,#0,REL_DMOV A,NUMBER_BCJNE A,#0,REL_DMOV A,NUMBER_CCJNE A,#0,REL_DMOV NUMBER_D,#00H LJMP RETURN_02 REL_D: MOV NUMBER_D,#09H;WEI_C: MOV A,NUMBER_C ;分十位DEC AMOV NUMBER_C,ACJNE A,#0FFH,RETURN_02MOV A,NUMBER_ACJNE A,#0,REL_CMOV A,NUMBER_BCJNE A,#0,REL_CMOV NUMBER_C,#00H LJMP RETURN_02 REL_C: MOV NUMBER_C,#05H;WEI_B: MOV A,NUMBER_B ;时个位DEC AMOV NUMBER_B,ACJNE A,#0FFH,RETURN_02MOV A,NUMBER_ACJNE A,#0,REL_BMOV NUMBER_B,#00H LJMP RETURN_02 REL_B: MOV NUMBER_B,#09H;WEI_A: MOV A,NUMBER_A ;时个位和时十位一同设置DEC AMOV NUMBER_A,ACJNE A,#0FFH,RETURN_02MOV NUMBER_A,#00HRETURN_02:MOV A,NUMBER_H2 ;秒百分位INC AMOV NUMBER_H2,ACJNE A,#0AH,RETURN_22MOV NUMBER_H2,#00H;MOV A,NUMBER_G2 ;秒十分位INC AMOV NUMBER_G2,ACJNE A,#0AH,RETURN_22MOV NUMBER_G2,#00H;MOV A,NUMBER_F2 ;秒个位INC AMOV NUMBER_F2,ACJNE A,#0AH,RETURN_22MOV NUMBER_F2,#00H;MOV A,NUMBER_E2 ;秒十位INC AMOV NUMBER_E2,ACJNE A,#06H,RETURN_22MOV NUMBER_E2,#00HMOV A,NUMBER_D2 ;分个位INC AMOV NUMBER_D2,ACJNE A,#0AH,RETURN_22MOV NUMBER_D2,#00HMOV A,NUMBER_C2 ;分十位INC AMOV NUMBER_C2,ACJNE A,#06H,RETURN_22MOV NUMBER_C2,#00HMOV A,NUMBER_A2CJNE A,#02H,GO_ON_22MOV A,NUMBER_B2INC AMOV NUMBER_B2,ACJNE A,#04H,RETURN_22MOV NUMBER_B2,#00HMOV NUMBER_A2,#00HLJMP RETURN_0GO_ON_22: MOV A,NUMBER_B2 ;时个位INC AMOV NUMBER_B2,ACJNE A,#0AH,RETURN_22MOV NUMBER_B2,#00H;MOV A,NUMBER_A2 ;时个位和时十位一同设置INC AMOV NUMBER_A2,ARETURN_22:POP PSWPOP BPOP ACCRETI END
电子钟计分 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)