AVR C statement run time test program source code

Publisher:二进制游侠Latest update time:2016-10-08 Source: eefocusKeywords:AVR Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Download the entire project:
http://www.rayfile.com/zh-cn/files/b8f67659-d773-11df-b350-0015c55db73d/f0ec1fdf/
 
 
Core code:
/********** AVR Run Time Test Program**********
* 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++;
}
 
 
Test results:
AVR C statement running time test program source code - Ear - Ear's Blog
 
Keywords:AVR Reference address:AVR C statement run time test program source code

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

Intelligent control system designed by AVR single chip microcomputer, data acquisition module and control circuit
  introduction   As the focus of the development of production process automation, fieldbus has played a huge role in promoting automation technology and is a symbol of modern industry. As a communication protocol of fieldbus, MODBUS realizes communication and information exchange between PLC controllers, industrial c
[Microcontroller]
Intelligent control system designed by AVR single chip microcomputer, data acquisition module and control circuit
Intelligent anti-theft and fire warning system based on AVR32
Introduction: This project uses Atmel's AVR32 AT32UC3A processor as the core and uClinux operating system as the platform. It uses a wide-angle camera to collect video (or images) and uses algorithms to implement functions such as face recognition (indoor anti-theft) or flame recognition (outdoor fire prevention). 1
[Microcontroller]
Intelligent anti-theft and fire warning system based on AVR32
LCD1602 Liquid Crystal Display Module In-depth Explanation of Software (AVR)
Although the driver of LCD1602 liquid crystal display module is more complicated than the display of seven-segment digital tube, it is not very difficult in fact. The most important thing is initialization. Why do we say that? When we debug a new LCD screen, we will initialize it first to see if there is a cursor flas
[Microcontroller]
LCD1602 Liquid Crystal Display Module In-depth Explanation of Software (AVR)
AVR MCU Tutorial - Digital Tube
Let’s first answer a previous question: If the pin is not configured as an output and a high level is written, what will happen if an LED is connected? The experimental result is that the LED lights up, but the brightness is very low compared to the case of high output level. Why is this? From the previous tutoria
[Microcontroller]
AVR MCU Tutorial - Digital Tube
Check out this article about the MCU bit configuration of AVR
Introduction: The configuration of AVR fuse bits is a relatively delicate task, and users often overlook its importance or find it difficult to master. Here are some key points and related matters that need to be paid attention to when configuring AVR fuse bits. Correctly configure the AVR fuse bits (1) In the AVR
[Microcontroller]
AVR microcontroller power failure detection function
      When the system is powered off, the power supply voltage will fluctuate for a certain period of time. If you do not handle it, you will find that the MCU will automatically reset and restart, and then execute a certain time value until the system is completely powered off. This will basically happen, especially f
[Microcontroller]
PORT.H header file download - AVR timer general IO port definition
/*****************************************************************************       File name: PORT.H       File ID: _PORT_H_       Abstract: AVR timer general IO port definition *****************************************************************************/ #ifndef  _PORT_H_ #define  _PORT_H_ #define P(X,Y) (B
[Microcontroller]
Harmful gas infrared sensing and voice warning control system based on AVR microcontroller
0Introduction The infrared sensing system is used to sense whether there are harmful gases nearby. When the infrared sensing system senses that harmful gases are approaching, it sends a high level that lasts for a period of time. The single-chip microcomputer starts the voice chip by opening an interrupt. The s
[Microcontroller]
Harmful gas infrared sensing and voice warning control system based on AVR microcontroller
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号