1、是 51 芯片。你参考看看!ORG 0000H ;程序入口地址AJMP STARTORG 000BH ;定时器 0 中断入口地址LJMP INT_0ORG 001BH ;定时器 1 中断入口地址LJMP INT_1 ORG 0100HSTART:LCALL QING ;初始化QING: ;初始化MOV 30H,#0 ;时十位寄存器清零MOV 31H,#0 ;时个位寄存器清零MOV 32H,#0 ;分十位寄存器清零MOV 33H,#0 ;分个位寄存器清零MOV 34H,#0 ;秒十位寄存器清零MOV 35H,#0 ;秒个位寄存器清零MOV 36H,#0 ;秒MOV 37H,#0 ;分MOV 38
2、H,#0 ;时MOV 39H,#20 MOV 40H,#0MOV 41H,#0MOV TMOD,#11HMOV TH0,#3CHMOV TL0,#0B0H ;赋初值,定时 50msMOV TH1,#09EHMOV TL1,#0D0HSETB TR0 ;开启定时器 0SETB TR1SETB EA ;开中断总开关SETB ET0 ;定时器 0 中断允许位SETB ET1SETB PT0CLR PT1MAIN:MOV P3,#0FFH ;开启按键JNB P3.3,KEY ;扫描按键AJMP MAINKEY:JNB P3.3,KEY ;控制时钟MOV 41H,#1CLR TR0 ;关“T0“中断LJ
3、MP KEY1DISPLAY: ;数码管MOV DPTR,#TABLEMOV P2,#80HMOV A,35H ; 显示秒个位MOVC A,A+DPTRMOV P0,AACALL DELAYMOV P2,#40HMOV A,34H ;显示秒十位MOVC A,A+DPTRMOV P0,AACALL DELAYMOV P2,#20H MOV A,33H ; 显示分个位MOVC A,A+DPTRMOV P0,AACALL DELAYMOV P2,#10H MOV A,32H ; 显示分十位MOVC A,A+DPTRMOV P0,AACALL DELAYMOV P2,#20H MOV P0,#7FH
4、;显示小数点ACALL DELAYJNB P3.2,LOOP ;转为” 时分“显示LJMP EXITLOOP:JNB P3.2,LOOPMOV 40H,#1AJMP EXITDELAY:MOV R3,#50 ;延时约为 50MSD0:MOV R2,#50DJNZ R2,$DJNZ R3,D0RETDISPLAY_1:MOV P2,#80HMOV A,33H ; 显示分个位MOVC A,A+DPTRMOV P0,AACALL DELAYMOV P2,#40HMOV A,32H ; 显示分十位MOVC A,A+DPTRMOV P0,AACALL DELAYMOV P2,#20HMOV A,31H
5、;显示时个位MOVC A,A+DPTRMOV P0,AACALL DELAYMOV P2,#10HMOV A,30H ; 显示时十位MOVC A,A+DPTRMOV P0,AACALL DELAYMOV P2,#20HMOV P0,#7FH ;显示小数点ACALL DELAYJNB P3.2,LOOP1 ;转为”分秒“显示LJMP EXITLOOP1:JNB P3.2,LOOP1MOV 40H,#0LJMP EXITK3:JNB P3.4,K3KEY3:JNB P3.5,K2_0 ;调整”时“JNB P3.3,SHI_0AJMP KEY3SHI_0:JNB P3.3,SHI_0SHI:JNB
6、P3.4,JIA_SHI ;”时“JNB P3.5,JIAN_SHIJNB P3.3,KEY0AJMP SHIJIA_SHI:JNB P3.4,JIA_SHI ; 加时INC 36HMOV R0,36HCJNE R0,#24,SHIMOV 36H,#0AJMP SHIJIAN_SHI:JNB P3.5,JIAN_SHI ; 减时DEC 36HMOV R0,36HCJNE R0,#-1,SHIMOV 36H,#23AJMP SHIKEY0: JNB P3.3,KEY0 ;转为时钟MOV 41H,#0MOV TH0,#3CHMOV TL0,#0B4HSETB TR0 ;开”T0” 中断AJMP M
7、AINK2: JNB P3.4,K2K2_0: JNB P3.5,K2_0KEY2: JNB P3.4,K3 ;调整” 分“JNB P3.5,K1JNB P3.3,F_0AJMP KEY2K1: JNB P3.5,K1KEY1: ;调整”秒“JNB P3.4,K2JNB P3.3,S_0AJMP KEY1S_0: JNB P3.3,S_0S: JNB P3.3,KEY0 ; ”秒“JNB P3.4,JIA_SJNB P3.5,JIAN_SAJMP SJIA_S:JNB P3.4,JIA_S ;加秒INC 38HMOV R0,38HCJNE R0,#61,SMOV 38H,#0AJMP SJIA
8、N_S:JNB P3.5,JIAN_S ;减秒DEC 38HMOV R0,38HCJNE R0,#-1,SMOV 38H,#59AJMP SF_0:JNB P3.3,F_0F: JNB P3.4,JIA_F ; ”分“JNB P3.5,JIAN_FJNB P3.3,KEY0AJMP FJIA_F:JNB P3.4,JIA_F ;加 ”分“INC 37HMOV R0,37HCJNE R0,#60,FMOV 37H,#0AJMP FJIAN_F:JNB P3.5,JIAN_F ;减 ”分“DEC 37HMOV R0,37HCJNE R0,#-1,FMOV 37H,#59AJMP FINT_0: ;
9、中断 0 初始化MOV TH0,#4BHMOV TL0,#0EAHDJNZ 39H,EXITMOV 39H,#20MOV A,41H ; 41H 控制是否计时CJNE A,#1,INT_01 INT_01:INC 38HMOV A,38HCJNE A,#60,EXITMOV 38H,#0INC 37HMOV A,37HCJNE A,#60,EXITMOV 37H,#0INC 36HMOV A,36HCJNE A,#24,EXITMOV 36H,#0INT_1:MOV TH1,#9EH ;定时 1 中断MOV TL1,#0D0HINT_13: ;数据转换 “时”“分”“秒”MOV A,36HMOV B,#10DIV ABMOV 30H,AMOV 31H,BMOV A,37HMOV B,#10DIV ABMOV 32H,AMOV 33H,BMOV A,38HMOV B,#10DIV ABMOV 34H,AMOV 35H,BACALL X1EXIT:RETIX1: MOV A,40H ;分秒转换CJNE A,#1,X2LJMP DISPLAY_1X2: LJMP DISPLAYRETTABLE: ;数据调用DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H ;字形显示编码END