📄 main.c
字号:
void IntExtOnOffConfig(FunctionalState NewState)
{
EXTI_InitTypeDef EXTI_InitStructure;
/* Initializes the EXTI_InitStructure */
EXTI_StructInit(&EXTI_InitStructure);
/* Disable the EXTI line 3, 7 and 15 on falling edge */
if(NewState == DISABLE)
{
EXTI_InitStructure.EXTI_Line = EXTI_Line3 | EXTI_Line7 | EXTI_Line15;
EXTI_InitStructure.EXTI_LineCmd = DISABLE;
EXTI_Init(&EXTI_InitStructure);
}
/* Enable the EXTI line 3, 7 and 15 on falling edge */
else
{
/* Clear the the EXTI line 3, 7 and 15 interrupt pending bit */
EXTI_ClearITPendingBit(EXTI_Line3 | EXTI_Line7 | EXTI_Line15);
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Line = EXTI_Line3 | EXTI_Line7 | EXTI_Line15;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
}
}
/*******************************************************************************
* 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 : DelayJoyStick
* Description : Inserts a delay time while no joystick RIGHT, LEFT and SEL
pushbuttons are pressed.
* Input : nCount: specifies the delay time length (time base 10 ms).
* Output : None
* Return : Pressed Key. This value can be: NOKEY, RIGHT, LEFT or SEL.
*******************************************************************************/
u32 DelayJoyStick(u32 nTime)
{
vu32 keystate = 0;
/* Enable the SysTick Counter */
SysTick_CounterCmd(SysTick_Counter_Enable);
TimingDelay = nTime;
while((TimingDelay != 0) && (keystate != RIGHT) && (keystate != LEFT) && (keystate != SEL))
{
keystate = ReadKey();
}
return keystate;
}
/*******************************************************************************
* 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 : LedShow_Init
* Description : Configure the leds pins as output pushpull: LED1, LED2, LED3
* and LED4
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void LedShow_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
TIM_OCStructInit(&TIM_OCInitStructure);
#if STM3210E
/* PF.06, PF.07, PF.08 and PF.09 as output push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOF, &GPIO_InitStructure);
#else
/* PB8..PB13 as output push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 |
GPIO_Pin_12 | GPIO_Pin_13 ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
#endif
/* Time Base configuration */
TIM_TimeBaseStructure.TIM_Prescaler = 719;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Period = 0x270F;
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0x0;
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
/* Channel 1 Configuration in Timing mode */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable;
TIM_OCInitStructure.TIM_Pulse = 0x0;
TIM_OC1Init(TIM1, &TIM_OCInitStructure);
}
/*******************************************************************************
* Function Name : LedShow
* Description : Enables or disables LED1, LED2, LED3 and LED4 toggling.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void LedShow(FunctionalState NewState)
{
/* Enable LEDs toggling */
if(NewState == ENABLE)
{
LedShowStatus = 1;
/* Enable the TIM1 Update Interrupt */
TIM_ITConfig(TIM1, TIM_IT_Update, ENABLE);
/* TIM1 counter enable */
TIM_Cmd(TIM1, ENABLE);
}
/* Disable LEDs toggling */
else
{
LedShowStatus = 0;
/* Disable the TIM1 Update Interrupt */
TIM_ITConfig(TIM1, TIM_IT_Update, DISABLE);
/* TIM1 counter disable */
TIM_Cmd(TIM1, DISABLE);
}
}
/*******************************************************************************
* Function Name : Get_LedShowStatus
* Description : Get the LedShowStatus value.
* Input : None
* Output : None
* Return : LedShowStatus Value.
*******************************************************************************/
u32 Get_LedShowStatus(void)
{
return LedShowStatus;
}
/*******************************************************************************
* Function Name : CheckBitmapFilesStatus
* Description : Checks the bitmap files availability and display a warning
* message if these files doesn't exit.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void CheckBitmapFilesStatus(void)
{
/* Checks if the Bitmap files are loaded */
if(CheckBitmapFiles() != 0)
{
/* Set the LCD Back Color */
LCD_SetBackColor(Blue);
/* Set the LCD Text Color */
LCD_SetTextColor(White);
LCD_DisplayStringLine(Line0, " Warning ");
LCD_DisplayStringLine(Line1, "No loaded Bitmap ");
LCD_DisplayStringLine(Line2, "files. Demo can't be");
LCD_DisplayStringLine(Line3, "executed. ");
LCD_DisplayStringLine(Line4, "Please be sure that ");
LCD_DisplayStringLine(Line5, "all files are ");
LCD_DisplayStringLine(Line6, "correctly programmed");
LCD_DisplayStringLine(Line7, "in the SPI FLASH and");
LCD_DisplayStringLine(Line8, "restart the Demo. ");
LCD_DisplayStringLine(Line9, " ");
/* Deinitializes the NVIC */
NVIC_DeInit();
/* Deinitializes the RCC */
RCC_DeInit();
/* Demo Can't Start */
while(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) */
LCD_Clear(White);
LCD_DisplayStringLine(Line0, " Assert Function ");
/* Infinite loop */
while (1)
{
}
}
#endif
/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -