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 mistakeUchar biggest 255, table1 and table2 uint instead
CodePudding user response: