/*****************************************************************
** Function description: xs128 dual timer PIT0 and PIT1
** Version: V1.00
**Revised by: Pang Hui, Wuhu Lianda Freescale Studio
** Modified on: September 19, 2011
**
** Description: PLL frequency is multiplied to 80Mhz, PB0 port light flashes for 1s, PB1 port light flashes for 2s
**
** Version update: see readme.txt for details
**
******************************************************************
**Note: LED1 lights PORTB0
** LED2 PORTB1
******************************************************************/
#include #include "derivative.h" /* derivative-specific definitions */ /*********************************************************** ** Name: void PLL_Init(void) ** Function: PLL phase-locked loop module initialization ** Input parameters: None ** Export parameters: None ** Instructions for use: 80MHz ************************************************************/ void PLL_Init(void) { CLKSEL = 0X00; PLLCTL_PLLON = 1; SYNR =0xc0 | 0x09; //80M REFDV=0x80 | 0x01; //SYNR =0xc0 | 0x04; //40M //REFDV=0x80 | 0x01; POSTDIV = 0x00; //pllclock=2*osc*(1+SYNR)/(1+REFDV)=160MHz; //BUS CLOCK=80M _asm(nop); //No operation, simple delay, waiting for the response of the phase-locked loop _asm(nop); while(!(CRGFLG_LOCK==1)) { _asm(nop); } CLKSEL_PLLSEL = 1; } /*********************************************************** ** Name: void PIT_Init(void) ** Function: Initialize PIT timing module ** Input parameters: None ** Export parameters: None ** Instructions for use: PIT0 1ms timing ** PIT1 8ms timing ************************************************************/ void PIT_Init(void) { PITCFLMT_PITE=0; //Close PIT // Loading register of micro timer PITMTLD0 = 80-1; //8-bit timer initial value setting. 80 division, under 80MHzBusClock, is 1MHz, i.e. 1us //PITMTLD1= 160-1; //8-bit timer initial value setting, 160 division, at 16MHz bus clock frequency, 0.1MHz, i.e. 10us //Timer loading register PITLD0 = 1000 - 1 ;//1ms PITLD1 = 8000 - 1; // Timing 8ms PITCE_PCE0=1; //Enable channel 0 PITCE_PCE1=1; //Enable channel 1 PITMUX_PMUX0=0; //0: The corresponding 16-bit timer is connected to micro time base 0 //PITMUX_PMUX1=1; //1: The corresponding 16-bit timer is connected to micro time base 1 PITINTE_PINTE0=1; // Enable the overflow interrupt of PIT0 timer PITINTE_PINTE1=1; // Enable the overflow interrupt of PIT1 timer PITCFLMT_PITE=1; //Enable PIT } /*********************************************************** ** Name: void main(void) ** Function: Main function ** Input parameters: None ** Export parameters: None ** Instructions for use: None **********************************************************/ void main(void) { DDRB = 0xff; PORTB = 0xff; EnableInterrupts; PLL_Init(); PIT_Init(); for(;;) { } } int i = 0, j = 0; #pragma CODE_SEG __NEAR_SEG NON_BANKED //Indicates that the program is in the non-paged area //Timer 0 void interrupt 66 PIT0(void) { DisableInterrupts; // Clear interrupt flag PITTF = 0x01; i++; //1s if(i == 1000) { PORTB_PB0 = ~PORTB_PB0; i = 0; } EnableInterrupts; } //Timer 1 void interrupt 67 PIT1(void) { DisableInterrupts; // Clear interrupt flag PITTF = 0x02; j++; //2s if(j == 250) { PORTB_PB1 = ~PORTB_PB1; j = 0; } EnableInterrupts; } #pragma CODE_SEG DEFAULT
Previous article:Freescale XS128 Series (I) PLL Phase-Locked Loop
Next article:Freescale HCS12 series MCU bootloader detailed explanation (Part 2)
- Popular Resources
- Popular amplifiers
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
- Questions about the nonlinear capacitance of MOSFET tubes
- 【RT-Thread software package application works】+ unpacking and development environment establishment
- [STM32WB55 Review] 7# Use and configuration of ADC on STM32WB development board
- Why are we not allowed to take photos without core technology?
- Espressif ESP32-C3-DevKitM-1 review is coming soon. Let’s learn about this board first.
- After deleting a wire that was previously laid, AD09 got stuck.
- Canaan wants to record a video about K510. What kind of content do you hope to see? (Attached is the official information about K510)
- Share some difficult problems with the LM25116EN chip
- [RVB2601 Creative Application Development] Dynamically loading MBRE Postscript
- Distance of ESD tip discharge needle