
   mov   SCON,#52h    ;set serial mode 1
   ORL   PCON,#80h
   mov   TMOD,#21h    ;timer0 16-bit, timer1 autoreload
   mov   TH1,#-10     ;9600
   setb  tr1          ;enable timer 1

Loop:
    jnb  ri,$         ;wait until character received 
    clr  ri           ;    not to flood the terminal
    mov  P3,#0FFh     ;refresh P3 for all cases
    mov  a,P3         ;direct load (should show inputs)
    call TxHexa
    mov  a,#'-'
    call TxChar
    push P3           ;push - this would show latch in OKI
    pop  acc
    call TxHexa
    mov  a,#'-'
    call TxChar
    clr  a
l1: inc  a            ;Chris's djnz solution - it works!
    djnz P3,l1
    mov  P3,a
    call TxHexa
    mov  a,#','
    call TxChar
    sjmp Loop


TxHexa:
    push acc
    swap a
    anl  a,#0Fh
    add  a,#TxHexaT-TxHexaX1
    movc a,@a+pc
TxHexaX1:
    call TxChar
    pop  acc
    anl  a,#0Fh
    add  a,#TxHexaT-TxHexaX2
    movc a,@a+pc
TxHexaX2:
;fallover
TxChar:
    jnb  ti,$
    clr  ti
    mov  sbuf,a
    ret

TxHexaT:
    db   '0123456789ABCDEF'

    end
    
