ORG 000H
AJMP MAIN
;EXT0 interrupt ;these vectors should be in order or the file won't assemble
ORG 0003H
ACALL INTERR1
RETI
;T0 interrupt
ORG 000BH ;these vectors should be in order or the file won't assemble
ACALL INTERR
MOV P3,#0FFH ;please be aware that there is no P3.6 on the 89C2051!
RETI
;Main Function
;ORG 0100H
MAIN:
MOV IE,#83H
MOV IP,01H
MOV TMOD,#12H
MOV TH0,#00H
MOV TL0,#00H
SETB IT0
;*************************
;*************************
;*************************
; MOV P0,#0FFH ;there is no P0 on 89C2051
MOV P1,#0FFH ;change this in your circuit
;*************************
;*************************
;*************************
SETB TR0
MOV R3,#00H
MOV R2,#01H
ACALL RAMC
MOV TH1,#00H
MOV TL1,#00H
SETB TR1
HERE:
AJMP HERE
;*****************************************************************
INTERR: ;T0 interrupt
CJNE R6,#0FFH,SK
MOV R6,#00H
ACALL DISP
SJMP SK1
SK:
MOV R6,#0FFH
SK1:
CLR TF0
RET
;*****************************************************************
; EXT0 interruupt
INTERR1:
CLR TR1
CLR TR0
MOV A,TH1
MOV R1,A
MOV A,TL1
MOV R0,A
MOV R3,#00H
MOV R2,#160
ACALL DIV16_16
MOV A,R2
SUBB A,0FFH
MOV TH0,A
MOV TL0,A
MOV TH1,#00H
MOV TL1,#00H
SETB TR1
SETB TR0
MOV R0,#23H
MOV R6,#00H
RET
;*****************************************************************
RAMC:
MOV DPTR,#MSG
MOV R7,#30
MOV R0,#40H
LOOP1:
MOV A,R7
SUBB A,#01H
MOVC A,@A+DPTR
MOV @R0,A
DEC R0
DJNZ R7,LOOP1
RET
DISP:
CJNE R5,#5,CONTINUE
MOV A,@R0
CJNE A,#'[',SPACE
;***************************
;***************************
;***************************
; MOV P0,#11111111B ;there is no P0 on 89C2051
MOV P1,#11111111B ;change this in your circuit
SJMP CONT
SPACE:
; MOV P0,#11111110B ;there is no P0 on 89C2051
; MOV P1,#11111110B ;change this in your circuit
;***************************
;***************************
;***************************
CONT:
INC R0
MOV R5,#00H
AJMP NEGLECT
CONTINUE:
MOV A,@R0 ; moves ASCII from RAM to R0
CLR C
SUBB A,#30H ;
MOV B,#05 ; ASCII to Adress conversion
MUL AB ;
MOV DPTR,#LOOKUP ;use labels here rather than address
ADD A,R5 ; Memory offset
MOVC A,@A+DPTR
;***************************
;***************************
;***************************
; MOV P0,A ;there is no P0 on 89C2051
MOV P1,A ;change this in your circuit
;***************************
;***************************
;***************************
INC R5
NEGLECT:
RET
;*****************************************************************
;ORG 230H ;don't need this, use the labels instead
LOOKUP:
DB 10000010B,01111100B,01111100B,01111100B,10000010B,11111110B,10111100B,00000000B,11111100B,11111110B,10111100B,01110010B,01110100B,01101100B,10011100B
DB 01111010B,01111100B,01011100B,00101100B,01110010B,11100110B,11010110B,10110110B,00000000B,11110110B,00001100B,01101100B,01101100B,01101100B,01110010B
DB 10000010B,01101100B,01101100B,01101100B,11110010B,00111100B,01111010B,01110110B,01101110B,00011110B,11100000B,00001100B,01101100B,00001100B,11100000B
DB 10011110B,01101100B,01101100B,01101100B,10000010B
;ORG 285H ;don't need this, use the labels instead
DB 10000000B,01101110B,01101110B,01101110B,10000000B,00000000B,01101100B,01101100B,10001100B,11110010B,10000010B,01111100B,01111100B,01111100B,01111100B
DB 01111100B,00000000B,01111100B,01111100B,10000010B,00000000B,01101100B,01101100B,01111100B,01111100B,00000000B,01101110B,01101110B,01111110B,01111110B
DB 00000000B,01111100B,01101100B,01101100B,01100000B,00000000B,11101110B,11101110B,11101110B,00000000B,11111110B,01111100B,00000000B,01111100B,11111110B
DB 11111010B,01111100B,00000010B,01111110B,11111110B,00000000B,11101110B,11010110B,10111010B,01111100B,00000000B,11111100B,11111100B,11111100B,11111100B
DB 00000000B,01111110B,11001110B,01111110B,00000000B,00000000B,10011110B,11101110B,11110010B,00000000B,00000000B,01111100B,01111100B,01111100B,00000000B
DB 00000000B,01101110B,01101110B,01101110B,10011110B,10000010B,01111100B,01110100B,01111000B,10000000B,00000000B,01101110B,01100110B,01101010B,10011100B
DB 10011000B,01101100B,01101100B,01101100B,10110010B,01111110B,01111110B,00000000B,01111110B,01111110B,00000000B,11111100B,11111100B,11111100B,00000000B
;*******************************************************************
;ORG 600H ;don't need this, use the labels instead
MSG:
DB 'SUMIT OJHA',0
;*******************************************************************
DIV16_16:
CLR C ;Clear carry initially
MOV R4,#00H ;Clear R4 working variable initially
MOV R5,#00H ;CLear R5 working variable initially
MOV B,#00H ;Clear B since B will count the number of left-shifted bits
DIV1:
INC B ;Increment counter for each left shift
MOV A,R2 ;Move the current divisor low byte into the accumulator
RLC A ;Shift low-byte left, rotate through carry to apply highest bit to high-byte
MOV R2,A ;Save the updated divisor low-byte
MOV A,R3 ;Move the current divisor high byte into the accumulator
RLC A ;Shift high-byte left high, rotating in carry from low-byte
MOV R3,A ;Save the updated divisor high-byte
JNC DIV1 ;Repeat until carry flag is set from high-byte
DIV2: ;Shift right the divisor
MOV A,R3 ;Move high-byte of divisor into accumulator
RRC A ;Rotate high-byte of divisor right and into carry
MOV R3,A ;Save updated value of high-byte of divisor
MOV A,R2 ;Move low-byte of divisor into accumulator
RRC A ;Rotate low-byte of divisor right, with carry from high-byte
MOV R2,A ;Save updated value of low-byte of divisor
CLR C ;Clear carry, we don't need it anymore
MOV 07H,R1 ;Make a safe copy of the dividend high-byte
MOV 06H,R0 ;Make a safe copy of the dividend low-byte
MOV A,R0 ;Move low-byte of dividend into accumulator
SUBB A,R2 ;Dividend - shifted divisor = result bit (no factor, only 0 or 1)
MOV R0,A ;Save updated dividend
MOV A,R1 ;Move high-byte of dividend into accumulator
SUBB A,R3 ;Subtract high-byte of divisor (all together 16-bit substraction)
MOV R1,A ;Save updated high-byte back in high-byte of divisor
JNC DIV3 ;If carry flag is NOT set, result is 1
MOV R1,07H ;Otherwise result is 0, save copy of divisor to undo subtraction
MOV R0,06H
DIV3:
CPL C ;Invert carry, so it can be directly copied into result
MOV A,R4
RLC A ;Shift carry flag into temporary result
MOV R4,A
MOV A,R5
RLC A
MOV R5,A
DJNZ B,DIV2 ;Now count backwards and repeat until "B" is zero
MOV R3,05H ;Move result to R3/R2
MOV R2,04H ;Move result to R3/R2
RET
;*******************************************************************
END