#include
sbit LED_0 = P1^0;
sbit LED_1 = P1^1;
unsigned Pwm = 0; // 操控 LED_0 的有暗到亮 其间LED_1 作为比照
unsigned Count=0;
void Time_Init(void)
{
TMOD = 0x02; //守时器0 守时,方法2
TH0 = 0x9c; //100us
TL0 = 0x9c;
EA = 1;
ET0 = 1;
TR0 = 1;
}
void Int0_Init(void)
{
IT0=1; //设置下降沿触发
EA=1; //开总中止
EX0=1; //开外部中止
}
void Int1_Init(void)
{
IT1=1; //设置下降沿触发
EA=1; //开总中止
EX1=1; //开外部中止
}
void main(void)
{
Time_Init();
Int0_Init();
Int1_Init();
LED_0 = 0;
LED_1 = 0;
while(1);
}
void INT_Time0() interrupt 1 using 1
{
Count++;
if(Count==100)
{
Count=0;
}
if(Count<=Pwm)
{
LED_0 = 0;
}
else
{
LED_0 = 1;
}
}
void Int0() interrupt 0
{
if(Pwm<=94)
{
Pwm=Pwm+5; //此刻占空比为Pwm/100
}
else
{
Pwm=99;
}
}
void Int1() interrupt 2
{
if(Pwm>=5)
{
Pwm=Pwm-5;
}
else
{
Pwm=0;
}
}
声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/qianrushi/261411.html