Task 3
Task 3
TASK 3
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 1st, 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)
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)
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)
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)
Code:
#include <reg51.h>
#include <stdio.h>
void main(void)
{
int check=0;
P1_2 = 1; //Configure for Input
while (1)
{
if(P1_2==0) //Button Pressed
check++;
switch(check%4)
{
case 0:
P1_1 = 1;
Delay(1); //1ms Delay
Delay1(); //0.25ms Delay
P1_1 =0;
Delay(11); //11ms Delay
Delay1(); //0.25ms Delay
break;
case 1:
P1_1 = 1;
Delay(5); //5ms Delay
P1_1 =0;
Delay(20); //20ms Delay
break;
case 2:
P1_1 = 1;
Delay(20); //20ms Delay
P1_1 =0;
Delay(30); //30ms Delay
break;
case 3:
P1_1 = 1;
Delay(80); //80ms Delay
P1_1 =0;
Delay(20); //20ms Delay
break;
}
}
}