📄 main.c
字号:
/******************** (C) COPYRIGHT 2006 STMicroelectronics ********************
* File Name : main.c
* Author : MCD Application Team
* Date First Issued : 03/10/2006
* Description : Main program body
********************************************************************************
* History:
* 06/20/2007 : V1.1
* The document is modified by New-Embed Co.Ltd(http://wwww.2embed.com) to fit the NE-STR750F board.
* 07/17/2006 : V1.0
* 03/10/2006 : V0.1
********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "75x_lib.h"
#include <stdio.h>
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
MRCC_ClocksTypeDef MRCC_Clocks;
ErrorStatus OSC4MStartUpStatus01;
/* Private function prototypes -----------------------------------------------*/
void EIC_Configuration(void);
void Delay(u32 nCount);
void RTC_Configuration(void);
/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* Function Name : main
* Description : Main program
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void main()
{
#ifdef DEBUG
debug();
#endif
/* Configures the different system clocks ------------------------------------*/
/* MRCC system reset(for debug purpose) */
MRCC_DeInit();
/* Wait for OSC4M start-up */
OSC4MStartUpStatus01 = MRCC_WaitForOSC4MStartUp();
if(OSC4MStartUpStatus01 == SUCCESS) // OSC4M 启动成功
{
/* Set HCLK to 60MHz */
MRCC_HCLKConfig(MRCC_CKSYS_Div1);
/* Set CKTIM to 30MHz */
MRCC_CKTIMConfig(MRCC_HCLK_Div2);
/* Set PCLK to 30MHz */
MRCC_PCLKConfig(MRCC_CKTIM_Div1);
/* Enable Flash burst mode */
CFG_FLASHBurstConfig(CFG_FLASHBurst_Enable);
/* Set CK_SYS to 60 MHz */
if(MRCC_CKSYSConfig(MRCC_CKSYS_OSC4MPLL, MRCC_PLL_Mul_15) == ERROR)
{
/* Add here some code to deal with this error */
}
}
else
{
/* Add here some code to deal with this error */
}
/* GPIO pins optimized for 3V3 operation */
MRCC_IOVoltageRangeConfig(MRCC_IOVoltageRange_3V3);
/* Configure RTC clock source ------------------------------------------------*/
/* Enable OSC32K */
if(MRCC_OSC32KConfig(MRCC_OSC32K_Enable, MRCC_OSC32KBypass_Disable) == SUCCESS)
{
/* Wait for OSC32K clock to be stable */
while(MRCC_GetFlagStatus(MRCC_FLAG_OSC32KRDY) == RESET);
/* Select OSC32K as RTC clock source */
if(MRCC_CKRTCConfig(MRCC_CKRTC_OSC32K)== SUCCESS)
{
/* Wait for RTC clock to be ready for use */
while(MRCC_GetFlagStatus(MRCC_FLAG_CKRTCOK) == RESET);
}
else
{
/* Add here some code to deal with this error */
}
}
else
{
/* Add here some code to deal with this error */
}
/* This function fills a MRCC_ClocksTypeDef structure with the current status
and frequencies of different on chip clocks (for debug purpose) */
MRCC_GetClocksStatus(&MRCC_Clocks);
/* The MRCC_Clocks members should be as following:
MRCC_Clocks.CKSYS_Source = OSC4MPLL
MRCC_Clocks.CKRTC_Source = OSC32K
MRCC_Clocks.CKUSB_Source = Disabled
MRCC_Clocks.PLL_Status = ON
MRCC_Clocks.OSC4M_Status = ON
MRCC_Clocks.LPOSC_Status = OFF
MRCC_Clocks.OSC32K_Status = ON
MRCC_Clocks.CKSYS_Frequency = 4000000
MRCC_Clocks.HCLK_Frequency = 60000000
MRCC_Clocks.CKTIM_Frequency = 30000000
MRCC_Clocks.PCLK_Frequency = 30000000 */
/* Enable GPIO clock */
MRCC_PeripheralClockConfig(MRCC_Peripheral_GPIO, ENABLE);
/* Configure the used I/O ports pins */
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure P0.12 as Output push-pull */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_Init(GPIO0, &GPIO_InitStructure);
/* Enable No Clock Detected interrupt */
MRCC_ITConfig(MRCC_IT_NCKD, ENABLE);
/* Configure the interrupt controller */
EIC_Configuration();
while(1)
{
/* Turn on led conencted to P0.12 pin */
GPIO_WriteBit(GPIO0, GPIO_Pin_12, Bit_RESET);
Delay(0x7FFFF);
/* Turn off conencted to P0.12 pin */
GPIO_WriteBit(GPIO0, GPIO_Pin_12, Bit_SET);
Delay(0x7FFFF);
}
}
/*******************************************************************************
* Function Name : EIC_Configuration
* Description : Configures the interrupt controller.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void EIC_Configuration(void)
{
EIC_IRQInitTypeDef EIC_IRQInitStructure;
/* Configure and enable MRCC IRQ Channel*/
EIC_IRQInitStructure.EIC_IRQChannel = MRCC_IRQChannel;
EIC_IRQInitStructure.EIC_IRQChannelPriority = 1;
EIC_IRQInitStructure.EIC_IRQChannelCmd = ENABLE;
EIC_IRQInit(&EIC_IRQInitStructure);
/* Enable EIC IRQ output request to CPU */
EIC_IRQCmd(ENABLE);
}
/*******************************************************************************
* Function Name : Delay
* Description : Inserts a delay time.
* Input : nCount: specifies the delay time length.
* Output : None
* Return : None
*******************************************************************************/
void Delay(u32 nCount)
{
for(; nCount!= 0;nCount--);
}
void RTC_Configuration(void)
{
/* If the system has resumed from STANDBY mode, there is no need to configure
the RTC clock source */
if(MRCC_GetFlagStatus(MRCC_FLAG_STDB) != RESET)
{
/* Clear the STDB flag */
MRCC_ClearFlag(MRCC_FLAG_STDB);
}
else /* Configure the RTC clock source */
{
/* RTC clock source configuration ----------------------------------------*/
/* Enable OSC32K*/
MRCC_OSC32KConfig(MRCC_OSC32K_Enable, MRCC_OSC32KBypass_Disable);
while(MRCC_GetFlagStatus(MRCC_FLAG_OSC32KRDY) == RESET);//检测MRCC_PWRCTRL的位31
/* Select OSC32K as CK_RTC clock source */
MRCC_CKRTCConfig(MRCC_CKRTC_OSC32K);
/* Wait for RTC clock to be ready */
while(MRCC_GetFlagStatus(MRCC_FLAG_CKRTCOK) == RESET);//检测MRCC_PWRCTRL的位27
}
/* RTC configuration -------------------------------------------------------*/
/* Enable RTC Clock */
MRCC_PeripheralClockConfig(MRCC_Peripheral_RTC, ENABLE);
/* Wait for RTC registers synchronization */
RTC_WaitForSynchro();
/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask();
/* Set RTC prescaler: set RTC period to 1 second */
RTC_SetPrescaler(32767); /* RTC period = CK_RTC/RTC_PR = (32.768 KHz)/(32767+1) */
/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask();
/* Enable the RTC Second interrupt */
RTC_ITConfig(RTC_IT_Second, ENABLE);
}
/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -