Aim:
To write a C program to generate Sine/Square/Triangular waveforms with different
frequency and amplitude using DAC.

Algorithm for Triangular Wave:
Step1. Declare control word register at address 0xe003
Step 2. Initialize Port A & Port B with memory locations 0xe000 and 0xe001 respectively
Step 3. Set the control word register of 8255 as 0x80 for setting IO modes
Step 4. Increment Port A 5 times until it reaches 0xff
Step 5. Once it reach 0xff, decrement port 5 times until it reaches 0x00
Step 6. Go to step 4
Step 7. Stop the execution

Algorithm for Square Wave:
Step1. Declare control word register at address 0xe003
Step 2. Initialize Port A & Port B with memory locations 0xe000 and 0xe001 respectively
Step 3. Configure the control word register of 8255 as 0x80 for setting IO modes
Step 4. Assign value 0x00 and 0xff to port A and Port B respectively
Step 5. For each value give some delay for getting proper square wave
Step 6. Go to step 4
Step 7. Stop the execution

Program to generate Triangular wave using DAC
#include <REG51.H>
unsigned char xdata control _at_ 0xe003;
unsigned char xdata porta _at_ 0xe000;
unsigned char xdata portb _at_ 0xe001;
void main()
{
control = 0x80;
porta=0x0;
while(1)
{
do
{
porta+=0x05;
}while(porta<0xff);
do
{
porta-=0x05;
}while(porta>0x00);
}
}

Program to generate Square wave using DAC
#include <REG51.H>
unsigned char xdata control _at_ 0xe003;
unsigned char xdata porta _at_ 0xe000;
unsigned char xdata portb _at_ 0xe001;
void delay(int g);
void main()
{
control = 0x80;
while(1)
{
porta=0x0;
portb=0x0;
delay(100);
porta=0xff;
portb=0xff;
delay(100);
}
}
void delay(int g)
{
int h;
for(h=0;h<=g;g++)
{
;
}
}