CS 531 LAB5 – Using the 8051 Serial Port and Interrupts Overview The purpose of
ID: 3813959 • Letter: C
Question
CS 531
LAB5 – 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)
0
0
1200
0
1
2400
1
0
4800
1
1
9600
Steps
1. 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.
2. 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.
.
3. 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 selected. The subroutine will use polling on the TI flag.
4. 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..
5. 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.
6. 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.
7. Document the new program and explain how the interrupt structure worked for Timer 0 and the Serial Port.
Please the program should be using assembly language (assembly code)
SW1
SW2
Baud (bps)
0
0
1200
0
1
2400
1
0
4800
1
1
9600
Explanation / Answer
#include <iostream>
using namespace std;
class Card
int getvalue()
come back value;
}
string getsuit()
come back suit;
}
};
int main()
}
}
for(j = 0; j < 52; j++)