* Version..........: 1.0
* Author..........: Chen Lidong
* Target.......: ATmega128
* File Name..........: main.c
* Compiler..........: IAR for AVR V5.5
* Created on.....: 2010.10.14
* Last Modified on.....: 2010.10.14
******************************************/
#include "main.h"
int putchar(int c)
{
return uart_putchar(c);
}
volatile unsigned int TimerOverflowCount = 0;
int main(void)
{
unsigned long TimerCount = 0;
UART_Init();
printf("*********** Run Time Test***********\r\n");
printf("Build: %s %s\r\n", __DATE__, __TIME__);
printf("Clock frequency: %fMHz\r\n", (float)F_CPU / 1000000);
TCCR1B_CS10 = 1; // Timer 1 enables counting, no frequency division
TIMSK_TOIE1 = 1; // Timer 1 enables overflow interrupt
__enable_interrupt(); // Total interrupt enable
TimerOverflowCount = 0; // Overflow count cleared
TCNT1 = 0; // Counter cleared
/* Insert the code to be run here*/ /
* Code starts*/
_delay_us(123456);
/* Code ends*/
TCCR1B_CS10 = 0; // Timer 1 stops counting and takes 3 clock cycles
TimerCount = TCNT1;
TimerCount |= ((unsigned long)TimerOverflowCount << 16);
TimerCount -= 3; // Timer off time
TimerCount -= (50 * TimerOverflowCount); // Overflow interrupt time
printf("Consumed clock cycles...: %ld 0x%lx\r\n", TimerCount, TimerCount);
printf("Consumed time (unit: s): %lf\r\n", (double)1 * TimerCount / F_CPU);
printf("Consumed time (unit: ms): %lf\r\n", (double)1000 * TimerCount / F_CPU);
printf("Consumed time (unit: us): %lf\r\n", (double)1000000 * TimerCount / F_CPU);
printf("Consumed time (unit: ns): %lf\r\n", (double)1000000000 * TimerCount / F_CPU);
while (1);
}
#pragma vector = TIMER1_OVF_vect
__interrupt void Timer1_Overflow(void)
{
TimerOverflowCount++;
}
Previous article:AVR single DS18B20 temperature reading program (can measure negative temperature)
Next article:AVR serial port transmission and reception using ring buffer program source code
Recommended ReadingLatest update time:2024-11-16 14:37
- Popular Resources
- Popular amplifiers
- Principles and Applications of Single Chip Microcomputers 3rd Edition (Zhang Yigang)
- Metronom Real-Time Operating System RTOS for AVR microcontrollers
- Learn C language for AVR microcontrollers easily (with video tutorial) (Yan Yu, Li Jia, Qin Wenhai)
- ATmega16 MCU C language programming classic example (Chen Zhongping)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- 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
- 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
- 【New Year's Flavor Competition】Busy Spring Festival
- BMP picture decoding system based on STM32
- Design of smart home based on Linux operating system
- [NXP Rapid IoT Review] + Unboxing the real thing brings back a lot of thoughts!
- TMS320F28335 startup process
- How to analyze the principle of totem pole circuit?
- Encoder Problems
- How does TI's MSP430 microcontroller (MCU) achieve both low power consumption and high performance?
- Share the method of deleting dangling line and via
- TI's active-clamp flyback controller is said to halve the size of power supplies