#include <reg52.h>
#include <function.h>//详见第六章第8讲
u8 T0RH, T0RL;
void
TIM0_Init(u32 us,
int
trim)
{
u32 tmp;
tmp = 11059200 / 12;
tmp = ( tmp * (us/100) )/10000;
tmp = 65536 - tmp;
tmp = tmp+trim;
T0RH = (unsigned
char
)(tmp>>8);
T0RL = (unsigned
char
)tmp;
TMOD &= 0xF0;
TMOD |= 0x01;
TH0 = T0RH;
TL0 = T0RL;
ET0 = 1;
TR0 = 1;
}
void
main()
{
u8 i,dir;
LED_Init();
EA = 1;
TIM0_Init(300,0);
while
(1)
{
if
(i<8)dir=0;
if
(dir==0)P0=~(0x01<<i);
if
(i>=8)dir=1;
if
(dir==1)P0=~( 0x80>>(i-7) );
i++;
if
(i>=15)i=1;
delay_ms(50);
}
}
void
TIM0_IRQHandler() interrupt 1
{
TH0 = T0RH;
TL0 = T0RL;
BEEP=!BEEP;
}