xs128 dual timers PIT0 and PIT1

Publisher:快乐的舞蹈Latest update time:2021-08-27 Source: eefocusKeywords:xs128 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

/*****************************************************************

** 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       /* common defines and macros */

#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


Keywords:xs128 Reference address:xs128 dual timers PIT0 and PIT1

Previous article:Freescale XS128 Series (I) PLL Phase-Locked Loop
Next article:Freescale HCS12 series MCU bootloader detailed explanation (Part 2)

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号