/*pwm 调制程序*/
/*作者: 尹书扬 */
/*时间:05-8-27 */
/*说明: key用来控制 脉宽的高电平时间,
可以在P2.0引脚 接一个led做测试*/
#i nclude <reg51.h>
#define CIRCLE 10
void pwmkey(void);
unsigned char count=1,last;
sbit led=P2^0;
sbit key=P0^0;
void main(void)
{
EA=1;
ET0=1;
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
TR0=1;
count=1;
last=1;
while(1)
{
pwmkey();
}
}
void pwmkey(void)
{
char old=0 ,new=0;
while(1)
{
new=key;
if(new && !old)
last++;
if(last>CIRCLE)
last=1;
old=new;
}
}
void into(void) interrupt 1
{
count++;
if(count>CIRCLE)
{
count=1;
}
if(count<=last)
led=0;
else
led=1;
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
}
|