        TA    EQU  0C7h
        MCON  EQU  0C6h


        ORG   00h
        SJMP  Start

;serial interrupt service routine
        ORG   23h
        RETI

;--------------------------------------------------------------------------------
                                   ;main routine

        ORG   30h
Start :
        MOV   TA,   #0AAh          ;Timed...
        MOV   TA,   #055h          ; ...Access
        ORL   MCON, #02h           ;Set PAA
        MOV   MCON, #020h          ;Set partition to 4KB
        MOV   TA,   #0AAh          ;Timed...
        MOV   TA,   #055h          ; ...Access
        ANL   MCON, #0FDh          ;Clear PAA

                                   ;Move data pointer to first unused RAM location

        MOV   DPTR, #1000h         ;Start of data memory

                                   ;Turn on interrupts

        ORL   PCON, #08h           ;Enable Power-fail warning
        SETB  PS                   ;Set serial port interrupt to high priority
        SETB  ES                   ;Enable serial port interrupt
        CLR   PT0                  ;Set external interrupt 0 to low priority
        CLR   EX0                  ;Disable external interrupt 0 (pin 3.2)
        SETB  EA                   ;Turn on interrupts

                                   ;Set up serial port

        MOV   SCON, #01010000b     ;Select mode 1 (async, 8N1, baud from timer 1)
        MOV   TH1,  #245           ;Baud rate (245 -> 2400 baud)
        ANL   PCON, #07fh          ;Baud rate multiplier (set to 1)
        MOV   TMOD, #00100000b     ;Set timer 1 for 8-bit auto-reload mode
        MOV   TCON, #01000000b     ;Enable timer 1
        CLR   RI                   ;Clear serial receive flag
        CLR   TI                   ;Clear serial transmit flag


;--------------------------------------------------------------------------------
                                   ;Main routine
                                   ;Sends data to the serial port until it hits a B7h

        MOV   A,#13                ;Send a <CR> to get away from the prompt
        MOV   SBUF,A
        JNB   TI,$
        CLR   TI
        CLR   RI

write:  
        MOVX  A,@DPTR              ;Store byte from memory into accumulator
        CJNE  A,#0B7H,cont         ;If the byte isn't a B7h, keep going
        SJMP  done
cont:   MOV   SBUF,A               ;Send byte to PC
        JNB   TI,$                 ;Wait until it is sent
        CLR   TI
        CLR   RI
        INC   DPTR                 ;Go to next memory location
        SJMP  write                ;Continue with next byte

done:   SJMP  $                    ;After we find a B7h, just stay here and wait

;--------------------------------------------------------------------------------
        END
