📄 main.c
字号:
/******************** (C) COPYRIGHT 2006 STMicroelectronics ********************
* File Name : main.c
* Author : MCD Application Team
* Date First Issued : 09/15/2006 : IAP Version 1.0
* Description : The main program
********************************************************************************
* History:
* 09/15/2006 : IAP 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.
*******************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "common.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
static u8 Push_Button_Read (void);
static void Push_Button_Config(void);
/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* Function Name : IAP_Init
* Description : Initialize the IAP(Configure PLL, UART and GPIOs).
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void IAP_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
UART_InitTypeDef UART_InitStructure;
/* Configure the system clocks */
/* Enable the UART0 Clock */
SCU_APBPeriphClockConfig(__UART0, ENABLE);
/* Enable the GPIO3 Clock */
SCU_APBPeriphClockConfig(__GPIO3, ENABLE);
/* Enable the GPIO5 Clock */
SCU_APBPeriphClockConfig(__GPIO5, ENABLE);
/*Gonfigure UART0_Rx pin GPIO5.1*/
GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable;
GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1 ;
GPIO_Init(GPIO5, &GPIO_InitStructure);
/*Gonfigure UART0_Tx pin GPIO3.4*/
GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt3 ;
GPIO_Init(GPIO3, &GPIO_InitStructure);
/* UART0 configured as follow:
- Word Length = 8 Bits
- One Stop Bit
- No parity
- BaudRate = 115200 baud
- Hardware flow control Disabled
- Receive and transmit enabled
- Receive and transmit FIFOs are Disabled
*/
UART_InitStructure.UART_WordLength = UART_WordLength_8D;
UART_InitStructure.UART_StopBits = UART_StopBits_1;
UART_InitStructure.UART_Parity = UART_Parity_No ;
UART_InitStructure.UART_BaudRate = 115200;
UART_InitStructure. UART_HardwareFlowControl = UART_HardwareFlowControl_None;
UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx;
UART_InitStructure.UART_FIFO = UART_FIFO_Disable;
UART_DeInit(UART0);
UART_Init(UART0, &UART_InitStructure);
UART_Cmd(UART0, ENABLE);
}
/*******************************************************************************
* Function Name : Push_Button_Read
* Description : Read the port pin (connected to the push button) level.
* Input : None
* Output : None
* Return : The port pin level (SET or RESET).
*******************************************************************************/
static u8 Push_Button_Read (void)
{
/* Return the status of the Joystick button (Port 7) on the STR910-EVAL */
return GPIO_Read(GPIO7);
}
/*******************************************************************************
* Function Name : Push_Button_Config
* Description : Configures the port pin connected to the push button.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
static void Push_Button_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure1;
/*Enable Clock for GPIO7*/
SCU_APBPeriphClockConfig(__GPIO7, ENABLE);
/*Configure GPIO7: pin5, pin6 and pin7*/
GPIO_DeInit(GPIO7);
GPIO_StructInit(&GPIO_InitStructure1);
GPIO_InitStructure1.GPIO_Direction = GPIO_PinInput;
GPIO_InitStructure1.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure1.GPIO_Type = GPIO_Type_PushPull ;
GPIO_Init(GPIO7, &GPIO_InitStructure1);
}
/*******************************************************************************
* Function Name : main
* Description : Main program.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void main(void)
{
#ifdef DEBUG
debug();
#endif
Push_Button_Config();
if (Push_Button_Read() == 0x60) /* If Joystick position is 'Right' */
{
/* Execute the IAP driver in order to re-program the Flash */
IAP_Init();
SerialPutString("\r\n======================================================================");
SerialPutString("\r\n= (C) Copyright 2006 STMicroelecronics =");
SerialPutString("\r\n= =");
SerialPutString("\r\n= In-Application Programming Application (Version 1.0) =");
SerialPutString("\r\n= =");
SerialPutString("\r\n= By MCD Application Team =");
SerialPutString("\r\n======================================================================");
SerialPutString("\r\n\r\n");
Main_Menu ();
}
else
/* Keep the user application running */
{
Execute_STR9Application();
}
while (1);
}
/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -