/***********************************************************
* Library Description: ATMEGE8 Delay Library Function
* Version: v1.0
*
************************************************************
*Note: LED PC5
***********************************************************/
#include
//Define external crystal
#define F_CPU 6000000UL
// Delay including header files
#include
// Function declaration
void Delay_s(int ss);
int main(void)
{
//LED etc. PC5 is set as output
DDRC |= (1 << DDC5);
//Start with PC5 outputting high level, LED is off
PORTC |= (1 << PC5);
while(1)
{
//Return
PORTC ^= (1 << PC5);
//Delay 1s
Delay_s(1);
}
return 0;
}
/***********************************************************
** Name: void Delay_s(int ss)
** Function: Accurate 1s delay
** Input parameter: ss The number of seconds to delay
** Export parameters: None
** Instructions: System library function delays are limited by the size of the crystal oscillator
***********************************************************/
void Delay_s(int ss)
{
int i = 0;
while(ss--)
{
for(i = 0; i < 25; i++)
{
_delay_ms(40);
}
}
}
//First, F_CPU (i.e., crystal frequency) is no longer defined in the library file
// And the system delay function has restrictions on the delay size due to different crystal oscillators, please note:
/**
\ingroup util_delay
Perform a delay of \c __us microseconds, using _delay_loop_1().
The macro F_CPU is supposed to be defined to a
constant defining the CPU clock frequency (in Hertz).
The maximal possible delay is 768 us / F_CPU in MHz.
*/
/**
\ingroup util_delay
Perform a delay of \c __ms milliseconds, using _delay_loop_2().
The macro F_CPU is supposed to be defined to a
constant defining the CPU clock frequency (in Hertz).
The maximal possible delay is 262.14 ms / F_CPU in MHz.
*/
Previous article:atmega8 example: 5110 LCD driver
Next article:atmega8 example: USART serial communication
Recommended ReadingLatest update time:2024-11-16 16:01
- Popular Resources
- Popular amplifiers
- 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)
- Signal Integrity and Power Integrity Analysis (Eric Bogatin)
- RT-Thread Kernel Implementation and Application Development Practical Guide: Based on STM32
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
- DGUS T5UID1 implements modbus protocol
- 【Goodbye 2021, Hello 2022】+ My summary of 2021
- Super detailed teaching you to use HFSS to design and simulate inverted F antenna 3
- Keil's optimization is really a rip-off
- [Zero-knowledge ESP8266 tutorial] Quick Start 2- Light up the external LED
- [Embedded Linux] RK3568 Android 11 screen point process
- Xiaoyi H8 camera, V831 vest QG2101
- Negative feedback bandwidth broadening
- Cyclone pin constraints
- 【Smart Network Desk Lamp】5. ESP32-S2 uses sntp for network time synchronization