Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

LAB7 Using the 8051 Serial Port and Interrupts Overview The purpose of this lab

ID: 2082822 • Letter: L

Question

LAB7 Using the 8051 Serial Port and Interrupts Overview The purpose of this lab is to control and program the serial port of the micro-controller in a given sequence. Two switches SW1 and SW2 are connected to the micro-controller input port bits P1.1 and P1.2. The two switches define the required Baud rate requirements for the serial communication as follows: SW1 SW2 Baud (bps) 10 1200 2400 1 0 4800 1 9600 Steps First, write a subroutine "BCODE" (Baud Code) starting at code address 100H to detect the setting of SW1 and SW2 and return a value in accumulator B (0 for 1200, 1 for 2400, 2 for 4800, and 3 for 9600 Baud). It also setup the TH1 register for the requested BAUD rate. 2.Second, write a subroutine "CONFIG Timers, Interrupts, and Serial Configuration) starting at code address 160H to configure the serial port for Mode 1, timer 0 for mode 1, and timer 1 for mode 2. Also it enables the timer 0 interrupt and start timer 0 and timer 1. 3 Third, write a subroutine "SDISPLAY (Serial Display) starting at code starting address of 200H to display on the serial port the message "SERIAL BAUD IS XXXX BPS. "XXXX" s the actual Baud rate value selected. The subroutine will use polling on the TI flag.

Explanation / Answer

sw1 equ p1.0
org 0h
main:   mov tmod,#20h
        mov th1,#-3
        mov scon,#50h
        setb tr1
        setb sw1
sb1:    jb sw1,next
        mov dptr,#mess1
fn:     clr a
        movc a,@a+dptr
        jz sb1
        acall sendcom
        inc dptr
        sjmp fn
next:   mov dptr,#mess2
ln:     clr a
        movc a,@a+dptr
        jz sb1
        acall sendcom
        inc dptr
        sjmp ln
sendcom:mov sbuf,a
here:   jnb ti,here
        clr ti
        ret

end