#include<reg52.h>
void init_sys(void); /*系统初始化函数*/
sbit P0_0=P0^0;
sbit P2_0=P2^0;
unsigned char ZKB1,ZKB2;
sbit P3_0=P0^0;
#define V_TH0 0XFF
#define V_TL0 0XF2
#define V_TMOD 0X01
void main()
{
init_sys();
ZKB1=80; /*占空比初始值设定*/
ZKB2=70; /*占空比初始值设定*/
while(1)
{
/*对占空比值限定范围*/
if (ZKB1>99) ZKB1=1;
if (ZKB1<1) ZKB1=99;
}
}
void init_sys()
{
TMOD=V_TMOD;
EA=1;
ET0=1;
TR0=1;
TH0=V_TH0;
TL0=V_TL0;
}
void timer0() interrupt 1 using 2
{
unsigned char click=0; /*中断次数计数器变量*/
TH0=V_TH0; /*恢复定时器初始值*/
TL0=V_TL0;
++click;
if (click>=100) click=0;
if (click<=ZKB1) /*当小于占空比值时输出低电平,高于时是高电平,从而实现占空比的调整*/
P0_0=0;
else
P0_0=1;
if (click<=ZKB2)
P2_0=0;
else
P2_0=1;
}