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

📄 cpu.c

📁 DSP中使用PWM模块对电机进行控制
💻 C
字号:
/** ###################################################################
**     THIS BEAN MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
**     Filename  : Cpu.C
**     Project   : pwm_motor
**     Processor : 56F8346
**     Beantype  : 56F8346
**     Version   : Bean 01.048, Driver 01.27, CPU db: 2.87.097
**     Datasheet : MC56F8346/D Rev. 1.0, MC56F8300UM/D - Rev. 1.0
**     Compiler  : Metrowerks DSP C Compiler
**     Date/Time : 2009-1-7, 11:09
**     Abstract  :
**
**     Settings  :
**
**     Contents  :
**         EnableInt   - void Cpu_EnableInt(void);
**         DisableInt  - void Cpu_DisableInt(void);
**         SetWaitMode - void Cpu_SetWaitMode(void);
**         SetStopMode - void Cpu_SetStopMode(void);
**         SetDataMode - void Cpu_SetDataMode(byte Mode);
**
**     (c) Freescale Semiconductor
**     2004 All Rights Reserved
**
**     (c) Copyright UNIS, spol. s r.o. 1997-2005
**     UNIS, spol. s r.o.
**     Jundrovska 33
**     624 00 Brno
**     Czech Republic
**     http      : www.processorexpert.com
**     mail      : info@processorexpert.com
** ###################################################################*/

/* MODULE Cpu. */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"
#include "Cpu.h"


/* Global variables */
volatile word SR_lock=0;               /* Lock */
volatile word SR_reg;                  /* Current value of the SR register */
/*
** ===================================================================
**     Method      :  Cpu_Interrupt (bean 56F8346)
**
**     Description :
**         The method services the interrupt of the selected peripheral(s)
**         and eventually invokes the beans event(s).
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
#pragma interrupt alignsp
void Cpu_Interrupt(void)
{
  asm(DEBUGHLT);                       /* Halt the core and placing it in the debug processing state */
}

/*
** ===================================================================
**     Method      :  Cpu_DisableInt (bean 56F8346)
**
**     Description :
**         Disables all maskable interrupts
**     Parameters  : None
**     Returns     : Nothing
** ===================================================================
*/
/*
void Cpu_DisableInt(void)

**      This method is implemented as macro in the header module. **
*/

/*
** ===================================================================
**     Method      :  Cpu_EnableInt (bean 56F8346)
**
**     Description :
**         Enables all maskable interrupts
**     Parameters  : None
**     Returns     : Nothing
** ===================================================================
*/
/*
void Cpu_EnableInt(void)

**      This method is implemented as macro in the header module. **
*/

/*
** ===================================================================
**     Method      :  Cpu_SetStopMode (bean 56F8346)
**
**     Description :
**         Sets low power mode - Stop mode.
**         For more information about the stop mode see this CPU
**         documentation.
**     Parameters  : None
**     Returns     : Nothing
** ===================================================================
*/
/*
void Cpu_SetStopMode(void)

**      This method is implemented as macro in the header module. **
*/

/*
** ===================================================================
**     Method      :  Cpu_SetWaitMode (bean 56F8346)
**
**     Description :
**         Sets low power mode - Wait mode.
**         For more information about the wait mode see this CPU
**         documentation.
**         Release from wait mode: Reset or interrupt
**     Parameters  : None
**     Returns     : Nothing
** ===================================================================
*/
/*
void Cpu_SetWaitMode(void)

**      This method is implemented as macro in the header module. **
*/

