www.pudn.com > Audio.rar > main.c, change:2008-12-19,size:10495b


/******************** (C) COPYRIGHT 2008 STMicroelectronics ******************** 
* File Name          : main.c 
* Author             : MCD Application Team 
* Version            : V1.1.1 
* Date               : 06/13/2008 
* Description        : Main program body 
******************************************************************************** 
* THE PRESENT FIRMWARE 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 FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 
*******************************************************************************/ 
 
/* Includes ------------------------------------------------------------------*/ 
#include "stm32f10x_tim.h" 
#include "stm32f10x_dac.h" 
#include "project.h" 
#include <stdio.h> 
 
/* Private typedef -----------------------------------------------------------*/ 
/* Private define ------------------------------------------------------------*/ 
/* Private macro -------------------------------------------------------------*/ 
/* Private variables ---------------------------------------------------------*/ 
static vu32 TimingDelay = 0; 
static vu32 LedShowStatus = 0; 
static volatile ErrorStatus HSEStartUpStatus = SUCCESS; 
static vu32 SELStatus = 0; 
 
/* Private function prototypes -----------------------------------------------*/ 
/* Private functions ---------------------------------------------------------*/ 
void Demo_Init(void); 
void InterruptConfig(void); 
void GPIO_Config(void); 
 
/******************************************************************************* 
* Function Name  : main 
* Description    : Main program. 
* Input          : None 
* Output         : None 
* Return         : None 
*******************************************************************************/ 
int main(void) 
{ 
#ifdef DEBUG 
  debug(); 
#endif 
 
  /* Initialize the Demo */ 
  Demo_Init(); 
 
  while (1) 
  { 
 
	  WavePlayer_StartSpeaker(); 
 
  }  
} 
 
/******************************************************************************* 
* Function Name  : Demo_Init 
* Description    : Initializes the demonstration application. 
* Input          : None 
* Output         : None 
* Return         : None 
*******************************************************************************/ 
void Demo_Init(void) 
{ 
  /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration -----------------------------*/    
  /* RCC system reset(for debug purpose) */ 
  RCC_DeInit(); 
 
  /* Enable HSE */ 
  RCC_HSEConfig(RCC_HSE_ON); 
 
  /* Wait till HSE is ready */ 
  HSEStartUpStatus = RCC_WaitForHSEStartUp(); 
 
  if(HSEStartUpStatus == SUCCESS) 
  { 
    /* Enable Prefetch Buffer */ 
    FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); 
 
    /* Flash 2 wait state */ 
    FLASH_SetLatency(FLASH_Latency_2); 
     
    /* HCLK = SYSCLK */ 
    RCC_HCLKConfig(RCC_SYSCLK_Div1);  
   
    /* PCLK2 = HCLK */ 
    RCC_PCLK2Config(RCC_HCLK_Div1);  
  
    /* PCLK1 = HCLK/2 */ 
    RCC_PCLK1Config(RCC_HCLK_Div2); 
  
    /* PLLCLK = 8MHz * 9 = 72 MHz */ 
    RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9); 
  
    /* Enable PLL */  
    RCC_PLLCmd(ENABLE); 
  
    /* Wait till PLL is ready */ 
    while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) 
    { 
    } 
  
    /* Select PLL as system clock source */ 
    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); 
  
    /* Wait till PLL is used as system clock source */ 
    while(RCC_GetSYSCLKSource() != 0x08) 
    { 
    } 
  } 
 
  /* Enable GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, GPIOF, GPIOG and AFIO clocks */ 
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |RCC_APB2Periph_GPIOC  
         | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_GPIOF | RCC_APB2Periph_GPIOG  
         | RCC_APB2Periph_AFIO, ENABLE); 
   
  /* TIM1 Periph clock enable */ 
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE); 
  
/*------------------- Resources Initialization -----------------------------*/ 
  /* GPIO Configuration */ 
  GPIO_Config(); 
 
  /* Interrupt Configuration */ 
  InterruptConfig(); 
 
  /* Configure the systick */     
  SysTick_Config(); 
  /* Initialize the LCD */ 
  STM3210E_LCD_Init(); 
 
/*------------------- Drivers Initialization -------------------------------*/ 
 
 
   
  /* If HSE is not detected at program startup */ 
  if(HSEStartUpStatus == ERROR) 
  { 
    /* Generate NMI exception */ 
    NVIC_SetSystemHandlerPendingBit(SystemHandler_NMI); 
  }   
    
  /* Initialize the SPI FLASH driver */ 
  SPI_FLASH_Init(); 
 
} 
 
