The STC10F10XE timer interrupts the output of a 10 kHz square wave program, and stc10f10xe10khz

Source: Internet
Author: User

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

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.