/*
** ===================================================================
**     Method      :  Cpu_SetDataMode (bean 56F8346)
**
**     Description :
**         Sets the Data memory map to use either internal &
**         external resources or external resources only.
**     Parameters  :
**         NAME            - DESCRIPTION
**         Mode            - Data memory access mode.
**                           Possible modes:
**                           INT_EXT_MODE - use internal & external
**                           resources
**                           EXT_MODE - use external resources only
**     Returns     : Nothing
** ===================================================================
*/
void Cpu_SetDataMode(byte Mode)
{
  if (Mode == INT_EXT_MODE)
    asm { bfclr  #0x0008,OMR }         /* Set internal and external data memory mode */
  else
    asm { bfset  #0x0008,OMR }         /* Set external data memory mode */
}

/*
** ===================================================================
**     Method      :  _EntryPoint (bean 56F8346)
**
**     Description :
**         Initializes the whole system like timing and so on. At the end 
**         of this function, the C startup is invoked to initialize stack,
**         memory areas and so on.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
extern void init_56800_(void);         /* Forward declaration of external startup function declared in startup file */

/*** !!! Here you can place your own code using property "User data declarations" on the build options tab. !!! ***/

void _EntryPoint(void)
{

  /*** !!! Here you can place your own code before PE initialization using property "User code before PE initialization" on the build options tab. !!! ***/

  /*** ### 56F8346 "Cpu" init code ... ***/
  /*** PE initialization code after reset ***/
  /* System clock initialization */
  setReg(PLLCR, (PLLCR_LCKON_MASK | PLLCR_ZSRC0_MASK)); /* Enable PLL, LCKON and select clock source from prescaler */
  /* PLLDB: LORTP=2,PLLCOD=0,PLLCID=1,??=0,PLLDB=59 */
  setReg16(PLLDB, 8507);               /* Set the clock prescalers */ 
  while(!getRegBit(PLLSR, LCK0)){}     /* Wait for PLL lock */
  setReg(PLLCR, (PLLCR_LCKON_MASK | PLLCR_ZSRC1_MASK)); /* Select clock source from postscaler */
  /* FMCLKD: ??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,DIVLD=0,PRDIV8=1,DIV=18 */
  setReg16(FMCLKD, 82);                /* Set the flash clock prescaler */ 
  /* External bus initialization */
  /* SEMI_CSBAR_0: ADR23=0,ADR22=0,ADR21=0,ADR20=0,ADR19=0,ADR18=0,ADR17=0,ADR16=0,ADR15=0,ADR14=0,ADR13=0,ADR12=0,BLKSZ3=0,BLKSZ2=1,BLKSZ1=0,BLKSZ0=1 */
  setReg16(SEMI_CSBAR_0, 5);           /* Chip select 0 base address register */ 
  /* SEMI_CSOR_0: RWS=1,BYTE_EN=3,R_W=3,PS_DS=2,WWS=1 */
  setReg16(SEMI_CSOR_0, 4033);         /* Chip select 0 option register */ 
  /* SEMI_CSTC_0: WWSS=0,WWSH=0,RWSS=0,RWSH=0,??=0,??=0,??=0,??=0,??=0,MDAR=0 */
  setReg16(SEMI_CSTC_0, 0);            /* Chip select 0 timing control register */ 
  /* SEMI_CSBAR_1: ADR23=0,ADR22=0,ADR21=0,ADR20=0,ADR19=0,ADR18=0,ADR17=0,ADR16=0,ADR15=0,ADR14=0,ADR13=0,ADR12=0,BLKSZ3=0,BLKSZ2=1,BLKSZ1=0,BLKSZ0=1 */
  setReg16(SEMI_CSBAR_1, 5);           /* Chip select 1 base address register */ 
  /* SEMI_CSOR_1: RWS=1,BYTE_EN=1,R_W=3,PS_DS=1,WWS=1 */
  setReg16(SEMI_CSOR_1, 2977);         /* Chip select 1 option register */ 
  /* SEMI_CSTC_1: WWSS=0,WWSH=0,RWSS=0,RWSH=0,??=0,??=0,??=0,??=0,??=0,MDAR=0 */
  setReg16(SEMI_CSTC_1, 0);            /* Chip select 1 timing control register */ 
  /* SEMI_CSBAR_2: ADR23=0,ADR22=0,ADR21=0,ADR20=0,ADR19=0,ADR18=0,ADR17=0,ADR16=0,ADR15=0,ADR14=0,ADR13=0,ADR12=0,BLKSZ3=0,BLKSZ2=1,BLKSZ1=0,BLKSZ0=1 */
  setReg16(SEMI_CSBAR_2, 5);           /* Chip select 2 base address register */ 
  /* SEMI_CSOR_2: RWS=1,BYTE_EN=2,R_W=3,PS_DS=1,WWS=1 */
  setReg16(SEMI_CSOR_2, 3489);         /* Chip select 2 option register */ 
  /* SEMI_CSTC_2: WWSS=0,WWSH=0,RWSS=0,RWSH=0,??=0,??=0,??=0,??=0,??=0,MDAR=0 */
  setReg16(SEMI_CSTC_2, 0);            /* Chip select 2 timing control register */ 
  /* GPIO_D_PER: PE9=1,PE8=1,PE0=1 */
  setReg16Bits(GPIO_D_PER, 769);        
  /* SEMI_BCR: DRV=1,BMDAR=0,??=0,??=0,BWWS=1,BRWS=1 */
  setReg16(SEMI_BCR, 32801);           /* Bus control register */ 
  /*** End of PE initialization code after reset ***/

  /*** !!! Here you can place your own code after PE initialization using property "User code after PE initialization" on the build options tab. !!! ***/

  asm(JMP init_56800_);                /* Jump to C startup code */
}

/*
** ===================================================================
**     Method      :  PE_low_level_init (bean 56F8346)
**
**     Description :
**         Initializes beans and provides common register initialization. 
**         The method is called automatically as a part of the 
**         application initialization code.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
void PE_low_level_init(void)
{
  /* TSENSOR_CONTROL: PWR=0 */
  clrReg16Bits(TSENSOR_CONTROL, 1);    /* Disable power source for the temperature sensor */ 
  __EI(0);                             /* Enable interrupts of the selected priority level */
}

/* END Cpu. */

/*
** ###################################################################
**
**     This file was created by UNIS Processor Expert 2.97 [03.74]
**     for the Freescale 56800 series of microcontrollers.
**
** ###################################################################
*/

⌨️ 快捷键说明

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