📄 main.c
字号:
/******************** (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.
*******************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "91x_lib.h"
#include "LCD.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
// Pll cfg
#define M (25UL) // PLL Pre-divider
#define P (4UL) // PLL Post-divider
#define N (48UL*P) // PLL Feedback divider
#define LED2 0x1
#define LED3 0x2
#define LED4 0x4
#define LED5 0x8
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
const char disp_ln1[] = "STR91x DEMO";
const char disp_ln2[] = "GPIO TEST";
/* Private function prototypes -----------------------------------------------*/
void SCU_Configuration(void);
void VIC_Configuration(void);
static void Delay(u32 nCount);
/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* Function Name : main
* Description : Main program
* Input : None
* Output : None
* Return : None
*******************************************************************************/
int main()
{
GPIO_InitTypeDef GPIO_InitStructure;
WIU_InitTypeDef WIU_InitStructure;
int i;
#ifdef DEBUG
debug();
#endif
/* Configure the system clocks */
SCU_Configuration();
GPIO_DeInit(GPIO2);
GPIO_DeInit(GPIO8);
GPIO_DeInit(GPIO6);
/* GPIO Configuration --------------------------------------------------------*/
//L2
GPIO_DeInit(GPIO9);
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
GPIO_Init (GPIO9, &GPIO_InitStructure);
//L3
GPIO_DeInit(GPIO3);
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt1;
GPIO_Init (GPIO3, &GPIO_InitStructure);
//L4
GPIO_DeInit(GPIO0);
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt1;
GPIO_Init (GPIO0, &GPIO_InitStructure);
//L5
// GPIO_DeInit(GPIO6);
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt1;
GPIO_Init (GPIO6, &GPIO_InitStructure);
//K5
// GPIO_DeInit(GPIO6);
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
GPIO_Init (GPIO6, &GPIO_InitStructure);
/*LCD Display -----------------------------------------------------------------*/
LCD_Init();
LCD_Clr();
LCD_SetCursor(0x02);
for(i=0;disp_ln1[i]!='\0';i++)
LCD_DISP_CHAR(disp_ln1[i]);
LCD_SetCursor(0x42);
for(i=0;disp_ln2[i]!='\0';i++)
LCD_DISP_CHAR(disp_ln2[i]);
// SCU_MCLKSourceConfig(SCU_MCLK_OSC); /*Main clock = OSC*/
/* Configure and enable the interrupt controller */
VIC_Configuration();
/* Clear the WIU line 21 pending bit */
WIU_ClearITPendingBit(WIU_Line21);
WIU_InitStructure.WIU_Mode = WIU_Mode_Interrupt ;
WIU_InitStructure.WIU_Line = WIU_Line21 ;
WIU_InitStructure.WIU_TriggerEdge = WIU_RisingEdge ;
WIU_Init(&WIU_InitStructure);
/*External interrupt------------------------------------------------------------*/
SCU_WakeUpLineConfig(21);
GPIO_WriteBit(GPIO9, GPIO_Pin_6, 1);
GPIO_WriteBit(GPIO3, GPIO_Pin_7, 1);
GPIO_WriteBit(GPIO0, GPIO_Pin_1, 1);
GPIO_WriteBit(GPIO6, GPIO_Pin_6, 1);
while(1)
{
/* Toggle leds connected to P9.6, P3.7, P0.1 and P6.6 pins */
switch(disp_led)
{
case LED2:
GPIO_WriteBit(GPIO9, GPIO_Pin_6, (BitAction)((1-GPIO_ReadBit(GPIO9, GPIO_Pin_6))));
break;
case LED3:
GPIO_WriteBit(GPIO3, GPIO_Pin_7, (BitAction)((1-GPIO_ReadBit(GPIO3, GPIO_Pin_7))));
break;
case LED4:
GPIO_WriteBit(GPIO0, GPIO_Pin_1, (BitAction)((1-GPIO_ReadBit(GPIO0, GPIO_Pin_1))));
break;
case LED5:
GPIO_WriteBit(GPIO6, GPIO_Pin_6, (BitAction)((1-GPIO_ReadBit(GPIO6, GPIO_Pin_6))));
break;
default:
break;
}
// Delay(0x7FFFF);
// Delay(0x7FFFF);
for(i=0;i<100;i++)
Delay(10000);
}
}
/*******************************************************************************
* Function Name : SCU_Configuration
* Description : Configures the system clocks.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void SCU_Configuration(void)
{
/*-------------------- System Clock Config --------------------*/
SCU_MCLKSourceConfig(SCU_MCLK_OSC);
SCU_PLLCmd(DISABLE);
SCU_PLLFactorsConfig(N,M,P);
SCU_PLLCmd(ENABLE);
while(!(SCU->SYSSTATUS&SCU_FLAG_LOCK));
SCU_MCLKSourceConfig(SCU_MCLK_PLL);
/* Enable the __GPIO9 __GPIO8 __GPIO6 __GPIO3 __GPIO2 __GPIO0*/
SCU_APBPeriphClockConfig(__GPIO9 ,ENABLE);
SCU_APBPeriphClockConfig(__GPIO3 ,ENABLE);
SCU_APBPeriphClockConfig(__GPIO0 ,ENABLE);
SCU_APBPeriphClockConfig(__GPIO2 ,ENABLE);
SCU_APBPeriphClockConfig(__GPIO6 ,ENABLE);
SCU_APBPeriphClockConfig(__GPIO8 ,ENABLE);
/* Enable WIU clock */
SCU_APBPeriphClockConfig(__WIU, ENABLE);
WIU_DeInit();
}
/*******************************************************************************
* Function Name : Delay
* Description : Inserts a delay time.
* Input : nCount: specifies the delay time length.
* Output : None
* Return : None
*******************************************************************************/
static void Delay(u32 nCount)
{
u32 j = 0;
for(j = nCount; j != 0; j--);
}
/*******************************************************************************
* Function Name : VIC_Configuration
* Description : This function configures and enables the interrupt controller.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void VIC_Configuration(void)
{
/* Enable VIC clock */
SCU_AHBPeriphClockConfig(__VIC,ENABLE);
VIC_DeInit();
VIC_InitDefaultVectors();
/* Configure the External interrupt group 2 priority */
VIC_Config(EXTIT2_ITLine, VIC_IRQ, 0);
/* Enable the External interrupt group 2 */
VIC_ITCmd(EXTIT2_ITLine, ENABLE);
}
/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -