T0作定時器匯編程序(中斷法)
電路是:P0口接數(shù)碼管的字型碼筆段,P2口接數(shù)碼管的數(shù)位選擇端.
本文引用地址:http://butianyuan.cn/article/201612/324573.htm下面是匯編語言源程序:
SECOND EQU 30H
TCOUNT EQU 31H
ORG 00H
LJMP START
ORG 0BH
LJMP INT0X
START: MOV SECOND ,#00H
MOV A,SECOND
MOV B,#10
DIV AB
MOV DPTR,#TABLE
MOVC A,@A+DPTR
MOV P0,A
MOV A,B
MOVC A,@A+DPTR
MOV P2,A
MOV TCOUNT,#00H
MOV TMOD,#01H
MOV TH0,#(65536-50000)/256
MOV TL0,#(65536-50000) MOD 256
SETB TR0
SETB ET0
SETB EA
SJMP $
INT0X: MOV TH0,#(65536-5000)/256
MOV TL0,#(65536-5000) MOD 256
INC TCOUNT
MOV A,TCOUNT
CJNE A,#20,NEXT
MOV TCOUNT,#00H
INC SECOND
MOV A,SECOND
CJNE A,#60,NEX
MOV SECOND,#00H
NEX: MOV A,SECOND
MOV B,#10
DIV AB
MOV DPTR,#TABLE
MOVC A,@A+DPTR
MOV P0,A
MOV A,B
MOVC A,@A+DPTR
MOV P2,A
NEXT: RETI
TABLE: DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH
END
T0工作在方式1,計時50ms,共20個循環(huán),總計時1秒。
P0口顯示低位,P2口顯示高位,滿60清零
評論