//HJSMSY-V1.0單片機開發(fā)板測試程序//---------------------------------------------// 電腦鐘>>//---------------------------------------------//=======主函數(shù)==================================ORG 0000HLJMP MAINORG 000BHLJMP T00// ORG 001BH// LJMP T11ORG 0030H//=======程序初始化=============================MAIN:MOV TMOD,#11HMOV TH0,#3CHMOV TL0,#0B0HMOV TH1,#0F0HMOV TL1,#0B0HSETB EASETB ET0// SETB ET1SETB TR0// SETB TR1CLR P3.4 MOV R7,#00H ;秒值MOV 30H,#00H ;秒個位值MOV 31H,#00H ;秒十位值MOV 32H,#00H ;分個位MOV 33H,#00H ;分十位MOV 34H,#00H ;時個位MOV 35H,#00H ;時十位MOV 44H,#00H ;秒表毫秒十位MOV 45H,#00H ;秒表秒毫秒百位MOV 46H,#00H ;秒表秒個位MOV 47H,#00H ;秒表秒十位MOV 48H,#00H ;秒表分個位MOV 49H,#00H ;秒表分十位MOV P2,#0F0H ;P2口按鍵初始化MOV 40H,#01H ;數(shù)碼管休眠值 /流水燈/秒表開關數(shù)MOV 41H,#08H ;流水燈循環(huán)值MOV 42H,#00H ;秒表暫停// ACALL T11//----------------------------------------------- MAIN1: MOV P0,#0FFHMOV P1,#0FFHMOV R0,40HCJNE R0,#01H,ACL1ACALL MAIN2 ;時鐘顯示ACL1:CJNE R0,#02H,ACL2ACALL MAIN3 ;秒表ACL2:CJNE R0,#03H,ACL3ACALL LED ;流水燈ACL3:ACALL KEY ;按鍵掃描// ACALL BAO ;定時報警LJMP MAIN1//=======報警子程序============================BAO:MOV R4,33H CJNE R4,#03H,YY1CLR P3.2ACALL KEYLJMP YY2YY1:CJNE R4,#05H,YY2SETB P3.2 ACALL KEYYY2:RET//======時鐘掃描子程序=======================MAIN2:MOV A,30H MOV DPTR,#TABMOVC A,@A+DPTRMOV P0,ACLR P1.0ACALL DELAYMOV A,31HMOV DPTR,#TABMOVC A,@A+ DPTRMOV P0,ACLR P1.1SETB P1.0ACALL DELAYMOV A,32HMOV DPTR,#TABMOVC A,@A+DPTRMOV P0,ACLR P1.2SETB P1.1ACALL DELAYMOV A,33HMOV DPTR,#TABMOVC A,@A+DPTRMOV P0,ACLR P1.3SETB P1.2ACALL DELAYMOV A,34HMOV DPTR,#TABMOVC A,@A+DPTRMOV P0,ACLR P1.4SETB P1.3ACALL DELAYMOV A,35HMOV DPTR,#TABMOVC A,@A+DPTRMOV P0,ACLR P1.5SETB P1.4ACALL DELAY MOV P0,#7FH MOV P1,#0EBHACALL DELAYMOV P1,#0FFHRET//========秒表掃描子程序=========================MAIN3:MOV A,44H MOV DPTR,#TABMOVC A,@A+DPTRMOV P0,ACLR P1.0ACALL DELAYMOV A,45HMOV DPTR,#TABMOVC A,@A+ DPTRMOV P0,ACLR P1.1SETB P1.0ACALL DELAYMOV A,46HMOV DPTR,#TABMOVC A,@A+DPTRMOV P0,ACLR P1.2SETB P1.1ACALL DELAYMOV A,47HMOV DPTR,#TABMOVC A,@A+DPTRMOV P0,ACLR P1.3SETB P1.2ACALL DELAYMOV A,48HMOV DPTR,#TABMOVC A,@A+DPTRMOV P0,ACLR P1.4SETB P1.3ACALL DELAYMOV A,49HMOV DPTR,#TABMOVC A,@A+DPTRMOV P0,ACLR P1.5SETB P1.4ACALL DELAY MOV P0,#7FH MOV P1,#0EBHACALL DELAYMOV P1,#0FFHRET//=======定時器T0中斷服務========================T00:MOV TH0,#0D8HMOV TL0,#0F0HINC R7CJNE R7,#64H,AAMOV R7,#00H//-------時鐘跑值--------------------------------TK1:INC 30H ;每秒鐘秒個位增一MOV R6,30HCJNE R6,#0AH,AAMOV 30H,#00HTK2:INC 31HMOV R6,31HCJNE R6,#06H,AAMOV 31H,#00H TK3:INC 32H MOV R6,32HCJNE R6,#0AH,AAMOV 32H,#00HTK4:INC 33HMOV R6,33HCJNE R6,#06H,AAMOV 33H,#00HTK5:INC 34HMOV R5,34HMOV R6,35HCJNE R5,#04H,TK6CJNE R6,#02H,TK6MOV 34H,#00HMOV 35H,#00HTK6:CJNE R5,#0AH,AAMOV 34H,#00HINC 35H//-------秒表跑值----------------------AA:MOV R5,42HCJNE R5,#01H,TK7INC 44HTK7:MOV R5,44HCJNE R5,#0AH,AA1MOV 44H,#00HINC 45HMOV R5,45HCJNE R5,#0AH,AA1MOV 45H,#00HINC 46HMOV R5,46HCJNE R5,#0AH,AA1MOV 46H,#00HINC 47HMOV R5,47HCJNE R5,#06H,AA1MOV 47H,#00HINC 48HMOV R5,48HCJNE R5,#0AH,AA1MOV 48H,#00HINC 49HMOV R5,49HCJNE R5,#06H,AA1MOV 49H,#00HAA1:RETI//====定時器T1中斷服務子程序====================//T11:MOV TH1,#0F0H// MOV TL1,#0B0H// RETI//******定時時間調(diào)整子程序*************************//TBAO:MOV 50H,#00HMOV 51H,#00HMOV 52H,#00HMOV 53H,#00HMOV 54H,#00HMOV 55H,#00HMOV R3,50HDJNZ 30H,RET1RET1: RET//======鍵盤掃描子程序========================== KEY:MOV P2,#0F0HMOV R3,P2CJNE R3,#0F0H,KE0LJMP KK13KE0:CJNE R3,#0E0H,KE1 ;P2.4行MOV P2,#0EFHJB P2.3,KK1 //用作調(diào)定時時間 ;K13 秒個位增一ACALL DELAY1ACALL TK1KK1:JB P2.2,KK2 ;K14 秒十增一ACALL DELAY1ACALL TK2KK2:JB P2.1,KK3 ;K15 分個位增一ACALL DELAY1ACALL TK3KK3:JB P2.0,KE1 ;K16 分十位增一ACALL DELAY1ACALL TK4KE1:MOV P2,#0DFH ;P2.5行JB P2.3,KK4 ;K9 時個位增一ACALL DELAY1ACALL TK5KK4:JB P2.2,KK5 ;K10 時十位增一ACALL DELAY1INC 35H MOV R3,35HCJNE R3,#03H,HH0MOV 35H,#00HLJMP KK5HH0:CJNE R3,#02H,HH1LJMP KK5HH1:CJNE R3,#01H,HH2LJMP KK5HH2:MOV 35H,#00HKK5:JB P2.1,KK6 ACALL DELAY1 ;K11 開/關蜂鳴器CPL P3.2KK6:JB P2.0,KE2 ;K12 秒表暫停MOV 42H,#00H KE2:MOV P2,#0BFH ;P.6行JB P2.3,KK7 ;K5 時鐘暫停/取消暫停ACALL DELAY1CPL ET0 KK7:JB P2.2,KK8 ;K6 顯示/休眠/流水燈ACALL DELAY2INC 40HMOV R3,40HCJNE R3,#04H,KK8MOV 40H,#01HKK8:JB P2.1,KK9 // ACALL DELAY3 ;K7 秒表清0 MOV 44H,#00HMOV 45H,#00HMOV 46H,#00HMOV 47H,#00HMOV 48H,#00HMOV 49H,#00HKK9:JB P2.0,KE3 ;K8 秒表開始跑MOV 42H,#01H KE3:MOV P2,#7FH ;P2.7行JB P2.3,KK10 ;K1 秒十位減一ACALL DELAY1MOV R3,31HCJNE R3,#00H,JA1LJMP KK10JA1:DEC 31HKK10:JB P2.2,KK11 ;K2 分個位減一ACALL DELAY1MOV R3,32HCJNE R3,#00H,JA2LJMP KK11JA2: DEC 32HKK11:JB P2.1,KK12 ;K3 分十位減一ACALL DELAY1MOV R3,33HCJNE R3,#00H,JA3LJMP KK12JA3:DEC 33HKK12:JB P2.0,KK13 ;K4 時個位減一ACALL DELAY1MOV R3,34HCJNE R3,#00H,JA4LJMP KK13JA4:DEC 34HKK13:RET//=====流水燈子程序===========================LED: MOV A,#0feHMOV 41H,#08HMOV P0,#0FFH LED1: MOV P1,AMOV R3,#100D0: ACALL DELAYDJNZ R3,D0MOV R3,41HDJNZ R3,AAALJMP BBAAA:RL AMOV 41H,R3 ACALL KEYLJMP LED1BB: MOV 41H,#07HCC: MOV P1,AMOV R3,#30D1: ACALL DELAYDJNZ R3,D1MOV R3,41HDJNZ R3,DDLJMP LED0DD:RR AMOV 41H,R3ACALL KEYLJMP CCLED0:RET //=====延時子程序============================== DELAY:MOV R1,#250DEL1:NOP NOPNOPNOP DJNZ R1,DEL1RET//====調(diào)用時鐘顯示作延時========================DELAY1:MOV R2,#20 DELA3: ACALL MAIN2DJNZ R2,DELA3 RET//====調(diào)用秒表顯示作延時========================DELAY3:MOV R2,#20DELA5:ACALL MAIN3DJNZ R2,DELA5RET//====調(diào)用延時子程序作延時======================DELAY2:MOV R2,#100 DELA4:ACALL DELAYDJNZ R2,DELA4RET//======共陽數(shù)碼管段碼表================================= TAB:DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H,87HEND
評論