Task 8
Task 8
TASK 8
Spring 2021
CSE307 MBSD
“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
Sunday, June 27, 2021
If temperature > 35C or below 10C then generate a 100Hz beep using speaker/sound card in Proteus. It
has a 25% duty cycle and verify it using an oscilloscope. Sampling rate of ADC = 1K samples/sec.
Problem Analysis:
It has a Vin pin which is connected to Vout pin of LM35. The converted result is send to
Dout(8-bits). The formula for Dout is:
Dout = Vin/Step-size
Since we are getting Vin from LM35 so Vin = Vout(LM35) = 10mV x Temperature.
So, Dout becomes
Dout = (10mV x Temperature)/Step-size.
Now we want step-size such that Dout = Temperature. So, our step-size should be 10mV
Dout = (10mV x Temperature)/10mV
Dout = Temperature
For step-size to be equal to 10mV, Vref/2 should be 1.28V.
Calculation:
Vref/2 = 1.28
Vref = 2.56
Step-size = Vref/255
Step-size = 2.56/255
Step-size = 10mV
This Dout is sent to P1 of 8051 microcontroller, if P1 is less than 10 or it is greater than 36 then
we need to generate a sound of 100Hz with a duty cycle of 25%.
Frequency Time Period(1/f) Duty Cycle ON OFF
100Hz 10 ms 25% 2.5ms 7.5ms
TMOD:
Timer1 Timer0
Gate C/T M1 M0 Gate C/T M1 M0
0 0 0 0 0 0 0 1 (Hex= 1)
IE:
EA -- -- ES ET1 EX1 ET0 EX0
1 0 0 0 0 0 1 0
/*Timer 0 interrupt is called when the temperature is less that 10 or greater than 36.
It will generate a Sound of 100Hz with a Duty cycle of 25% to P3.4 */
void timer0() interrupt 1
{
if(SPK ) //if the Speaker is ON
{
SPK = 0; //Turn it OFF
SetTimer(0xE2,0xB3); //Set Delay to 7.5msec
}
else //if the Speaker is OFF
{
SPK = 1; //Turn it ON
SetTimer(0xF6,0x3B); //Set the delay to 2.5msec
}
}
void main(void)
{
SPK = 0; //Turn the Speaker OFF
P1 = 0xFF; //Set P1 as an input Port
P2 = 0x00; //Set P2 as an output Port
INTR = 1; //Set P3.2 as an input pin
for(i = 0;i<5;i++)
{
writecmd(cmd[i]); //Send the Commands to LCD
delay(10); //Give some delay
}
writedata('T');
writedata('e');
writedata('m');
writedata('p');
writedata('e');
writedata('r');
writedata('a');
writedata('t');
writedata('u');
writedata('r');
writedata('e');
writedata(':');
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
Ext0(); //Call the Ext0 function
}
}
void writedata(char t)
{
RS = 1; // This is data
P2 = t; //Data transfer
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
}
void writecmd(int z)
{
RS = 0; // This is command
P2 = z; //Data transfer
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
}
void Init()
{
TMOD = 0x1; //Timer 0 is Mode 1
EA = 1; //Enable Global interrupt
ET0 = 1; //Enable timer overflow interrupt for timer 0
SetTimer(0xF6,0x3B); //Set the values of TH0 and TL0 for a delay of 2.5ms
}
void StartTimer()
{
TR0 = 1; //Start Timer 0;
}
void StopTimer()
{
TR0 = 0; //Stop Timer 0
}
//Ext0 is used for displaying the temperature value to LCD and generating sound at P3.4
void Ext0()
{
RD_n = 0; //Set the RD pin of ADC from HIGH to LOW
//The ADC sends the converted value to P1
temperature = P1; //Store the value at P1 in temperature
convert(temperature); //Display temperature on LCD
if(temperature<10 || temperature>36) //If the is less than 10 or it is greater than 36
{
SPK = 1; //Turn the speaker ON
StartTimer(); //Start the Timer
}
else //if the temperature is in-between 10 and 36
{
if(TR0 == 1) //if the Timer 0 is satarted
{
StopTimer(); //stop the timer
SetTimer(0xF6,0x3B); //Set a delay of 2.5ms
}
SPK = 0; //Turn the Speaker OFF
}
}
Output / Graphs / Plots / Results:
Schematic:
Temperature<10:
Oscilloscope Output:
Since the temperature is less than 10 so a sound of 100Hz with a Duty Cycle 25% will be
generated.
10<Temperature<36:
Oscilloscope Output:
No Signal should be generated in this case so a flat line.
Temperature>36:
Oscilloscope Output:
Since the temperature is greater than 36 so a sound of 100Hz with a Duty Cycle 25% will be
generated.