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

📄 rtc.c

📁 飞思卡尔MC9S08QE128芯片和MCF51QE128芯片所有模块的范例代码,包括ACMP, ADC, ICS, IIC_Master, IIC_Slave, KBI, PWM, RTC, SCI,
💻 C
字号:
/*********************************************************************/
/* Project Name: RTC.mcp                                             */
/* Source fle name: RTC.c                                            */
/*********************************************************************/
/* Copyright (C) 2007 Freescale Semiconductor, Inc.                  */
/* All Rights Reserved                                               */
/*********************************************************************/
/*********************************************************************/
/* Hands on training for QE128 MCU's                                 */
/* Module: RTC                                                       */
/* The firmware was developed and tested on CodeWarrior 6.0 version  */
/*                                                                   */
/* Description: The MCU interrupts every second and PTC0 pin is      */
/* toggle                                                            */
/*********************************************************************/
/*                                                                   */
/* 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 = 0x04;          /* Bus Clock to the RTC module is enable */
}

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


void RTC_configuration (void) {
  
 RTCSC = 0x0F;          /* RTCPS configure prescaler period every 1s */
 RTCMOD = 0x00;         /* RTCMOD configure to interrupt every 1s */
}

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

void main(void) {

  MCU_Init();           /* Function that initializes the MCU */
  GPIO_Init();          /* Function that initializes the Ports of the MCU */
  RTC_configuration();  /* Function that initializes the RTC module */

  EnableInterrupts; /* enable interrupts */
  
  RTCSC_RTIE = 1;   /* Enable RTC interrupt */
  for(;;) {
 
  } /* loop forever */
  /* please make sure that you never leave this function */
}


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

void interrupt VectorNumber_Vrtc RTC_ISR(void) {
                                                                
 RTCSC = RTCSC | 0x80;        /* Clear the RTC flag */
 PTCD_PTCD0 ^= 1;             /* Toggles PTC0 pin */
} 

⌨️ 快捷键说明

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