//晶振12M KEY BIT P3.2 ;按鍵接P3.2 LED_bits BIT P3.1;個位顯示控制端 LED_ten BIT P3.0;十位顯示控制端 DATA_bits DATA 30H;個位 DATA_ten DATA 31H;十位 ORG 00H LJMP MAIN ORG 30H MAIN: ;主程式 SETB LED_bits SETB LED_ten SETB KEY MOV DATA_bits,#0 MOV DATA_ten,#0 LOOP: ACALL DISPLAY;顯示 ACALL KEY_COUNT;鍵控 LJMP LOOP KEY_COUNT:;鍵控計數 JB KEY, KEY_END ACALL DELAY10MS JNB KEY,$ ACALL COUNT KEY_END: RET COUNT: ;計數 INC DATA_bits MOV A,DATA_bits CJNE A,#10,COUNT_END MOV DATA_bits,#0 INC DATA_ten MOV A,DATA_ten CJNE A,#10,COUNT_END MOV DATA_ten,#0 COUNT_END: RET DISPLAY: ;顯示 MOV A,DATA_bits MOV DPTR,#LEDSHOW MOVC A,@A+DPTR MOV P2,A CLR LED_bits ACALL DELAY1MS SETB LED_bits MOV A,DATA_ten MOV DPTR,#LEDSHOW MOVC A,@A+DPTR MOV P2,A CLR LED_ten ACALL DELAY1MS SETB LED_ten RET DELAY10MS: ;誤差 0us MOV R7,#01H DL1: MOV R6,#26H DL0: MOV R5,#82H DJNZ R5,$ DJNZ R6,DL0 DJNZ R7,DL1 RET DELAY1MS: ;誤差 0us MOV R7,#01H DL3: MOV R6,#8EH DL2: MOV R5,#02H DJNZ R5,$ DJNZ R6,DL2 DJNZ R7,DL3 RET LEDSHOW: DB 03FH;0 DB 006H;1 DB 05BH;2 DB 04FH;3 DB 066H;4 DB 06DH;5 DB 07DH;6 DB 007H;7 DB 07FH;8 DB 06FH;9 END
//晶振12M KEY BIT P3.2 ;按鍵接P3.2 LED_bits BIT P3.1;個位顯示控制端 LED_ten BIT P3.0;十位顯示控制端 DATA_bits DATA 30H;個位 DATA_ten DATA 31H;十位 ORG 00H LJMP MAIN ORG 30H MAIN: ;主程式 SETB LED_bits SETB LED_ten SETB KEY MOV DATA_bits,#0 MOV DATA_ten,#0 LOOP: ACALL DISPLAY;顯示 ACALL KEY_COUNT;鍵控 LJMP LOOP KEY_COUNT:;鍵控計數 JB KEY, KEY_END ACALL DELAY10MS JNB KEY,$ ACALL COUNT KEY_END: RET COUNT: ;計數 INC DATA_bits MOV A,DATA_bits CJNE A,#10,COUNT_END MOV DATA_bits,#0 INC DATA_ten MOV A,DATA_ten CJNE A,#10,COUNT_END MOV DATA_ten,#0 COUNT_END: RET DISPLAY: ;顯示 MOV A,DATA_bits MOV DPTR,#LEDSHOW MOVC A,@A+DPTR MOV P2,A CLR LED_bits ACALL DELAY1MS SETB LED_bits MOV A,DATA_ten MOV DPTR,#LEDSHOW MOVC A,@A+DPTR MOV P2,A CLR LED_ten ACALL DELAY1MS SETB LED_ten RET DELAY10MS: ;誤差 0us MOV R7,#01H DL1: MOV R6,#26H DL0: MOV R5,#82H DJNZ R5,$ DJNZ R6,DL0 DJNZ R7,DL1 RET DELAY1MS: ;誤差 0us MOV R7,#01H DL3: MOV R6,#8EH DL2: MOV R5,#02H DJNZ R5,$ DJNZ R6,DL2 DJNZ R7,DL3 RET LEDSHOW: DB 03FH;0 DB 006H;1 DB 05BH;2 DB 04FH;3 DB 066H;4 DB 06DH;5 DB 07DH;6 DB 007H;7 DB 07FH;8 DB 06FH;9 END