/************************************************
This function will continuously generate a 38KHZ square wave at the P3^0 port of the microcontroller.
**********************************************/
#include
sbit P3_0=P3^0;
void main()
{
TMOD = 0x02; //TMOD is the timer mode control register, here timer 0 is selected, working in mode 2
TL0 = 0xF3; //Timer initial value
TH0 = 0xF3; //Timer initial value
EA = 1; // Enable general interrupt
ET0 = 1; // Enable CPU interrupt and T0 interrupt
TR0 = 1; //Start the timer
while(1);
}
void time0_int(void) interrupt 1 //Timer 0 interrupt service routine. Except for the function name, the other parts should be written in this format.
{
P3_0 = ~P3_0;
}
/*
******Calculation of initial value of timer************
If timer 0 is used, working in mode 1:
(2^8 - X)*oscillation period*12 = timing time
The crystal oscillator I use here is 12MHZ, that is, the oscillation period is 1/12MHZ = 1 microsecond.
To generate a 38KHZ square wave, that is, 1/38KHZ = 26 microseconds, the timer should be set to 13 microseconds to ensure that a square wave with a period of 26 microseconds can be generated at P3^0. The initial count value X = 253 (0xF3)
*/
/*
***************Timer Mode Selection*******************
The timer has four working modes. In principle, it can work in any mode, but working in mode 2 is more accurate and has a smaller error. This is because the timer in mode 2 has the feature of automatically reloading the initial value.
*/
/*
********Writing of interrupt service routine***********
void function name() interrupt interrupt number
{
}
Interrupt number
0 External interrupt 0
1 Timer 0
2 External interrupt 1
3 Timer 1
4 Serial interrupt
Here we use timer 0, so the interrupt function is written as
void void time0_int(void) interrupt 1
{}
*/
/*
********Start and stop the timer**********
As long as TR0 = 1, timer 0 is started, and TR0 = 0, timer 0 is stopped.
*/
Previous article:USB debugging for C8051F320
Next article:About C51 absolute addressing
Recommended ReadingLatest update time:2024-11-25 13:28
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- Automechanika Shanghai 2024 to feature a record number of concurrent events, bringing together industry wisdom and planning for future development
- Corporate Culture Sharing: How to cultivate scarce silicon IP professionals? SmartDV's journey of personal growth and teamwork
- Corporate Culture Sharing: How to cultivate scarce silicon IP professionals? SmartDV's journey of personal growth and teamwork
- NXP releases first ultra-wideband wireless battery management system solution
- NXP releases first ultra-wideband wireless battery management system solution
- Beijing Jiaotong University undergraduates explore Tektronix's advanced semiconductor open laboratory and experience the charm of cutting-edge high technology
- Beijing Jiaotong University undergraduates explore Tektronix's advanced semiconductor open laboratory and experience the charm of cutting-edge high technology
- New CEO: Dr. Torsten Derr will take over as CEO of SCHOTT AG on January 1, 2025
- How Edge AI Can Improve Everyday Experiences
- How Edge AI Can Improve Everyday Experiences
- Circuit diagram of motor control development board based on dsPIC30F4011
- Linux-3.14.52 Compiler Reference Manual v2.0
- GCC macro function definition example
- ESP32 firmware is divided into two versions: ESP-IDF v3.x/4.x
- Two methods of programming TMS320C6748
- Enabling higher-performance front-end radar to make Vision Zero a reality
- MSPFET430UIF emulator self-made data
- Power supply control principle of three-phase fuel pump used in Mercedes-Benz passenger cars
- Jackie Chan and Jet Li co-star in a movie
- Review summary: Free review of Fudan Micro FM33LG0 series, Winsilver chip