0% found this document useful (0 votes)
16 views8 pages

Task 9

The document outlines a microprocessor-based system design task for generating four different waveforms using a DAC0808. It includes problem analysis, code implementation, and details about the timer and interrupts used for waveform generation. The task was submitted by Shah Raza to Dr. Bilal Habib at the University of Engineering and Technology, Peshawar.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views8 pages

Task 9

The document outlines a microprocessor-based system design task for generating four different waveforms using a DAC0808. It includes problem analysis, code implementation, and details about the timer and interrupts used for waveform generation. The task was submitted by Shah Raza to Dr. Bilal Habib at the University of Engineering and Technology, Peshawar.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

MICROPROCESSOR BASED SYSTEM DESIGN

TASK 9

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, July 4, 2021

Department of Computer Systems Engineering


University of Engineering and Technology, Peshawar
Task:
Design the following four waveforms: all of them have 120Hz frequency
Problem Analysis:
DAC:
DAC is used for digital to analog conversion. We will be using DAC0808 in this
task. DAC0808 has 8-bits digital input and it converts this input into analog. It has
Iout and Vref pins. Formulas for DAC:
Iref = Vref / R
Iout = Iref(D7/2 +D6/4 +D5/8 +D4/16 +D3/32 +D2/64 + D1/128 + D0/256)
Vout = Iout*R

TMOD:

Timer1 Timer0
Gate C/T M1 M0 Gate C/T M1 M0
0 0 0 0 0 0 0 1 (Hex= 1)

Timer 0: Used as Timer with mode 1

IE:
EA -- -- ES ET1 EX1 ET0 EX0
1 0 0 0 0 0 1 1

Timer 0 (Used as timer in Mode 1):


Code:
#include <reg51.h>
#include <stdio.h>

int wave = 0; //Used to keep track of which waveform to show


int index =0; //Used in the formation of a sine wave
unsigned char i=0; //Used in the formation of triangular wave and square wave
unsigned char ramp = 255; //Used in the formation of ramp wave

char sine[12] = {128,192,239,255,239,192,128,64,17,0,17,64}; //Digital values that needs to


be sent at P1 to form sine wave

void ext0() interrupt 0 //Called when a button is pressed at P3.2


{
wave++;
i = 0;
index =0;
ramp = 255;
}

void timer() interrupt 1 //Called when the TF0 bit is set


{
switch(wave%4)
{
case 0: //Sine wave
index++;
index = index%12;
TH0 = 0xFD; //8.4ms/12 = 0.7ms delay
TL0 = 0x43;
break;
case 1: //Do nothing
break;
case 2: //Ramp wave
ramp--;
TH0 = 0xFF; //32usec delay
TL0 = 0xDF;
break;
case 3: //Square Wave
if(i==0)
i=255;
else
i = 0;
TH0 = 0xEF; //8.4/2 = 4.2msec delay
TL0 = 0x97;
break;
}
}

void init()
{
TMOD = 0x1; //Timer 0 mode 1
EA =1; //Enable Global interrupt
ET0 = 1; //Enale Timer 0 interrupt
EX0 = 1; //Enable external interrupt 0
TH0 = 0xFD; //700usec delay
TL0 = 0x43;
IT0 =1; //Make interrupt 0 edge triggered
}

void delay()
{
unsigned int a;
for(a=0;a<1;a++);
}

void main(void)
{
init();
TR0 = 1; //Start timer 0
while (1)
{
switch(wave%4)
{
case 0:
P1 = sine[index]; //Send sine wave
break;
case 1: //Send Triangular Wave
for(i =0;i<255;i++)
{
P1 = i;
delay();
}
for(i=255;i>0;i--)
{
P1 = i;
delay();
}
break;
case 2: //Send Ramp wave
P1 = ramp;
break;
case 3: //Send Square wave
P1 = i;
break;

}
}

Output / Graphs / Plots / Results:


Schematic:
Sine Wave(Button not pressed) :

Triangular Wave (Button pressed once):

Ramp Wave (Button pressed twice):


Square Wave (Button Pressed trice):

You might also like