//*f=6MHZ, timer 0 generates 100us timing in working mode 2 (auto-reload 8-bit timer mode) and query mode,
Keywords:Timer
Reference address:Use the timer to control the LED light, turn on for 1 second and turn off for 1 second
//And output a continuous square wave r with a period of 2s at P0.0 to control the LED light, that is, on for 1s and off for 1s*// #includesbit d1=P0^0; void timer(); unsigned int num,tt; void main() { TMOD=0X02; //Adjust working mode// TH0= 0Xce; //Set initial value TL0=0Xce; IE=0X00; //Disable interrupt TR0=1; //Timer start while(1) //Large loop { if(num==10000) //This big loop must be added, otherwise the program starts from the beginning and all variables are reset. //The value of d1 remains unchanged, because num is always 0 here // d1=!d1; // You can also put these three sentences after the timing program, so that after the timing program, the value of num is 10000, //When the required timing is reached, (it is not reset because the program is not completed)// num=0; // After that, output d1 will change as required// while(num<10000) //100us timing program { if(TF0) //Check whether the 100us timing has arrived? // timer(); } } } void timer() { TF0=0; //The query method must be cleared by software, otherwise TF will always overflow to 1, and the timing will only be accurate for the first time// num++; }
Previous article:LED pattern lamp test-C51 program
Next article:Inversion matrix keyboard
Recommended ReadingLatest update time:2024-11-16 13:25
PIC16F15323 microcontroller (interrupt and timer Timer0)
The development environment selected is MPLAB X IDE v5.50 and xc8-v2.32-full-install-windows-x64-installer. 1 Basic principles 2 Implementation Code The code is mainly written based on FIGURE 25-1 and the interrupt logic block diagram, so that the code is readable and easy to understand. However, some registe
[Microcontroller]
C51 MCU's precise delay program (Timer)
Using timer/counter to achieve accurate delay Single-chip microcomputer systems generally use 11.059 2 MHz, 12 MHz or 6 MHz crystal oscillators. The first one is easier to generate various standard baud rates, and the machine cycles of the latter two are 1 μ s and 2 μ s respectively, which is convenient for accurate d
[Microcontroller]
Cortex M3S811 Study Notes-TIMER32
Today, we have clarified the timing functions under 32-bit. First of all, there are only three functions under 32-bit, 32-bit single-cycle timing, 32-bit multi-cycle timing, and an RTC that requires an external clock. We will not use RTC for the time being, so ignore it.
Grasp the overall situation, it is a timer us
[Microcontroller]
Recommended Content
Latest Microcontroller Articles
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
MoreDaily News
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
Guess you like
- DAPLink Upgrade to 0253
- PCB panelization skills
- Microchip Q&A | New MCU Core Independent Peripheral (CIP) Technology Decryption
- Various CCS compilation errors
- CCS project loading and debugging
- How did you electronic design engineers grow up?
- Whenever there is a heavy rainstorm, I face frequent network outages.
- An FPGA frequency multiplier problem
- [Review of Arteli Development Board AT32F421] 2. Read the MCU model
- TE official WeChat manual customer service function is now online. You can communicate directly with TE technical experts via WeChat!