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

📄 acmp.c

📁 飞思卡尔MC9S08QE128芯片和MCF51QE128芯片所有模块的范例代码,包括ACMP, ADC, ICS, IIC_Master, IIC_Slave, KBI, PWM, RTC, SCI,
💻 C
字号:
/*********************************************************************/
/* Project Name: ACMP.mcp                                            */
/* Source fle name: ACMP.c                                           */
/*********************************************************************/
/* Copyright (C) 2007 Freescale Semiconductor, Inc.                  */
/* All Rights Reserved                                               */
/*********************************************************************/
/*********************************************************************/
/* Hands on training for QE128 MCU's                                 */
/* Module: ACMP                                                      */
/* The firmware was developed and tested on CodeWarrior 6.0 version  */
/*                                                                   */
/* Description: The PTC7 pin is the input for ACMP module. If the    */
/* ACMP interrupt is generated the PTC0 toggles.                     */
/*********************************************************************/
/*                                                                   */
/* Date: 12/03/2007                                                  */
/* Ulises Corrales Salgado                                           */
/* Application Engineer                                              */
/* RTAC Americas                                                     */
/*********************************************************************/                                                                      

#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */


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

void MCU_Init(void) {
  
 SOPT1 = 0x23;          /* Watchdog disable. Stop Mode Enable. Background Pin enable. RESET pin enable */ 
 SCGC1 = 0x00;          /* Disable Bus clock to unused peripherals */
 SCGC2 = 0x08;          /* Bus Clock to ACMP module is enabled */
}

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

void ACMP_configuration (void) {

 ACMP2SC = 0xC3;        /* ACMP module enable. Internal reference selected. Comparator output rising */
}                       /* or falling edge */


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

void main(void) {

  MCU_Init();       /* Function that initializes the MCU */         
  GPIO_Init();      /* Function that initializes the Ports of the MCU */
  ACMP_configuration(); /* Function that initializes the ACMP module */

  EnableInterrupts; /* enable interrupts */
  ACMP2SC_ACIE = 1; /* enable the interrupt from the ACMP */

  for(;;) {
    } /* loop forever */
  /* please make sure that you never leave this function */
}


/*********************************************************************
*  Interrupt Service Routines                                        *
*********************************************************************/

void interrupt VectorNumber_Vacmpx ACMP_ISR(void) {

 ACMP2SC_ACF = 1;    /* Clear ACMP flag */
 
 PTCD_PTCD0 ^= 1;    /* Toggle PTC0 */
}

⌨️ 快捷键说明

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