📄 rtc.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 + -