;PROGRAM NAME B11-6.ASM
MS10 EQU 9217 ;APPROXIMATELY 10ms INTERRUPR
INTR_CNT EQU 30H ;CNT STORIAGE
BUFFER EQU 31H ;DISPLAY BUFFER
BINARY EQU 32H ;BINARY DATA STORIAGE
;
SCOPE REG P3.3 ;CHECK BY SCOPE
BUZZER REG P3.4
LED REG P3.7
KEY REG P3.7
;
ORG 0000H
JMP START
ORG 0003H ;[DISABLE] EXTERNAL INT0 INTERRUPT
RETI
ORG 000BH ;[ENABLE] TIMER0 OVERFLOW INTERRUPT
JMP T0_ISR
;
ORG 0013H
RETI ;[DISABLE] EXTERNAL INT1 INTERRUPT
ORG 001BH
RETI ;[DISABLE] TIMER1 OVERFLOW INTERRUPT
ORG 0023H
RETI ;[DISABLE] SERIAL INTERRUPT
;
ORG 30H
START MOV R0,#00H
DJNZ R0,$ ;DELAY A WHILE
MOV SP,#60H
MOV P1,#FFH
MOV P3,#FFH
MOV INTR_CNT,#00H
CLR BUZZER ;P3.4=0,BUZZER OFF
CLR LED ;P3.7=0,LED OFF
CALL SET_TMR0
MOV BINARY,#00H ;BINARY DATA FOR DISPLAY
;
$LOOP SETB KEY ;KEY=1
JB KEY,$S100
MOV R7,#08H
DJNZ R7,$ ;WAIT A LITTLE WHILE
SETB KEY
JB KEY,$S100
;KEY PRESS TRUE
MOV A,BINARY
ADD A,#01H
MOV BINARY,A
CJNE A,#100,$S100 ;IF A>=100 THEN A=0
MOV BINARY,#00H ;CLEAR BINARY DATA
ACALL CONV
$WAIT SETB KEY
JNB KEY,$WAIT ;WAIT UNTIL KEY RELEASE
;
$S100 ACALL CONV ;CONVERT BINARY TO BCD
;
ACALL DELAY
ACALL DELAY
ACALL DELAY
SJMP $LOOP
;
CONV MOV A,BINARY
MOV B,#10
DIV AB ;A=A/10,B=A MOD 10
ANL A,#0FH ;A=A AND 0FH
JNZ $1
MOV A,#0FH ;IF A=00H THEN A=0FH LEADING BLANK
$1 SWAP A
ORL A,B ;A AS BCD FORM
MOV BUFFER,A ;SAVE AT BUFFER
RET
;
DELAY MOV R7,#00H
$1 MOV R6,#00H
DJNZ R6,$
DJNZ R7,$1
RET
;
T0_ISR SETB SCOPE
MOV TH0,#(65536-MS10)/256 ;RELOAD TH0
MOV TL0,#(65536-MS10).MOD. 256
PUSH A
PUSH PSW
;
MOV A,BUFFER
ANL A,#0FH ;GET LOW NIBBLE
SETB ACC.5 ;BIT5=1
MOV P1,A ;SHOW 1 DIGIT
MOV R0,#30H
DJNZ R0,$ ;DELAY
;inter-blanking
CLR ACC.4
CLR ACC.5
MOV P1,A ;ALL DIGIT BLANK
MOV R0,#04H
DJNZ R0,$ ;DELAY
;
MOV A,BUFFER
ANL A,#F0H ;GET HIGH NIBBLE
SWAP A ;SWAP A
SETB ACC.4 ;BIT4=1
MOV P1,A ;SHOW ANOTHER DIGIT
MOV R0,#30H
DJNZ R0,$ ;DELAY
;
CLR ACC.4
CLR ACC.5
MOV P1,A ;ALL DIGIT BLANK
;
;INTR_CNT+1
INC INTR_CNT
MOV A,INTR_CNT
CJNE A,#100,$T0_END
MOV INTR_CNT,#00H
$T0_END POP PSW
POP A
CLR SCOPE
RETI
;
SET_TMR0
MOV A,#01H ;TIMER MODE 1
MOV TMOD,A
MOV TH0,#(65536-MS10)/256 ;RELOAD TH0
MOV TL0,#(65536-MS10).MOD. 256
CLR TF0 ;CLEAR TIMER0 FLAG
SETB TR0 ;TIMER0 START COUNT
SETB ET0 ;ENABLE TIMER0 INTERRUPT
SETB EA ;ENABLE SYSTEM INTERRUPT
RET
;