0% found this document useful (0 votes)
7 views

Task 4

The document outlines a microprocessor-based system design task involving the generation of a signal on pin P1.1 with varying frequencies and duty cycles based on button presses. The task includes programming in C to create delays using timers and displaying the results on an oscilloscope. The document also provides detailed calculations for the timing parameters and includes the source code for the implementation.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Task 4

The document outlines a microprocessor-based system design task involving the generation of a signal on pin P1.1 with varying frequencies and duty cycles based on button presses. The task includes programming in C to create delays using timers and displaying the results on an oscilloscope. The document also provides detailed calculations for the timing parameters and includes the source code for the implementation.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

MICROPROCESSOR BASED SYSTEM DESIGN

TASK 4

Spring 2021
CSE307 MBSD

Submitted by: Shah Raza


Registration No. : 18PWCSE1658
Class Section: B

“On my honor, as student of University of Engineering and Technology, I have neither given
nor received unauthorized assistance on this academic work.”

Student Signature: ______________

Submitted to:
Dr. Bilal Habib
Sunday, May 9, 2021

Department of Computer Systems Engineering


University of Engineering and Technology, Peshawar
Task:
A. Generate a signal on pin P1.1 having frequency equal to 80 Hz with a duty cycle of 10%.
B. When a user presses a button at P1.2 then frequency changes to 40Hz with a 20% duty
cycle.
C. When a user again presses the same button then frequency changes to 20Hz with a duty
cycle of 40%.
D. When a user again presses the same button then frequency changes to 10Hz with a duty
cycle of 80%.
E. Show it on oscilloscope.
F. Each time a user presses a button the signal toggles from case A to B, then B to C, then C
to D and finally from D to A, on every subsequent button press.
G. Program only in C
Create all Delays using timers.

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>

sbit Signal = P1^1;


sbit Input = P1^2;
int check = 0;
int i;

void Timer0(int XX, int YY)


{
TMOD = 0x01; //Timer o, Mode 1
TH0 = XX; //High 8 bits
TL0 = YY; //Low 8 bits
TR0 = 1; //Start the Timer
while(TF0 == 0); //Check Timer Flag
TR0 = 0; //Stop Timer
TF0 = 0; //Reset Timer Flag
}

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):

Case C (Pressing the Button for the 2nd Time):

Case D (Pressing the Button for the 3rd Time):

You might also like