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

📄 ics.c

📁 飞思卡尔MC9S08QE128芯片和MCF51QE128芯片所有模块的范例代码,包括ACMP, ADC, ICS, IIC_Master, IIC_Slave, KBI, PWM, RTC, SCI,
💻 C
字号:
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */

typedef unsigned int UINT16;

/* Uncomment one of the following definitions to configure the MCU clock in the desired mode */

//#define FEI       // Configure bus clock to run at 29MHz in FEI mode
//#define FEE		    // Configure bus clock to run at 2MHz in FEE mode
//#define FBI		    // Configure bus clock to run at low frequency in FBI mode
//#define FBE       // Configure bus clock to run at low frequency in FBE mode


/*********************************************************************/
/*  Function declarations                                            */
/*********************************************************************/

void MCU_Init(void) {
  
  SOPT1 = 0x23;          /* Watchdog disable */  
  SCGC1 = 0x00;          /* All clocks to peripherals are disable */
  SCGC2 = 0x00;          /* All clocks to peripherals are disable */
}

void GPIO_Init(void) { 
  
  PTCDD = 0x01;          /* Configure PTC0 pin as output */
  PTCD = 0x01;           /* Put 1 in PTC0 pin to turn the LED off */
}

  
void ICS_configuration(void) {
  
  #ifdef FEI
  ICSC1 = 0b00000100;   /* Output of FLL is selected and Internal Reference Selected */
  ICSC2 = 0b00000000;   /* Bus frequency divided by 1 */
  ICSTRM = *(unsigned char*far)0xFFAF; /* Initialize ICSTRM register from a non volatile memory */
  ICSSC = (*(unsigned char*far)0xFFAE) | 0xA0;  /* Initialize ICSSC register from a non volatile memory */
                                                /* High range selected and Maximum frequency enabled */    
  #endif

  #ifdef FEE
  ICSC1 = 0b00000000;  /* Output of FLL is selected */
  ICSC2 = 0b10000111;  /* Divides slected clock by 4. External reference is selected */
  ICSTRM = *(unsigned char*far)0xFFAF; /* Initialize ICSTRM register from a non volatile memory */
  ICSSC = (*(unsigned char*far)0xFFAE) | 0x00;  /* Initialize ICSSC register from a non volatile memory */
  #endif

  #ifdef FBE
  ICSC1 = 0b10111000;   /* External reference clock selected. External reference divided by 5 */     
  ICSC2 = 0b00000000;   /* Bus frequency divided by 1 */    
  ICSTRM = *(unsigned char*far)0xFFAF; /* Initialize ICSTRM register from a non volatile memory */
  ICSSC = (*(unsigned char*far)0xFFAE) | 0x00;  /* Initialize ICSSC register from a non volatile memory */
  #endif
  
  #ifdef FBI
  ICSC1 = 0b01000000;   /* Internal reference clock is selected */     
  ICSC2 = 0b00000000;   /* Divides selected clock by 1 */     
  ICSTRM = *(unsigned char*far)0xFFAF; /* Initialize ICSTRM register from a non volatile memory */
  ICSSC = (*(unsigned char*far)0xFFAE) | 0x00;  /* Initialize ICSSC register from a non volatile memory */
  #endif FBI
}

void Delay () {
  
  UINT16 i = 0;
  for (i; i<=60000; i++){
  }
}


/*********************************************************************/
/*  Main Function                                                    */
/*********************************************************************/

void main(void) {

  MCU_Init();
  GPIO_Init();
  ICS_configuration();
                 
  EnableInterrupts;  /* enable interrupts */

  for(;;) {
  
  PTCD_PTCD0 ^= 1;    /* Toggle PTC0 pin */
  Delay();            /* Delay function used to observe the LED toggle */
  
  } /* loop forever */
  /* please make sure that you never leave this function */
}

⌨️ 快捷键说明

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