Microcontroller › 8051 › GENERATING VARIABLE PWM › Hii Ajish, The Programing
Hii Ajish,
The Programing part i have done yet is using 4 push buttons to change d value of PWM output. Now this is the next step in my project design dat i want to do it using only two push buttons to either increase or decrease the duty cycle of the PWM.
My present program is….
#include <reg51.h>
sbit ONE=P2^7;
sbit TWO=P2^6;
sbit THREE=P2^5;
sbit FOUR=P2^4;
sbit FIVE=P2^3;
sbit SIX=P2^2;
sbit SEVEN=P2^1;
sbit EIGHT=P2^0;
sbit MTR=P1^0;
void MSDelay(int value);
void main()
{
unsigned int on,off;
ONE=1;
TWO=1;
THREE=1;
FOUR=1;
FIVE=1;
SIX=1;
SEVEN=1;
EIGHT=1;
while(1)
{
if (ONE==0)
{
FIVE=0;
SIX=1;
SEVEN=1;
EIGHT=1;
while(FIVE==0 && TWO==1 && THREE==1 && FOUR==1)
{
on=2;
off=8;
MTR=1;
MSDelay(on);
MTR=0;
MSDelay(off);
}
}
else if (TWO==0)
{
FIVE=1;
SIX=0;
SEVEN=1;
EIGHT=1;
while(SIX==0 && ONE==1 && THREE==1 && FOUR==1)
{
on=3;
off=7;
MTR=1;
MSDelay(on);
MTR=0;
MSDelay(off);
}
}
else if (THREE==0)
{
FIVE=1;
SIX=1;
SEVEN=0;
EIGHT=1;
while(SEVEN==0 && ONE==1 && TWO==1 && FOUR==1)
{
on=5;
off=5;
MTR=1;
MSDelay(on);
MTR=0;
MSDelay(off);
}
}
else if (FOUR==0)
{
FIVE=1;
SIX=1;
SEVEN=1;
EIGHT=0;
while(EIGHT==0 && ONE==1 && TWO==1 && THREE==1)
{
MTR=1;
}
else
{
MTR=1;
}
}
}
void MSDelay(int value)
{
int x;
for(x=0;x<=value;x++);
}
If u cn help me where to change d logic in dis present program…looking forward for it…!!