Using the 8051 Serial Port and Interrupts The purpose of this lab is to control
ID: 3766601 • Letter: U
Question
Using the 8051 Serial Port and Interrupts
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 SW2are 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)
0
0
1200
0
1
2400
1
0
4800
1
1
9600
Steps
First, write a subroutine ”BCODE” (Baud Code) starting at code address 200H 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.
Second, write a subroutine “CONFIG” (Timers, Interrupts, and Serial Configuration) starting at code address 300H 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.
.
Third, write a subroutine “SDISPLAY”” (Serial Display) starting at code starting address of 400H to display on the serial port the message “SERIAL BAUD IS XXXX BPS”. “XXXX” is the actual Baud rate value. The subroutine will use polling on the TI flag.
Fourth, write a Timer 0 Interrupt Service Routine “TIMER0H” at address 500H to provide maximum delay in updating port 3 based on the status of input port 2..
Test and debug your program. Also document and submit your final report along with the well documented list file. Monitor the serial port window and verify the SBUF contents using the ASCII code for the selected message and associated BAUD rate. You can slow the SBUF update by controlling the MC clock using the clock window in the PREPHERALS selection. Make sure to check the “4x” box.
Modify the program in order to perform serial character transmission using the serial port interrupt instead of the use of polling on the TI flag. The processor will be reading Port 2 (P2) and outputting the input byte to Port 3 (P3) while the serial message is being transmitted.
Document the new program and explain how the interrupt structure worked for Timer 0 and the Serial Port.
SW1
SW2
Baud (bps)
0
0
1200
0
1
2400
1
0
4800
1
1
9600
Explanation / Answer
in 8051 micro controller p3 port supports communication in case you are using input any other port rest of p3 programming like this using timer / counters observe the code once
sw1 equ p1.0
org 0h
main: mov tmod,#20h
mov th1,#-3 % mention the baud rate of 8051 microcontroller
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
mess2: db "chegg",0
mess1: db "expert ",0
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.