我是从最简单的万年历开始学习单片机的当时感觉真的很酷很炫,又很感兴趣,我觉得兴趣是最好的老师。
SEC_L EQU 20H ;秒个位数存放处SEC_H EQU 21H ;秒十位数存放处SEC EQU 22H ;秒计数器寄存处MIN EQU 23H ;分个位数存放处MIN_H EQU 24H ;分十位数存放处MIN_L EQU 25H ;分计数器寄存处SHI EQU 26H ;分个位数存放处SHI_H EQU 27H ;分十位数存放处SHI_L EQU 28H ;分计数器寄存处WEI1 EQU P2.7WEI2 EQU P2.6WEI3 EQU P2.5WEI4 EQU P2.4WEI5 EQU P2.3WEI6 EQU P2.2WEI7 EQU P2.1WEI8 EQU P2.0ORG 0000HSTAR: MOV SEC,#0 ;初始化计数器 MOV MIN,#0 MOV SHI,#0 STLOP: ACALL DISPLAY1 INC SEC MOV A,SEC CJNE A,#100,STLOP;等于100 MOV SEC,#0 INC MIN MOV A,MIN CJNE A,#60,STLOP;等于60 MOV MIN,#0 INC SHI MOV A,SHI CJNE A,#60,STLOP;等于60 MOV SHI,#0 ;INC MIN_L ; MOV A,MIN_L ; CJNE A,#10,STLOP;等于10 ; MOV MIN_L,#0 ; INC MIN_H ; MOV A,MIN_H ; CJNE A,#60,STLOP;等于60 ; MOV MIN_H,#0 NEXT: LJMP STLOP;显示子程序DISPLAY1:MOV A,SEC MOV B,#10 DIV AB MOV SEC_H,A MOV SEC_L,B MOV DPTR,#NUMTAB ;少了把分钟的高低位分离出来 MOV A,MIN MOV B,#10 DIV AB MOV MIN_H,A MOV MIN_L,B MOV DPTR,#NUMTAB MOV A,SHI MOV B,#10 DIV AB MOV SHI_H,A MOV SHI_L,B MOV DPTR,#NUMTAB MOV R1,#30DPLOP: MOV A,SEC_L MOVC A,@A+DPTR MOV P0,A SETB WEI1 ACALL D1MS CLR WEI1 MOV A,SEC_H MOVC A,@A+DPTR MOV P0,A SETB WEI2 ACALL D1MS CLR WEI2 MOV A,MIN_L MOVC A,@A+DPTR MOV P0,A SETB WEI3 ACALL D1MS CLR WEI3 MOV A,MIN_H MOVC A,@A+DPTR MOV P0,A SETB WEI4 ACALL D1MS CLR WEI4 MOV A,SHI_L MOVC A,@A+DPTR MOV P0,A SETB WEI5 ACALL D1MS CLR WEI5 MOV A,SHI_H MOVC A,@A+DPTR MOV P0,A SETB WEI6 ACALL D1MS CLR WEI6 CLR WEI7 CLR WEI8 DJNZ R1,DPLOP RETD1MS: MOV R7,#4 D1: MOV R6,#4 D2: DJNZ R6,$ DJNZ R7,D1 RET;ORG 0100hNUMTAB: DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH ;0123456789字形码NUMTAB1: DB 0BFH,86H,0DBH,0CFH,0E6H,0EDH,0FDH,87H,0FFFH,0EFHEND