The STC10F10XE timer interrupts the output of a 10 kHz square wave program, and stc10f10xe10khz
// The hardware is also used to test the program. In order to test the new motor drive board, a 51 board is found as a 10 k signal generator to test the time delay of the IGBT switch.
# Include <STC_NEW_8051.H>
# Include <intrins. h>
# Define uchar unsigned char
// This T0 timer interrupt program was found online, changed the definition and counter value, and transplanted to STC10F10XE.
Sbit OUT = P2 ^ 7; // defines the OUT output port
/*------------------------------------------------
Timer initialization subroutine
------------------------------------------------*/
Void Init_Timer0 (void)
{
TMOD | = 0x01; // use Mode 1, 16-bit timer, use the "|" symbol can be used when multiple timers are not affected
// TH0 = 0x00; // given the initial value, the maximum value of the timer is counted from 0 to 65535 overflow.
// TL0 = 0x00;
EA = 1; // open the total interrupt
ET0 = 1; // The timer is disconnected.
TR0 = 1; // The timer is enabled.
}
/*------------------------------------------------
Main Program
------------------------------------------------*/
Main ()
{
CLK_DIV = 0x00; // do not divide
P2M1 = 0x00; // push/pull output of P2 Port
P2M0 = 0xff; // port P2 pushes the output
Init_Timer0 ();
While (1 );
}
/*------------------------------------------------
Timer interrupt subroutine
------------------------------------------------*/
Void Timer0_isr (void) interrupt 1 using 1
{
TH0 = 255; // assign a new value to the 11.0592M crystal oscillator. The 10 kHz waveform output is tested by the oscilloscope.
TL0 = 211 ;//
// Overflow and reverse output
OUT = ~ OUT; // use an oscilloscope to view the square wave output
}