#include<reg51.h>
#define uchar unsigned char
uchar time;
sbit spk=P1^0;
void t0isr() interrupt 1
{
TH0=t_h;
TL0=t_l;
spk=~spk;
}
void t1isr() interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
time++;
time%=6;
if(time==0)
{
t_h=(65536-500)/256;
t_l=(65536-500)%256;
}
if(time==2)
{
t_h=(65536-1000)/256;
t_l=(65536-1000)%256;
}
}
main()
{
TMOD=0x11;
t_h=(65536-500)/256;
t_l=(65536-500)%256;
TH0=t_h;
TL0=t_l;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
TR0=1;
TR1=1;
ET0=1;
ET1=1;
EA=1;
while(1);
}
温馨提示:答案为网友推荐,仅供参考