#include <reg52.h>
#include <function.h>//详见第六章第8讲
#include <timer.h> //详见第八章第11讲
sbit PWMOUT = P1^7;
u16 highval=15;
void
main()
{
u8 key;
LED_Init();
KEY_Init();
EA = 1;
TIM0_Init(100,9);
TIM1_Init(1000,0);
ShowNumber(highval);
while
(1)
{
key=KEY_Scan(1,500);
if
(key==8)
{
highval++;
if
(highval>25)highval=25;
ShowNumber(highval);
}
if
(key==16)
{
highval--;
if
(highval<5)highval=5;
ShowNumber(highval);
}
}
}
void
TIM0_IRQHandler() interrupt 1
{
static
u8 pwm=0;
TH0 = T0RH;
TL0 = T0RL;
pwm++;
if
(pwm>=200)pwm=0;
if
(pwm<highval)PWMOUT=1;
else
PWMOUT=0;
}
void
TIM1_IRQHandler() interrupt 3
{
TH1 = T1RH;
TL1 = T1RL;
SEG_Scan();
}