Home > other >  Two 51 single-chip microcomputer timer control buzzer make different voices
Two 51 single-chip microcomputer timer control buzzer make different voices

Time:11-25

Title: at the same time with two timer control buzzer 1 control frequency and timer timer 0 control with frequency, the duration of the interval of 2 s, a lose 1,10,50,100,200,400,800,1000 hz square-wave


My program is only the first two seconds of 1 hz, the other not possible, don't know what went wrong, trouble bosses have a look!


#include
#include
# define uchar unsigned char
# define uint unsigned int
Uint t0, t1, aa, bb, spin, tt, flag;
Sbit FM=P2 ^ 3;
Uchar code table1 []={1000100, 0100, 0100, 0500,50,5,500};//spin choice according to different hz
Uchar code table2 []={500,50,10,5,5,25,125,1};//according to the different spin calculated beforehand good vibrations of the number of each cycle
Void init ();
Void main ()
{the init ();
While (1) {};
}
Void init ()
{uint t0=0;
Uint t1=0;
Uint aa=0;
Uint bb=0;
Uint tt=0;
Uint flag=0;
TMOD=0 x11;
EA=1;
ET0=1;
ET1=1;
TL0=(65536-50000) % 256;
TH0=(65536-50000)/256;
TL1=(65536 - spin) % 256;
TH1=(65536 - spin)/256;
Spin=table1 (aa);
TR0=1;
TR1=1; }
Void timer0 () interrupt 1
{TL0=(65536-50000) % 256;
TH0=(65536-50000)/256;
T0 + +;
If (t0==40)
{t0=0; Aa++; Bb++; }
If (aa==8)
{TR0=0;
flag=1;
}
}
Void timer1 interrupt ()
3{spin=table1 (aa);
Tt=table2 (bb);
TL1=(65536 - spin) % 256;
TH1=(65536 - spin)/256;
T1 + +;
If (t1==tt)
{t1=0;
FM=~ FM.
}
If (flag==1)
TR1=0;
}

CodePudding user response:

Control 1 second output different square wave don't need two timer, a timer with enough,

CodePudding user response:

Don't look, there is a clear mistake
Uchar biggest 255, table1 and table2 uint instead

CodePudding user response:

refer to the second floor forget345 response:
didn't look, there is a clear mistake
Uchar maximum 255, table1 and table2 instead uint

Thanks for reply, I was too careless,
  • Related