#includereg52.h#defineuintunsignedint#defineucharunsignedchar#defineHIGH10//HIGH与ALL的比值为占空比#defineALL20//ALL为周期时间,即20ms,改变数值即可改变周期sbitout=P1^0;uinttt;voidmain(){TMOD=0x01;//设置定时器0为工作方式1TH0=(65536-1000)/256;//设置初值TL0=(65536-1000)%256;EA=1;//开总中断ET0=1;//开定时器0中断TR0=1;//启动定时器0out=1;while(1);}voidtimer0()interrupt1{TH0=(65536-1000)/256;//重装初值TL0=(65536-1000)%256;tt++;if(tt==HIGH)out=0;if(tt==ALL){out=1;tt=0;}}/*THATISALL.THANKYOU.*/