03.01.2015 Views

80C186EC/80C188EC Microprocessor User's Manual

80C186EC/80C188EC Microprocessor User's Manual

80C186EC/80C188EC Microprocessor User's Manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

SERIAL COMMUNICATIONS UNIT<br />

DisconnectMode:<br />

mov dx, S1STS ; clear any pending exceptions<br />

in ax,dx<br />

mov dx, P1CON ; get state of port 1 controls<br />

in ax, dx<br />

and ax, 0f0h ; make sure P1.0:P1.3 is port<br />

out dx, ax<br />

mov dx, P2CON ; set P2.1 for TXD1, P2.0for RXD1<br />

mov ax, 0ffh<br />

out dx, ax<br />

mov dx, P1LTCH ; make sure TXD latch is tristated<br />

mov ax, TriStateDis<br />

out dx, ax ; set P1.7 to zero<br />

mov dx, S1CON ; select control register<br />

mov ax, 0022h ; receive, Mode 2<br />

out dx, ax<br />

SelStatus: mov dx, S1STS ; select status register<br />

Check_4_RI: in ax, dx ; get status<br />

test ax, 0040h ; data waiting<br />

jz Check_4_RI ; no: then keep checking<br />

mov dx, S1SRUF ; yes: then get data<br />

in ax, dx<br />

cmp al, My_Address ; is slave_1 being addressed<br />

jne SelStatus ; no: then ignore<br />

mov dx, S1CON ; yes: then switch to Mode 3, transmit<br />

mov ax, 0003h ; Mode 3<br />

out dx, ax<br />

mov dx, P1LTCH ; enable tristate buffer<br />

mov ax, TriStateEna<br />

out dx, ax ; gate TXD onto master’s RXD<br />

mov dx, S1TBUF ; echo My_Address to the master<br />

mov ax, My_Address<br />

out dx, ax<br />

mov dx, S1CON ; switch to receive mode<br />

mov ax, 0023h ; Mode 3, receive<br />

out dx, ax<br />

Wait_4_Cmd: mov dx, S1STS ; select status register<br />

in ax, dx ; get status<br />

test ax, 0040h ; command waiting<br />

jz Wait_4_Cmd ; no: then keep checking<br />

mov dx, S1RBUF ; yes: then get command<br />

in ax, dx<br />

cmp<br />

je<br />

al, Disconnect ; Disconnect command<br />

DisconnectMode ; yes: then disconnect RXD from network<br />

Example 11-5. Master/Slave — The slave_1 Routine (Continued)<br />

11-30

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!