#include <reg52.h>
#include <function.h> //详见第六章第8讲
#include <timer.h>
u8 pwm=0,highval=99;
void
main()
{
LED_Init();
EA = 1;
TIM0_Init(100,9);
TIM1_Init(10000,10);
while
(1)
{
if
(pwm<highval)P0=0xFF;
else
P0=0x00;
}
}
void
TIM0_IRQHandler() interrupt 1
{
TH0 = T0RH;
TL0 = T0RL;
pwm++;
if
(pwm>=100)pwm=0;
}
void
TIM1_IRQHandler() interrupt 3
{
static
u8 dir;
TH1 = T1RH;
TL1 = T1RL;
if
(dir==1)highval--;
if
(highval==0)dir=0;
if
(dir==0)highval++;
if
(highval>=99)dir=1;
}