The following is the query working mode of the timer, and no interrupt request will occur:
#include
int main(void)
{
//8-bit timer time calculation T=(256-initial value) * pulse period
int i;
TCNT0 = 55; //Set the initial value
TCCR0 |= (1 << CS01); //8-division
for (i = 0; i < 10000; i++)
{
while(!(TIFR & TOV0)); //Judge the T/C0 overflow flag, automatically clear it after overflow, and no interrupt occurs.
}
}
In the following working mode, an overflow interrupt request will occur:
#include
#include
volatile unsigned int i = 0; //Note that volatile is required
int main(void)
{
//8-bit timer time calculation T=(256-initial value) * pulse period
TCNT0 = 55; //Set TC0 initial value
TIMSK |= (1 << TOIE0) //TC0 overflow interrupt enable
sei(); //Global interrupt enable
TCCR0 |= (1 << CS01); //8 division, start timer
while(1);
}
SIGNAL (SIG_OVERFLOW0) //TC0 overflow interrupt service routine
{
TCNT0 = 55; //Reset TC0 initial value
i++;
if (cnt >= 1000)
{
}
}
Previous article:ATMEGA128 PWM output series routines
Next article:AVR MCU GCC Programming: Basic Operation of External Interrupts
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- Fiber Optic Project Overview
- Bluetooth module problem
- Switching Power Supply Interest Group 13th Task
- Is the ST website down? Or is it crashing?
- How to Design a Low-Cost Bluetooth Music Playback System
- I would like to ask which other manufacturers have single-pole TMR switches, except MDT (only a model, but out of stock)?
- PIC16F684 IO port output problem
- The difference between building a system and building a module
- I'm a little confused. I want to stabilize the voltage at 3.3V. How should I choose the resistor and the voltage regulator?
- Beidou short board communication positioning development board