#include<reg51.h>
unsigned char pwhh,pwhl,pwlh,pwll
bit flag
sbit pwm=P1^0
void t0isr() interrupt 1
{
if(flag)
{
TH0=pwhh
TL0=pwhl
}
else
{
TH0=pwlh
TL0=pwll
}
pwm=~pwm
}
main()
{
TMOD=0x01
pwhh=(65536-1000)/256
pwhl=(65536-1000)%256
pwlh=(65536-500)/256
pwll=(65536-500)%256
TH0=pwhh
L0=pwhl
TR0=1
ET0=1
EA=1
while(1)
}
#include<reg51.h>#define uchar unsigned char
uchar pwm=50,cnt
sbit pluse=P1^0
sbit keyu=P1^4
sbit keyd=P1^5
void t0isr() interrupt 1
{
TH0=(65536-100)/256
TL0=(65536-100)%256
cnt++
if(pwm>0)
{
if(cnt>100)cnt=0
if(cnt<=pwm)pluse=1
else pluse=0
}
else pluse=0
}
main()
{
TMOD=0x01
TH0=(65536-100)/256
TL0=(65536-100)%256
TR0=1
ET0=1
EA=1
while(1)
{
if(keyu==0)
{
while(keyu==0)
pwm++
if(pwm>100)pwm=100
}
if(keyd==0)
{
while(keyd==0)
if(pwm>0)pwm--
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)