/******************************************************************************* 
* Function Name  : InterruptConfig 
* Description    : Configures the used IRQ Channels and sets their priority. 
* Input          : None 
* Output         : None 
* Return         : None 
*******************************************************************************/ 
void InterruptConfig(void) 
{  
 
  /* Deinitializes the NVIC */ 
  NVIC_DeInit(); 
 
  /* Set the Vector Table base address at 0x08000000 */ 
  NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x00); 
 
  /* Configure the Priority Group to 2 bits */ 
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); 
 
  /* Configure the SysTick handler priority */ 
  NVIC_SystemHandlerPriorityConfig(SystemHandler_SysTick, 0, 0); 
   
} 
 
/******************************************************************************* 
* Function Name  : SysTick_Config 
* Description    : Configure a SysTick Base time to 10 ms. 
* Input          : None 
* Output         : None 
* Return         : None 
*******************************************************************************/ 
void SysTick_Config(void) 
{ 
  /* Configure HCLK clock as SysTick clock source */ 
  SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK); 
  
  /* SysTick interrupt each 100 Hz with HCLK equal to 72MHz */ 
  SysTick_SetReload(720000); 
 
  /* Enable the SysTick Interrupt */ 
  SysTick_ITConfig(ENABLE); 
} 
 
 
 
/******************************************************************************* 
* Function Name  : GPIO_Config 
* Description    : Configures the different GPIO ports pins. 
* Input          : None 
* Output         : None 
* Return         : None 
*******************************************************************************/ 
void GPIO_Config(void) 
{ 
  GPIO_InitTypeDef GPIO_InitStructure; 
 
  /* Configure PG.07, PG.08, PG.13, PG.14 and PG.15 as input floating */ 
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; 
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; 
  GPIO_Init(GPIOG, &GPIO_InitStructure); 
 
  /* Configure PD.03 as input floating */ 
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; 
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; 
  GPIO_Init(GPIOD, &GPIO_InitStructure); 
 
  /* RIGHT Button */ 
  GPIO_EXTILineConfig(GPIO_PortSourceGPIOG, GPIO_PinSource13); 
 
  /* LEFT Button */ 
  GPIO_EXTILineConfig(GPIO_PortSourceGPIOG, GPIO_PinSource14); 
 
  /* DOWN Button */ 
  GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource3); 
 
  /* UP Button */ 
  GPIO_EXTILineConfig(GPIO_PortSourceGPIOG, GPIO_PinSource15); 
 
  /* SEL Button */ 
  GPIO_EXTILineConfig(GPIO_PortSourceGPIOG, GPIO_PinSource7); 
 
  /* KEY Button */ 
  GPIO_EXTILineConfig(GPIO_PortSourceGPIOG, GPIO_PinSource8); 
} 
 
/******************************************************************************* 
* Function Name  : Delay 
* Description    : Inserts a delay time. 
* Input          : nCount: specifies the delay time length (time base 10 ms). 
* Output         : None 
* Return         : None 
*******************************************************************************/ 
void Delay(u32 nCount) 
{ 
  TimingDelay = nCount; 
 
  /* Enable the SysTick Counter */ 
  SysTick_CounterCmd(SysTick_Counter_Enable); 
   
  while(TimingDelay != 0) 
  { 
  } 
 
  /* Disable the SysTick Counter */ 
  SysTick_CounterCmd(SysTick_Counter_Disable); 
 
  /* Clear the SysTick Counter */ 
  SysTick_CounterCmd(SysTick_Counter_Clear); 
} 
 
 
 
/******************************************************************************* 
* Function Name  : Decrement_TimingDelay 
* Description    : Decrements the TimingDelay variable. 
* Input          : None 
* Output         : TimingDelay 
* Return         : None 
*******************************************************************************/ 
void Decrement_TimingDelay(void) 
{ 
  if (TimingDelay != 0x00) 
  { 
    TimingDelay--; 
  } 
} 
 
/******************************************************************************* 
* Function Name  : Set_SELStatus 
* Description    : Sets the SELStatus variable. 
* Input          : None 
* Output         : SELStatus 
* Return         : None 
*******************************************************************************/ 
void Set_SELStatus(void) 
{ 
  SELStatus = 1; 
} 
 
 
 
 
 
/******************************************************************************* 
* Function Name  : Get_HSEStartUpStatus 
* Description    : Returns the HSE StartUp Status. 
* Input          : None 
* Output         : None 
* Return         : HSE StartUp Status. 
*******************************************************************************/ 
ErrorStatus Get_HSEStartUpStatus(void) 
{ 
  return (HSEStartUpStatus); 
} 
 
 
 
#ifdef  DEBUG 
/******************************************************************************* 
* Function Name  : assert_failed 
* Description    : Reports the name of the source file and the source line number 
*                  where the assert error has occurred. 
* Input          : - file: pointer to the source file name 
*                  - line: assert error line source number 
* Output         : None 
* Return         : None 
*******************************************************************************/ 
void assert_failed(u8* file, u32 line) 
{ 
  /* User can add his own implementation to report the file name and line number, 
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 
 
  /* Infinite loop */ 
  while (1) 
  { 
  } 
} 
#endif 
 
/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/