Task 4
Task 4
TASK 4
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, May 9, 2021
Problem Analysis:
Case A: To generate a signal of frequency 80Hz we need a time period of 1/80 s
So T = 1/f = 1/80 = 0.0125s
T = 12.5 ms
As Duty Cycle is 10%, so
P1.1 ON (1.25 ms)
P1.1 OFF(11.25 ms)
Delay using Timers:
1.25ms = 1250us
65535(FFFF in hex)-1250 = 64285(FB1D)
11.25ms = 11250us
65535-11250 = 54285(D40D)
Case B: To generate a signal of frequency 40Hz we need a time period of 1/40 s
So T = 1/f = 1/40 = 0.025s
T = 25 ms
As Duty Cycle is 20%, so
P1.1 ON (5 ms)
P1.1 OFF(20 ms)
Delay using Timers:
5ms = 5000us
65535-5000 = 60535(EC77)
20ms = 20000us
65535-20000 = 45535(B1DF)
Case C: To generate a signal of frequency 20Hz we need a time period of 1/20 s
So T = 1/f = 1/20 = 0.05s
T = 50 ms
As Duty Cycle is 40%, so
P1.1 ON (20 ms)
P1.1 OFF(30 ms)
Delay using Timers:
20ms = 20000us
65535-20000 = 45535(B1DF)
30ms = 30000us
65535-30000 = 35535(8ACF)
Case D: To generate a signal of frequency 10Hz we need a time period of 1/10 s
So T = 1/f = 1/10 = 0.10s
T = 100 ms
As Duty Cycle is 80%, so
P1.1 ON (80 ms)
P1.1 OFF(20 ms)
Delay using Timers:
80ms = 80000us
65.535ms is the max delay we can create, so to attain a delay of 80ms, we should create a delay
of 40ms and run it 2 times.
40ms = 40000us
65535-40000 = 25535(63BF)
20ms = 20000us
65535-20000 = 45535(B1DF)
Code:
#include <reg51.h>
#include <stdio.h>
void main(void)
{
Input = 1; //Configure for input
while (1)
{
if(Input==0) //Button Pressed
check++;
switch(check%4)
{
case 0:
Signal = 1;
Timer0(0xFB,0x1D); //Delay of 1.25ms
Signal = 0;
Timer0(0xD4,0x0D); //Delay of 11.25ms
break;
case 1:
Signal = 1;
Timer0(0xEC,0x77); //Delay of 5ms
Signal = 0;
Timer0(0xB1,0xDF); //Delay of 20ms
break;
case 2:
Signal = 1;
Timer0(0xB1,0xDF); //Delay of 20ms
Signal = 0;
Timer0(0x8A,0xCF); //Delay of 30ms
break;
case 3:
Signal = 1;
for(i=0;i<2;i++) //40ms x 2 = 80ms
Timer0(0x63,0xBF); //Delay of 40ms
Signal = 0;
Timer0(0xB1,0xDF); //Delay of 20ms
break;
}
}
}
Output / Graphs / Plots / Results:
Circuit Diagram:
Oscilloscope Verification:
Case A (Without Pressing the Button):
Case B (After Pressing the Button):