The file consists of: test program
/* *****************************************
* File name: main.c
* Function: 8-bit timer overflow interrupt mode test program
* Description: The timer controls the LED to flash at 500ms intervals
* Author & Date: Joshua Chan, 2012/03/24
* *****************************************/
#include
#include
#include
#include "timer_8bit_test1.h"
/* Use timer0 overflow interrupt to control the LED to flash every 500ms */
void main(void)
{
set_pb0_output();
timer0_ovf_init();
_SEI(); /* Global interrupt enable */
while (1)
_WDR();
}
/* *****************************************
* File name: timer_8bit_test1.h
* Function: 8-bit timer overflow interrupt mode test program
* Description: The timer controls the LED to flash at 500ms intervals
* Author & Date: Joshua Chan, 2012/03/24
* *****************************************/
#ifndef _TIMER_8BIT_TEST1_H
#define _TIMER_8BIT_TEST1_H
/* Configure 8-bit timer timer0 overflow interrupt enable */
extern void timer0_ovf_init(void);
/* Configure LED pin as output */
extern void set_pb0_output(void);
/* LED on */
extern void set_pb0_low(void);
/* LED off */
extern void set_pb0_high(void);
/* Detect LED status */
extern unsigned char pb0_is_high(void);
#endif
/* ***************************************** * File name: timer_8bit_test1.c * Function: 8-bit timer overflow interrupt mode test program * Description: The timer controls the LED to flash at 500ms intervals * Author & Date: Joshua Chan, 2012/03/24 * *****************************************/ #include#include #include #include #include #include "timer_8bit_test1.h" /* Configure 8-bit timer timer0 overflow interrupt enable */ void timer0_ovf_init(void) { TCCR0 |= 0x07; /* Prescaler 1024 */ TIMSK |= 0x01; /* Overflow interrupt enable*/ TCNT0 = 0x64; /* Interrupt interval ((0xFF-0x64)+1)*1024*(1/16.0MHz)*1000 = 10ms */ } /* Configure LED pin as output */ void set_pb0_output(void) { DDRB |= 0x01; } /* LED turns on */ void set_pb0_low(void) { PORTB &= ~(0x01); } /* LED off*/ void set_pb0_high(void) { PORTB |= 0x01; } /* Check LED status */ unsigned char pb0_is_high(void) { return (PORTB & 0x01); } /* Define timer0 overflow interrupt processing function*/ #pragma vector = TIMER0_OVF_vect __interrupt void timer0_isr(void) { static volatile unsigned char count = 50; TCNT0 = 0x64; /* The TCNT0 value needs to be reset in the overflow interrupt processing function*/ if (!(--count)) { count = 50; if (pb0_is_high()) set_pb0_low(); else set_pb0_high(); } }
Previous article:Programming Tips: 8-bit AVR timer compare match interrupt test program
Next article:Programming Tips: AVR External Interrupt Test Program
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
- Do the read and write registers of the ds2438 coulomb meter have a lifespan?
- Raspberry Pi based smartphone
- Share WB-Serial Port Debugging Assistant
- About bus conflicts (Part 2)
- PMOS is turned on
- CCS compiles and generates binary files
- Mobile phone calculators are all dead: What is 10% + 10%? [Have you ever calculated it?]
- When the serial port is connected, if the host receives wrong data, it will return to the initial state.
- How to set the temperature of the battery temperature detection pin TS of BQ24650 to -10℃-50℃
- Summary of DSP CMD file writing method