| /* Includes ------------------------------------------------------------------*/ #include "stm32f10x_lib.h"
 #include "stm32f10x_it.h"
 #include "lcm.h"
 #include "avr2stm32.h"
 #include "display.h"
 #include "touchscreen.h"
 
 /* Private typedef -----------------------------------------------------------*/
 /* Private define ------------------------------------------------------------*/
 #define ADC1_DR_Address    ((u32)0x4001244C)
 
 /* Private macro -------------------------------------------------------------*/
 /* Private variables ---------------------------------------------------------*/
 ADC_InitTypeDef ADC_InitStructure;
 DMA_InitTypeDef DMA_InitStructure;
 vu16 ADC_ConvertedValue;
 ErrorStatus HSEStartUpStatus;
 
 /* Private function prototypes -----------------------------------------------*/
 void RCC_Configuration(void);
 void GPIO_Configuration(void);
 void NVIC_Configuration(void);
 void SysTick_Config(void);
 void TIM2_Init(void);
 
 /* Private functions ---------------------------------------------------------*/
 void delay(void);
 void delay()
 {
 int i = 0, j = 0;
 for (i=0; i<0xfffff; i++) j++;
 }
 
 volatile u32 flash_timer = 0;
 
 char display[4]={0,0};
 /*******************************************************************************
 * Function Name  : main
 * Description    : Main program
 * Input          : None
 * Output         : None
 * Return         : None
 *******************************************************************************/
 int main(void)
 {
 #ifdef DEBUG
 debug();
 #endif
 
 //u16 flash = 0;
 
 /* System clocks configuration ---------------------------------------------*/
 RCC_Configuration();
 
 /* NVIC configuration ------------------------------------------------------*/
 NVIC_Configuration();
 
 /* GPIO configuration ------------------------------------------------------*/
 GPIO_Configuration();
 
 /* Configure the systick */
 SysTick_Config();
 TIM2_Init();
 
 
 lcm_init();
 
 show_**();
 
 en_touch_init();
 
 while(1)
 {
 //u8 tmp = scan_touch();
 if(0x00000000 == flash_timer)
 {
 //if(0x02 == touch_state)
 {
 touch_state = 0x00;
 en_touch_init();
 flash_timer = 1000;
 GPIO_Write(GPIOC, GPIO_ReadOutputData(GPIOC) ^ GPIO_Pin_4);
 }
 }
 }
 }
 
 /*******************************************************************************
 * Function Name  : RCC_Configuration
 * Description    : Configures the different system clocks.
 * Input          : None
 * Output         : None
 * Return         : None
 *******************************************************************************/
 void RCC_Configuration(void)
 {
 /* 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);
 
 /* ADCCLK = PCLK2/4 */
 RCC_ADCCLKConfig(RCC_PCLK2_Div4);
 
 /* PLLCLK = 4MHz * 14 = 56 MHz */
 RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_14);
 
 /* 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 peripheral clocks --------------------------------------------------*/
 /* Enable DMA clock */
 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA, ENABLE);
 
 /* Enable ADC1 and GPIOC clock */
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_GPIOC, ENABLE);
 
 /* Enable GPIOA, GPIOB, GPIOC, GPIOD, GPIOE and AFIO clocks */
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |RCC_APB2Periph_GPIOC
 | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE);
 
 /* TIM2 clocks enable */
 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
 }
 
 /*******************************************************************************
 * Function Name  : GPIO_Configuration
 * Description    : Configures the different GPIO ports.
 * Input          : None
 * Output         : None
 * Return         : None
 *******************************************************************************/
 void GPIO_Configuration(void)
 {
 GPIO_InitTypeDef GPIO_InitStructure;
 
 lcm_dbus_dir(LCM_DBUS_IN);
 
 /*Configure PE.09 -- PE.10 as input pull_up; LCM_BUSY LCM_INT*/
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
 GPIO_Init(GPIOE, &GPIO_InitStructure);
 
 /*Configure PE.08 PE.11-- PE.15 as output push-pull; LCM_RST LCM_CS2 LCM_CS1 LCM_RD LCM_WR LCM RS*/
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 |
 GPIO_Pin_14 | GPIO_Pin_15;
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
 GPIO_Init(GPIOE, &GPIO_InitStructure);
 
 GPIO_Write(GPIOE, 0XFFFF);
 
 /* Configure PC.04 -- PC.11 as Output push-pull  : COM1~4 */
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
 GPIO_Init(GPIOC, &GPIO_InitStructure);
 }
 
 /*******************************************************************************
 * Function Name  : NVIC_Configuration
 * Description    : Configures Vector Table base location.
 * Input          : None
 * Output         : None
 * Return         : None
 *******************************************************************************/
 void NVIC_Configuration(void)
 {
 NVIC_InitTypeDef NVIC_InitStructure;
 
 #ifdef  VECT_TAB_RAM
 /* Set the Vector Table base location at 0x20000000 */
 NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
 #else  /* VECT_TAB_FLASH  */
 /* Set the Vector Table base location at 0x08000000 */
 NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
 #endif
 
 /* Configure the Priority Group to 2 bits */
 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
 
 /* enabling interrupt */
 //NVIC_InitStructure.NVIC_IRQChannel=USB_LP_CAN_RX0_IRQChannel;
 //NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
 //NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
 //NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
 //NVIC_Init(&NVIC_InitStructure);
 
 /* DISABLE the EXTI1 Interrupt */
 NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQChannel;
 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
 NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE;
 NVIC_Init(&NVIC_InitStructure);
 
 /* enabling interrupt */
 NVIC_InitStructure.NVIC_IRQChannel=TIM2_IRQChannel;
 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
 NVIC_Init(&NVIC_InitStructure);
 
 /* Configure the SysTick handler priority */
 NVIC_SystemHandlerPriorityConfig(SystemHandler_SysTick, 2, 0);
 }
 
 
 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);
 
 /* Enable the SysTick Counter */
 SysTick_CounterCmd(SysTick_Counter_Enable);
 }
 
 void TIM2_Init(void)
 {
 TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
 TIM_OCInitTypeDef  TIM_OCInitStructure;
 
 /* Time base configuration */
 TIM_TimeBaseStructure.TIM_Period = 8000;
 TIM_TimeBaseStructure.TIM_Prescaler = 17;
 TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
 TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
 
 TIM_ARRPreloadConfig(TIM2,DISABLE);
 /* only counter overflow/underflow generate U interrupt */
 TIM_UpdateRequestConfig(TIM2,TIM_UpdateSource_Regular);
 
 /* Output Compare Timing Mode configuration: Channel1 */
 TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;
 TIM_OCInitStructure.TIM_Channel = TIM_Channel_1;
 TIM_OCInitStructure.TIM_Pulse = 4000;
 TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
 TIM_OCInit(TIM2, &TIM_OCInitStructure);
 
 TIM_OC1PreloadConfig(TIM2, TIM_OCPreload_Disable);
 
 /* TIM IT enable */
 TIM_ITConfig(TIM2, TIM_IT_CC1 | TIM_IT_Update, ENABLE);
 
 /* TIM2 enable counter */
 TIM_Cmd(TIM2, ENABLE);
 }
 
 #ifdef  DEBUG
 /*******************************************************************************
 * Function Name  : assert_failed
 * Description    : Reports the name of the source file and the source line number
 *                  where the assert_param error has occurred.
 * Input          : - file: pointer to the source file name
 *                  - line: assert_param 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
", file, line) */
 
 /* Infinite loop */
 while (1)
 {
 }
 }
 #endif
 
 /******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/
 
 
 |