Question 11.8: Write a program in which the 8051 reads data from P1 and wri...

Write a program in which the 8051 reads data from P1 and writes it to P2 continuously while giving a copy of it to the serial COM port to be transferred serially. Assume that XTAL=11.0592. Set the baud rate at 9600.

The blue check mark means that this solution has been answered and checked by an expert. This guarantees that the final answer is accurate.
Learn more on how we answer questions.

 

ORG       0000H
LJMP     MAIN
ORG       23H
LJMP     SERIAL         ;jump to serial int ISR
ORG       30H

MAIN:           MOV      P1,#0FFH       ;make P1 an input port

MOV      TMOD,#20H ;timer 1, auto reload
MOV      TH1,#0FDH   ;9600 baud rate
MOV      SCON,#50H   ;8-bit,1 stop, ren enabled
MOV      IE,10010000B ;enable serial int.
SETB     TR1                    ;start timer 1

BACK:          MOV      A,P1                  ;read data from port 1

MOV     SBUF,A            ;give a copy to SBUF
MOV     P2,A                  ;send it to P2
SJMP    BACK                ;stay in loop indefinitely

. . .
. . .
;—————–SERIAL   PORT   ISR

ORG    100H

SERIAL:       JB      TI,TRANS         ;jump if TI is high

MOV    A,SBUF             ;otherwise due to receive
CLR     RI                        ;clear RI since CPU doesn’t
RETI                                ;return from ISR

TRANS:        CLR      TI                        ;clear TI since CPU doesn’t

RETI                                ;return from ISR
END

The moment a byte is written into SBUF it is framed and transferred
serially. As a result, when the last bit (stop bit) is transferred the TI is
raised, and that causes the serial interrupt to be invoked since the
corresponding bit in the IE register is high. In the serial ISR, we check
for both TI and RI since both could have invoked interrupt.

Related Answered Questions

Question: 11.22

Verified Answer:

(a) The address range for Y4 is calculated as foll...
Question: 11.25

Verified Answer:

Figure 14-14 shows the design. Notice the role of ...
Question: 11.20

Verified Answer:

The 27128 has a capacity of 128K bits. It has 16K ...