1. Experimental purpose
Through experiments, master the use of timers, especially the use of timer interrupts!
2. Experimental content
1 Use the timer0 of the Mega16 microcontroller to generate a 1ms interval timer interrupt (it is recommended to use the application builder, which can use both the Normal working mode and the CTC mode). (1) Implement dynamic refresh of the 4-bit digital tube in the timer interrupt. (2) Design a 100mS time flag in the 1ms timer interrupt, query the time flag in the main program, and realize LED flashing.
2 Reconfigure TImer0 to work in PWM mode, use the buttons to change the PWM duty cycle and adjust the motor speed;
3. Experimental preparation requirements
Carefully read the examples of timed interrupts in the textbook;
4. Experimental steps
1 Start ICCAVR, create a project file, configure timer0, implement a 10ms timer interrupt, and use Application Builder to generate initialization code. Note: The IO ports used in this experiment must also be initialized, including the IO used by the digital tube driver, buttons, etc.
2. Implement the timed refresh of the four-digit digital tube in the timed interrupt (Note: use the driver of HC595 from the last lab class), and implement the 100ms time mark (time stamp) in the timed interrupt, query the time stamp in the main program, and realize the flashing of the LED (any LED of PORTC port can be used);
3 Reconfigure TImer0 to work in PWM mode, set the initial duty cycle to 10%, and then use the button INT1 (SW8 in the schematic diagram, connected to the PD3 pin of the microcontroller) to change the duty cycle. For example, each time the button is pressed, the duty cycle increases by 10%.
Note: The pins used in the experiment are: PD4, PD5, PD6, PD7, PB0, PB1, PA0, PD3. Please refer to the schematic diagram for the connection of each pin.
Experiment 3: Timer application experiment
Content of report
1. Purpose
Through experiments, master the use of timers, especially the use of timer interrupts!
2 Experimental content
1. Use the timer0 of the Mega16 microcontroller to generate a 1ms interval timer interrupt (it is recommended to use the application builder, which can use both the Normal working mode and the CTC mode). (1) Implement dynamic refresh of the 4-digit digital tube in the timer interrupt. (2) Design a 100mS time flag in the 1ms timer interrupt, query the time flag in the main program, and realize LED flashing.
2. Reconfigure TImer0 to work in PWM mode, use the buttons to change the PWM duty cycle and adjust the motor speed;
3 Use the timer0 of the Mega16 microcontroller to generate a timer interrupt with an interval of 1ms (it is recommended to use the application builder, which can use both Normal working mode and CTC mode). Write the working mode used and the values of each timer register.
#include #include void port_init(void) { PORTA = 0x00; DDRA = 0x00; PORTB = 0x00; DDRB = 0x00; PORTC = 0x00; //m103 output only DDRC = 0x00; PORTD = 0x00; DDRD = 0x00; } //TIMER0 initialize - prescale:8 // WGM: CTC // desired value: 1000Hz // actual value: 992.063Hz (-0.8%) void timer0_init(void) { TCCR0 = 0x00; //stop TCNT0 = 0x83; //set count OCR0 = 0x7D; //set compare match TCCR0 = 0x0A; //start timer } //call this routine to initialize all peripherals void init_devices(void) { //stop errant interrupts until set up CLI(); //disable all interrupts port_init(); timer0_init(); MCUCR = 0x00; GICR = 0x00; TIMSK = 0x00; //timer interrupt sources SEI(); //re-enable interrupts //all peripherals are now initialized } 4. Implement dynamic refresh of 4-digit digital tube in timer interrupt. (Only write out the code related to timer interrupt, this part will borrow the driver function of HC595 implemented in the last lab class) 5. Design a 1000mS time flag in the 1ms timer interrupt, query the time flag in the main program, and use the stopwatch function. (Only write the timer interrupt service program and the function code to implement the stopwatch)
Previous article:Getting started with the first 74HC595 driver in C language
Next article:NEC infrared remote control signal decoding program based on attiny13
Recommended ReadingLatest update time:2024-11-16 13:28
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
- Introduction to the method of board-level online compilation and downloading of C6000 DSP code
- Tiny technology, global impact: Breakthrough TI BAW resonator technology creates a new electronic heartbeat
- Could you please tell me which manufacturers produce magnetic resistance switches? I only found one.
- Field Effect Transistor Basics and Application Practice
- Verilog Golden Reference Guide Chinese version.pdf
- [ART-Pi Evaluation] V: ATT-Pi WiFi networking and MQTT publishing and subscription evaluation in RTT Studio environment
- A chart to understand China Telecom's "5G SA Deployment Guide"
- Art on Silicon (3)
- MSP430F5529 multi-channel PWM output control servo and motor
- Discrete Difference Amplifiers vs. Integrated Solutions