	org 	8000h
        jmp     8100h
	
	$MOD51GB

        org     801bh
        jmp     T1_ISR
	

        org     8100h
main:   clr     TR1
        mov     TH1,#0B7h
        mov     TL1,#0CBh
        setb    TR1        

;        mov     TMOD,#010h
;        orl     TMOD,A
        setb    ET1
        setb    EA
        clr     TR1
        call    Print
        db      'This seems to work',0,
        setb    TR1
wait:   jmp    wait
	
T1_ISR: clr     TR1
        mov     TH1,#0B7h
        mov     TL1,#0CBh
        cpl     P5.7
        setb    TR1
        reti


SEND_BYTE:
       	 JNB	TI, SEND_BYTE		; WAIT FOR THE TI FLAG TO SET
	CLR     	TI		                  ; CLEAR THE TI FLAG ONCE SENT
        	MOV   	SBUF,A 			; SEND THE CONTENTS OF REGISTER A
	RET           			; RETURN
;*****************************************************************************



PRINT:
        PUSH    ACC      ; push the A and DPTR registers so their contents  
        PUSH    DPH      ; don't get lost in case they are being used
        PUSH    DPL      ; before calling this function. 

; move the stack pointer down low in order to pop the first string's byte
; address
        MOV     A,SP     
        ADD     A,#0FDH
        MOV     SP,A
        POP     DPH
        POP     DPL

; send (PRINT) the string back to the PC computer
READ_TX:
        CLR     A
        MOVC    A,@A+DPTR
        INC     DPTR             

        CJNE    A,#'\',SND

        CLR     A
        MOVC    A,@A+DPTR
        INC     DPTR             

        CJNE    A,#'n',SND

        MOV     A,#0DH
        ACALL   SEND_BYTE
        MOV     A,#0AH

SND:    ACALL   SEND_BYTE
        CJNE    A,#0,READ_TX

; place the new return addres in stack
        PUSH    DPL
        PUSH    DPH

; move the stack pointer up high in order to pop the A and DPTR registers 
        MOV     A,SP
        ADD     A,#3
        MOV     SP,A
        POP     DPL
        POP     DPH
        POP     ACC
        RET



	end
