prosenjit.calcutta
Newbie level 3
Code:
[syntax=csharp]
// pwm
#include <reg51.h>
sbit R = P0^0;
sbit G = P0^1;
sbit BL = P0^2;
int j;
void pwm_setup();
void DelayMs(unsigned int);
unsigned char pwm_width;
bit a=0;
void main(void)
{
pwm_setup();
while(1)
{
for (j=0;j<=255;j++)
pwm_width=j;
DelayMs(100);
/*
I want to use total 7 case, R,G,B,RG,RB,GB,RGB...
Case 1:
{
G=0;
BL=0;
break;
}
case 2:
{
R=0;
BL=0;
break;
}
*/
}
}
void pwm_setup(){
TMOD = 0;
pwm_width = 160;
EA = 1;
ET0 = 1;
TR0 = 1;
}
void timer0() interrupt 1
{
R=~R;
G=~G;
BL=~BL;
a=~a;
if(a==0)
TH0 = pwm_width; //Load timer
else
TH0 = 255 - pwm_width; //Load timer
}
//---------------------------------------
// Delay mS function
//---------------------------------------
void DelayMs(unsigned int count)
{ // mSec Delay 11.0592 Mhz
unsigned int i;
while(count) {
i = 115;
while(i>
0) i--;
count--;
}
}
[/syntax]
In a single for loop all port using same PWM output. I am unable to turn off individually.
Please help me on this..