MBSD Task 9
MBSD Task 9
TASK 9
“On my honor, as student of University of Engineering and Technology, I have neither given nor
received unauthorized assistance on this academic work.”
Submitted to:
Dr. Bilal Habib
In this project you are required to use two microcontrollers to communicate over serial lines as shown
below in figure 1.
• Input signal to ADC has a frequency (f_in) of 50Hz. How you supplied it.
Answer: I supplied this input frequency by editing the properties of sine generator.
• What happens if you decrease the sampling rate (fs) from 500HZ, 400HZ to 100HZ samples per
second? Answer: If we decrease the sampling rate from 500hz to 400hz and then to 100hz, the
output signal will be distorted as we are not taking enough samples to reform the original signal.
Output Signal :
• Can we increase the frequency of input signal (f_in) to 10KHz, if not then why?
Answer: No, we cannot increase the frequency of input signal to 10KHz because we will need a
sampling frequency of 1MHz for that, which is practically not possible to achieve.
• If transmission rate is increased to 19,200 bps. Is your design able to handle input frequency
(f_in) equal to 10KHz, without any loss of information? Assuming fs = = 10 x f_in.
Answer: No, my design will not be able to handle input frequency of 10KHz without any loss of
information even if we increase the transmission rate to 19200 bps.
Code:
MCU 1:
#include <reg51.h>
#include <stdio.h>
void main(void)
{
P1 = 0xFF; //Set P1 as an input Port
INTR = 1; //Set P3.2 as an input pin
TMOD = 0x20; //Timer 1 mode 2
TH1 = 0xFD; //9600 bps
SCON = 0x40; //Mode 1 serial communication
PCON = 0x00; //SMOD = 0
TR1= 1; //Start timer 1
while (1)
{
RD_n = 1; //Set the RD pin to High
WR_n = 0;//WR = Low WR_n = 1;//Low-->High
while(INTR==1); //Wait for the ADC to Convert the given voltage
RD_n = 0; //Set the RD pin of ADC from HIGH to LOW
//The ADC sends the converted value to P1 SBUF = P1; //Send the
value at P1 to SBUF while(TI==0); //While the SBUF is not
transmitted, do nothing
TI = 0; //Reset the TI bit to 0
}
}
MCU 2:
#include <reg51.h>
#include <stdio.h>
void main(void)
{
P1 = 0x00; //Set P1 as an Output Port
TMOD = 0x20; //Timer 1 mode 2
TH1 = 0xFD; //9600 bps
SCON = 0x50; //Mode 1 serial communication with REN bit set to 1
PCON = 0x00; //SMOD = 0 TR1=
1; //Start timer 1 while
(1)
{
while(RI == 0); //While the value is not recieved, do nothing
RI = 0; //Reset the RI bit to 0
P1 = SBUF; //Send the value recieved at SBUF to P1
}
}
Output / Graphs / Plots / Results:
Schematic:
Oscilloscope Output: