?? main.c
字號(hào):
/******************** (C) COPYRIGHT 2006 STMicroelectronics ********************
* File Name : main.c
* Author : MCD Application Team
* Date First Issued : 05/18/2006 : Version 1.0
* Description : Main program body
********************************************************************************
* History:
* 05/24/2006 : Version 1.1
* 05/18/2006 : Version 1.0
********************************************************************************
* 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.
*******************************************************************************/
/* Standard include ----------------------------------------------------------*/
#include "main.h"
/* Include of other module interface headers ---------------------------------*/
/* Local includes ------------------------------------------------------------*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
GPIO_InitTypeDef GPIO_InitStructure;
ADC_InitTypeDef ADC_InitStructure;
WIU_InitTypeDef WIU_InitStructure;
extern TIM_InitTypeDef TIM_InitStructure;
u16 k,s;
u32 l;
u8 j=1,i=0x80;
u8 LedIndex = 0;
u16 LedPulse = 0;
u8 buffer[13] = " ADC:";
u16 Conversion_Value = 0;
unsigned int centaine(unsigned int val){
unsigned int valCopy;
valCopy = val % 1000;
return((valCopy/100) + 0x30);
}
unsigned int dixaine(unsigned int val){
unsigned int valCopy;
valCopy = val % 100;
return((valCopy/10) + 0x30);
}
unsigned int unite(unsigned int val){
unsigned int valCopy;
valCopy = val % 100;
return((valCopy%10) + 0x30);
}
/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* Function Name : main
* Description : Main program
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void main()
{
#ifdef DEBUG
debug();
#endif
/*Initialize the demonstration application*/
Demo_Init();
/* Start playing Osiris wave */
WavePlayer_Start();
/* Display " Welcome to the " message on LCD: Line 1 */
LCD_SendStringByStep(" Welcome to the ", 1, 1);
Delay(0xFFFF);
/* Display " STR912 Demo " message on LCD: Line 2 */
LCD_SendStringByStep(" STR912 Demo ", 2, 1);
/* Wait the end of Osiris wave */
Delay(0x5FFFFF);
/* Display " B1 : Conversion" message on LCD: Line 1 */
LCD_SendStringByStep(" B1 : Conversion", 1, 1);
Delay(0xFFFF);
/* Display " B2 : LedShow " message on LCD: Line 2 */
LCD_SendStringByStep(" B2 : LedShow ", 2, 1);
/* Enable WIU interrupt*/
VIC_ITCmd(WIU_ITLine, ENABLE);
while(1);
}
/*******************************************************************************
* Function Name : Demo_Init
* Description : Initializes the demonstration application.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void Demo_Init(void)
{
/*----------------------- System Clock Config --------------------------------*/
FMI_BankRemapConfig(4, 2, 0, 0x80000); /* Set Flash banks size & address */
FMI_Config(FMI_READ_WAIT_STATE_2, FMI_WRITE_WAIT_STATE_0, FMI_PWD_ENABLE,\
FMI_LVD_ENABLE, FMI_FREQ_HIGH); /* FMI Waite States */
/* Set the PCLK Clock to MCLK/2 */
SCU_PCLKDivisorConfig(SCU_PCLK_Div2);
SCU_PLLFactorsConfig(192, 25, 2); /* Configure Factors FPLL = 96MHz */
SCU_PLLCmd(ENABLE);
SCU_MCLKSourceConfig(SCU_MCLK_PLL);
/*--------------------- Peripherals Clock Enable -----------------------------*/
/* Enable TIM0 clock */
SCU_APBPeriphClockConfig(__TIM01, ENABLE);
TIM_DeInit(TIM0);
/* Enable TIM2 and TIM3 clock */
SCU_APBPeriphClockConfig(__TIM23, ENABLE);
TIM_DeInit(TIM2);
TIM_DeInit(TIM3);
/* Enable ADC clock */
SCU_APBPeriphClockConfig(__ADC, ENABLE);
ADC_DeInit();
/* Enable VIC clock */
SCU_AHBPeriphClockConfig(__VIC, ENABLE);
VIC_DeInit();
/* Enable WIU clock */
SCU_APBPeriphClockConfig(__WIU, ENABLE);
WIU_DeInit();
/* Enable GPIO3 clock */
SCU_APBPeriphClockConfig(__GPIO3, ENABLE);
GPIO_DeInit(GPIO3);
/* Enable GPIO4 clock */
SCU_APBPeriphClockConfig(__GPIO4, ENABLE);
GPIO_DeInit(GPIO4);
/* Enable GPIO6 clock */
SCU_APBPeriphClockConfig(__GPIO6, ENABLE);
GPIO_DeInit(GPIO6);
/* Enable GPIO7 clock */
SCU_APBPeriphClockConfig(__GPIO7, ENABLE);
GPIO_DeInit(GPIO7);
/*--------------------- Drivers Initialization -------------------------------*/
/* Initialize LCD driver */
LCD_Init();
LCD_Clear();
/* Initialize wave player driver */
WavePlayer_Init();
/* Initialize LedShow */
LedShow_Init();
SystemTimer_Init();
/*------------------------ GPIOs Configuration -------------------------------*/
/* GPIO7 pin 5 and 6 configuration */
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5|GPIO_Pin_6;
GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
GPIO_Init (GPIO7, &GPIO_InitStructure);
/* Configure the GPIO4 pin 5 as analog input */
GPIO_ANAPinConfig(GPIO_ANAChannel5, ENABLE);
/*----------------------------ADC Configuration------------------------------*/
ADC_StructInit(&ADC_InitStructure);
ADC_InitStructure.ADC_Channel_5_Mode = ADC_NoThreshold_Conversion;
ADC_InitStructure.ADC_Select_Channel = ADC_Channel_5;
ADC_InitStructure.ADC_Scan_Mode = DISABLE;
ADC_InitStructure.ADC_Conversion_Mode = ADC_Continuous_Mode;
/* Enable the ADC */
ADC_Cmd(ENABLE);
/* Prescaler config */
ADC_PrescalerConfig(0x4);
/* Configure the ADC */
ADC_Init(&ADC_InitStructure);
/*------------------------ WIU Configuration ---------------------------------*/
/* WIU Line 29 configuration */
WIU_ClearITPendingBit(WIU_Line29);
WIU_InitStructure.WIU_Mode = WIU_Mode_Interrupt;
WIU_InitStructure.WIU_Line = WIU_Line29;
WIU_InitStructure.WIU_TriggerEdge = WIU_FallingEdge;
WIU_Init(&WIU_InitStructure);
/* WIU Line 30 configuration */
WIU_ClearITPendingBit(WIU_Line30);
WIU_InitStructure.WIU_Mode = WIU_Mode_Interrupt;
WIU_InitStructure.WIU_Line = WIU_Line30;
WIU_InitStructure.WIU_TriggerEdge = WIU_FallingEdge;
WIU_Init(&WIU_InitStructure);
/*------------------------ VIC Configuration ---------------------------------*/
VIC_Config(WIU_ITLine, VIC_IRQ, 0);
VIC_Config(TIM0_ITLine, VIC_IRQ, 1);
VIC_ITCmd(TIM0_ITLine, ENABLE);
}
/*******************************************************************************
* Function Name : SystemTimer_Init
* Description : Implements a system timer that generates an event each 100
* millisecondes (100ms).
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void SystemTimer_Init(void)
{
TIM_StructInit(&TIM_InitStructure);
TIM_InitStructure.TIM_Mode = TIM_OCM_CHANNEL_1;
TIM_InitStructure.TIM_OC1_Modes = TIM_TIMING;
TIM_InitStructure.TIM_Clock_Source = TIM_CLK_APB;
TIM_InitStructure.TIM_Prescaler = 0xFF;
TIM_InitStructure.TIM_Pulse_Length_1 = 0x493E;
/* Initialize the Timer 2 */
TIM_Init (TIM2, &TIM_InitStructure);
/* Enable the Timer Overflow interrupt */
TIM_ITConfig(TIM2, TIM_IT_OC1, ENABLE);
/* Start the Timer counter */
TIM_CounterCmd(TIM2, TIM_START);
}
/*******************************************************************************
* Function Name : LedShow_Init
* Description : Configure the leds pins as output pushpull
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void LedShow_Init(void)
{
/* GPIO3 pins configuration */
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull;
GPIO_InitStructure.GPIO_Alternate=GPIO_OutputAlt1;
GPIO_Init(GPIO3, &GPIO_InitStructure);
/* GPIO6 pins configuration */
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull;
GPIO_InitStructure.GPIO_Alternate=GPIO_OutputAlt1;
GPIO_Init(GPIO6, &GPIO_InitStructure);
}
/*******************************************************************************
* Function Name : LedShow_Start
* Description : Configure the leds pins as output pushpull
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void LedShow_Start(void)
{
LedPulse += 0x493E;
/* Enable leds show untill press of "B1" pushbutton */
while(WIU_GetITStatus(WIU_Line29) == RESET)
{
/* Display " ADC Conversion " message on LCD: Line 1 */
LCD_SendStringByStep(" Led Show ",1, 1);
Delay(0xFFFF);
LCD_LineClear(2);
for(k=0;k<7;k++)
{
GPIO_WriteBit(GPIO3,j, Bit_SET);
GPIO_WriteBit(GPIO6,i, Bit_SET);
Delay(0x3FFFF);
GPIO_Write(GPIO3,0x0);
GPIO_Write(GPIO6,0x0);
j=j*2;
i=i/2;
}
i=1;
j=0x80;
for(s=0;s<7;s++)
{
GPIO_WriteBit(GPIO3,j, Bit_SET);
GPIO_WriteBit(GPIO6,i, Bit_SET);
Delay(0x3FFFF);
GPIO_Write(GPIO3,0x0);
GPIO_Write(GPIO6,0x0);
i=i*2;
j=j/2;
}
LedIndex ++;
/* Reset Index to replay leds switch on sequence */
if (LedIndex == 1)
LedIndex = 0;
}
TIM_SetPulse(TIM2, TIM_PWM_OC1_Channel, LedPulse);
TIM_ClearFlag(TIM2, TIM_FLAG_OC1);
GPIO_Write(GPIO3,0xFF);
GPIO_Write(GPIO6,0xFF);
}
/*******************************************************************************
* Function Name : Conversion_Start
* Description : Configure the leds pins as output pushpull
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void Conversion_Start(void)
{
/* Display " ADC Conversion " message on LCD: Line 1 */
LCD_SendStringByStep(" ADC Conversion ",1, 1);
Delay(0xFFFF);
LCD_LineClear(2);
Delay(0xFFFF);
/* Display " ADC:" message on LCD: Line 2 */
LCD_SendStringByStep(buffer,2, 1);
/* Start the conversion */
ADC_ConversionCmd(ADC_Conversion_Start);
/* Enable ADC Conversion untill a press of "B2" pushbutton */
while(WIU_GetITStatus(WIU_Line30) == RESET)
{
/* Wait until conversion completion */
while(ADC_GetFlagStatus(ADC_FLAG_ECV) == RESET);
/* Get the conversion value */
Conversion_Value = ADC_GetConversionValue(ADC_Channel_5);
/* Clear the end of conversion flag */
ADC_ClearFlag(ADC_FLAG_ECV);
buffer[11] = unite(Conversion_Value);
buffer[10] = dixaine(Conversion_Value);
buffer[9] = centaine(Conversion_Value);
buffer[12] = 0;
/* Display ADC conversion Value on LCD */
LCD_SendStringByStep(&buffer[9],2, 9);
Delay(0xFFFF);
LCD_SetPosCur(2,9);
}
}
/*******************************************************************************
* Function Name : Delay
* Description : Inserts a delay time.
* Input : nCount: specifies the delay time length.
* Output : None
* Return : None
*******************************************************************************/
void Delay(u32 nCount)
{
u32 j = 0;
for(j = nCount; j != 0; j--);
}
/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -