⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dz60_init.c

📁 基于FREESCALE单片机9S08DZ60的CAN的应用层源代码.开发环境为CODEWARRIOR FOR HC08
💻 C
字号:
/*******************************************************************************/
/*
Copyright (c) 2007 Freescale Semiconductor
Freescale Confidential Proprietary
\file       DZ60_init.c
\brief      S08DZ60 initialization
\author     Freescale Semiconductor
\author     B05114
\version    0.1
\date       January/2008
*/
/*******************************************************************************/

/* Derivative peripheral declarations */
#include "derivative.h" 

/* Definitions and function prototypes */
#include "DZ60_init.h"

/*******************************************************************************/
/*
* \brief    Multipurpose Clock Generator initialization.
* \author   B05114
* \param    void
* \return   void
*/
void MCG_Init(void) 
{
    SOPT1_COPT = 0;         /* Watchdog disabled */

    MCGC2_BDIV = BUS_DIV;   /* Bus divider */        
    MCGC2_RANGE = 1;        /* High frequency range selected */
    MCGC2_HGO = 1;          /* High gain for external oscillator */
    MCGC2_EREFS = 1;        /* External reference is crystal oscillator */ 
    MCGC2_ERCLKEN = 1;      /* External reference enabled */
    
        while(!MCGSC_OSCINIT);  /* Wait until the initialization cycles
                                   of the external oscillator are complete */
                                 
    MCGC1_CLKS = 0x02;      /* External reference is system clock source */
    MCGC1_RDIV = 0x07;      /* Configure Reference Divider to div by 128 */      
    MCGC1_IREFS = 0;        /* External reference clock selected */
                                      
        while(MCGSC_IREFST);  /* Wait until the external reference is 
                                 the source for the reference clock */   
                                 
        while((MCGSC_CLKST)^(0x02));  /* Wait until the external reference 
                                         is directed to MCGOUT */    
                                        
    MCGC2_LP = 1;           /* BLPE mode entered */  
                

    MCGC1_RDIV = REF_DIV;   /* Configure the Reference Divider */
    MCGC3_PLLS = 1;         /* Enable PLL to use it in PBE mode */
    MCGC3_VDIV = VCO_DIV;   /* Multiplication factor applied to the reference */
    
        while(!MCGSC_PLLST);    /* Wait until the PLL is the 
                                   source for the reference clock */   
                                   
    MCGC2_LP = 0;   /* Switch to PBE mode before going to PEE mode */          
    
        while(!MCGSC_LOCK);    /* Wait until the PLL locks */     
        
    MCGC1_CLKS = 0x00;      /* PLL selected as system clock source */  
    
        while((MCGSC_CLKST)^(0x03));  /* Wait until the PLL is directed to MCGOUT */                                                                    
}


/*******************************************************************************/
/*
* \brief    DZ60 demo board GPIO settings
* \author   B05114
* \param    void
* \return   void
*/
void GPIO_Init(void)
{     
    PTBDD_PTBDD3 = 1;  /* PTB3 is output to LED2 */
    PTBDD_PTBDD6 = 0;  /* PTB6 is input from push-button PB1 */
    PTBDD_PTBDD7 = 0;  /* PTB7 is input from push-button PB2 */
                                                                                
    PTCDD_PTCDD5 = 1;   /* PTC5 is output to LED1 */  
}

/*******************************************************************************/
/*
* \brief    Timer TPM1 configuration
* \author   B05114
* \param    void
* \return   void
*/
void TPM1_Init(void)
{   
    TPM1SC_PS = PS_DIV;     /* Prescaler selection */
    TPM1SC_CLKSx = BUS_CLK; /* Clock source selection */                    
    TPM1SC_TOIE = 1;        /* Timer overflow interrupt enabled */       
}  

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

/*******************************************************************************/
/*                                                                             */
/* All software, source code, included documentation, and any implied know-how */
/* are property of Freescale Semiconductor and therefore considered            */ 
/* CONFIDENTIAL INFORMATION.                                                   */
/*                                                                             */
/* This confidential information is disclosed FOR DEMONSTRATION PURPOSES ONLY. */
/*                                                                             */
/* All Confidential Information remains the property of Freescale Semiconductor*/
/* and will not be copied or reproduced without the express written permission */
/* of the Discloser, except for copies that are absolutely necessary in order  */
/* to fulfill the Purpose.                                                     */
/*                                                                             */
/* Services performed by FREESCALE in this matter are performed AS IS and      */
/* without any warranty. CUSTOMER retains the final decision relative to the   */
/* total design and functionality of the end product.                          */
/*                                                                             */
/* FREESCALE neither guarantees nor will be held liable by CUSTOMER for the    */
/* success of this project.                                                    */
/*                                                                             */
/* FREESCALE disclaims all warranties, express, implied or statutory including,*/
/* but not limited to, implied warranty of merchantability or fitness for a    */
/* particular purpose on any hardware, software ore advise supplied to the     */
/* project by FREESCALE, and or any product resulting from FREESCALE services. */
/*                                                                             */
/* In no event shall FREESCALE be liable for incidental or consequential       */
/* damages arising out of this agreement. CUSTOMER agrees to hold FREESCALE    */
/* harmless against any and all claims demands or actions by anyone on account */
/* of any damage,or injury, whether commercial, contractual, or tortuous,      */
/* rising directly or indirectly as a result of the advise or assistance       */
/* supplied CUSTOMER in connectionwith product, services or goods supplied     */
/* under this Agreement.                                                       */
/*                                                                             */
/*******************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -