sbit sg90_con = P3^6;
int jd;
int cnt =0;
void Delay2000ms() //@11.0592MHz
{
unsigned char i, j, k;
i = 15;
j = 2;
k = 235;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
void Delay300ms() //@11.0592MHz
{
unsigned char i, j, k;
_nop_();
i = 3;
j = 26;
k = 223;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
void Timer0Init(void) //500微秒@11.0592MHz
{
TMOD =0x01; //设置定时器模式
TL0 = 0x33; //设置定时初值
TH0 = 0xFE; //设置定时初值
TF0 = 0; //清除TF0标志
TR0 = 1; //定时器0开始计时
EA =1;
ET0 =1;
}
int main()
{
Delay300ms();
Timer0Init();
jd =1;
cnt =0;
sg90_con = 1;
while(1) {
jd =4;
cnt =0;
Delay2000ms();
jd =1;
cnt =0;
Delay2000ms();
}
return 0;
}
void Time0Handler() interrupt 1
{
cnt ++;
TL0 = 0X33;
TH0 =0XFE;
if(cnt < jd ) {
sg90_con = 1;
} else {
sg90_con = 0;
}
if(cnt == 40) {
cnt = 0;
sg90_con =1;
}
}