1. Turn off the timer module
When the TEN bit of TSCR1 is 0;
2. Set IOSx as output compare pin (taking 7 as an example)
TIOS_IOS7 = 1;
3. Binding Output Compare Pins
TCTL1_OM7 = 0;
TCTL1_OL7 = 1;
4. Set the comparison value of the counter (under 24Mhz system time, 0xBB is 1ms) interrupt period: 0x4926*128/24MHz = 100ms
TC7 = 0xBB;
5. Set the timer frequency division setting (taking 128 frequency division as an example)
TSCR2_PR = 0x7;
6. Set the timer to output after successful comparison to generate an interrupt
TSCR2_TCRE = 1;
7. Finally, start the timer
TSCR1_TEN = 1;
8. The interrupt function should be written as
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt VectorNumber_Vtimch7 TIM7_ISR(void)
{
// And clear the flag after each interrupt
TFLG1 =128U;
}
Code
void OutputCompare_Init(void)
{
TSCR1_TEN = 0; /* Disable Timer module before adjusting registers. */
TIOS_IOS7 = 1; /* Set Channel 0 as output compare. */
TCTL1_OM7 = 0; /* Set channel 0 to toggle when a Timer match occurs. */
TCTL1_OL7 = 1; /* Set channel 0 to toggle when a Timer match occurs. */
TC7 = 0xBB; /* Set a value for channel 0 timer compare. */
TIE_C7I = 1; /* Enable channel 0 interrupt, handled by function TIM0ISR. */
TSCR1_TSWAI = 1; /* Disables the timer module while in wait mode. */
TSCR1_TSFRZ = 1; /* Disables the timer counter while in freeze mode. */
TSCR2_PR = 0x7; /* Set prescaler to divide by 128 */
TSCR2_TCRE = 1;
TSCR1_TEN = 1; /* Timer Enable. */
//Interrupt period: 0x4926*128/24MHz = 100ms
}
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt VectorNumber_Vtimch7 TIM7_ISR(void)
{
TFLG1 =TFLG1_C7F_MASK; /* Clear channel 0 flag. */
PORTB ^= bit4;
}
Previous article:Notes on transplanting MC9S08DZ60 to ucos
Next article:Freescale 9s12xs128 interrupt declaration in multiple ways
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Brief Analysis of Automotive Ethernet Test Content and Test Methods
- How haptic technology can enhance driving safety
- General welding specifications for MINI manufacturers
- Why constant current source simulation does not produce constant current
- [National Technology N32G457 Review] 1. Unboxing + Lighting
- The second article is a simple comparison between GD32VF103C START and ST official routines
- [GD32L233C-START Review] Part 3 PWM driving breathing light
- 【AT-START-F425 Review】 5. Brief analysis of timer interrupt code and implementation of breathing light
- Understanding GaN Thermal Analysis
- CC2652LP driving Δ∑ ADC - ADS1261
- Toyota car machine disassembly suitable for DIY modification
- EEWORLD University Hall----Nonlinear Control Systems