/** * @brief Display Init (LCD) * @param None * @retval None */ void Display_Init(void) { /* Initialize the LCD */ #ifdef USE_STM320518_EVAL STM320518_LCD_Init(); #else STM32072B_LCD_Init(); #endif /* USE_STM320518_EVAL */ /* Clear the LCD */ LCD_Clear(White); /* Set the LCD Text size */ LCD_SetFont(&Font8x12); /* Set the LCD Back Color and Text Color*/ LCD_SetBackColor(Blue); LCD_SetTextColor(White); /* Display */ LCD_DisplayStringLine(LINE(0x13), " ADC conversion example (Basic example)"); /* Set the LCD Text size */ LCD_SetFont(&Font16x24); LCD_DisplayStringLine(LINE(0), MESSAGE1); LCD_DisplayStringLine(LINE(1), MESSAGE2); /* Set the LCD Back Color and Text Color*/ LCD_SetBackColor(White); LCD_SetTextColor(Blue); }
/** * @brief Display Init (LCD) * @param None * @retval None */ static void Display_Init(void) { /* Initialize the LCD */ #ifdef USE_STM320518_EVAL STM320518_LCD_Init(); #else STM32072B_LCD_Init(); #endif /* USE_STM320518_EVAL */ /* Clear the LCD */ LCD_Clear(LCD_COLOR_WHITE); /* Set the LCD Back Color */ LCD_SetBackColor(Blue); /* Set the LCD Text Color */ LCD_SetTextColor(White); /* Displays MESSAGE1 on line 1 */ LCD_DisplayStringLine(LINE(0), (uint8_t *)MESSAGE1); /* Set the LCD Text Color */ LCD_SetTextColor(Red); /* Set the LCD Back Color */ LCD_SetBackColor(Red); LCD_DrawFullRect(31, 292,264,34); /* Set the LCD Back Color */ LCD_SetBackColor(White); LCD_DrawFullRect(33, 290 ,260,30); /* Set the LCD Text, Back Colors and Text size */ LCD_SetTextColor(Black); LCD_SetBackColor(Cyan); LCD_SetFont(&Font12x12); LCD_DisplayStringLine(LINE(18), (uint8_t *)MESSAGE2); /* Set the LCD Back Color */ LCD_SetBackColor(Blue); LCD_SetTextColor(White); LCD_DisplayStringLine(LINE(19), (uint8_t *)MESSAGE3); /* Set text size */ LCD_SetFont(&Font16x24); /* Set the LCD Text Color */ LCD_SetTextColor(Blue); }
/** * @brief Display Init (LCD) * @param None * @retval None */ static void Display_Init(void) { /* Initialize the LCD */ #ifdef USE_STM320518_EVAL STM320518_LCD_Init(); #elif defined (USE_STM32072B_EVAL) STM32072B_LCD_Init(); #endif /* USE_STM320518_EVAL */ /* Clear the LCD */ LCD_Clear(White); /* Set the LCD Text size */ LCD_SetFont(&Font8x12); /* Set the LCD Back Color and Text Color*/ LCD_SetBackColor(Blue); LCD_SetTextColor(White); /* Display */ LCD_DisplayStringLine(LINE(0x13), " ADC Analog Watchdog example "); /* Set the LCD Text size */ LCD_SetFont(&Font16x24); LCD_DisplayStringLine(LINE(0), MESSAGE1); LCD_DisplayStringLine(LINE(1), MESSAGE2); /* Set the LCD Back Color and Text Color*/ LCD_SetBackColor(White); LCD_SetTextColor(Blue); /* Display */ LCD_DisplayStringLine(LINE(3), MESSAGE3); LCD_DisplayStringLine(LINE(4), MESSAGE4); /* Set the LCD Text size */ LCD_SetFont(&Font12x12); LCD_SetTextColor(Green); LCD_DisplayStringLine(LINE(12),"AWD High threshold = 2.5 V"); LCD_DisplayStringLine(LINE(13),"AWD Low threshold = 1.5 V"); /* Set the LCD Text size */ LCD_SetFont(&Font16x24); LCD_SetTextColor(Blue); }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f0xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file */ /* Initialize the LCD */ #ifdef USE_STM320518_EVAL STM320518_LCD_Init(); #else STM32072B_LCD_Init(); #endif /* USE_STM320518_EVAL */ /* Enable The Display */ LCD_DisplayOn(); /* Clear the Background Layer */ LCD_Clear(LCD_COLOR_WHITE); /* Clear the LCD */ LCD_Clear(White); /* Set the LCD Back Color */ LCD_SetBackColor(Blue); /* Set the LCD Text Color */ LCD_SetTextColor(White); /* Displays MESSAGE1 on line 0 */ LCD_DisplayStringLine(LINE(0), (uint8_t *)MESSAGE1); /* RTC configuration */ RTC_Config(); /* Set the LCD Text Color */ LCD_SetTextColor(Red); /* Displays a rectangle on the LCD */ LCD_DrawRect(80, 280, 25, 240 ); /* Configure the external interrupt "WAKEUP" and "TAMPER" buttons */ STM_EVAL_PBInit(BUTTON_SEL, BUTTON_MODE_EXTI); STM_EVAL_PBInit(BUTTON_TAMPER, BUTTON_MODE_EXTI); /* Configure RTC AlarmA register to generate 8 interrupts per 1 Second */ RTC_AlarmConfig(); /* set LCD Font */ LCD_SetFont(&Font12x12); /* Set the LCD Back Color */ LCD_SetBackColor(White); /* Set the LCD Text Color */ LCD_SetTextColor(Black); /* Set the Back Color */ LCD_SetBackColor(LCD_COLOR_CYAN); /* Displays MESSAGE2 and MESSAGE3 on the LCD */ LCD_DisplayStringLine(LINE(18), (uint8_t *)MESSAGE2); LCD_DisplayStringLine(LINE(19), (uint8_t *)MESSAGE3); /* Infinite loop */ while (1) { uint32_t tmp =0; /* ALARM Interrupt */ if (ALARM_Occured) { if(RTCAlarmCount != 480) { /* Increament the counter of Alarma interrupts */ RTCAlarmCount++; /* Set the LCD Back Color */ LCD_SetTextColor(Green); /* Draw rectangle on the LCD */ LCD_DrawFullRect(81, 359, 80+ (((RTCAlarmCount)-1)/2) , 24); /* Set the LCD text color */ LCD_SetTextColor(Red); /* Display rectangle on the LCD */ LCD_DrawRect(80, 280, 25, 240 ); /* Define the rate of Progress bar */ tmp = (RTCAlarmCount * 100)/ 480; /* Set the LCD Font */ LCD_SetFont(&Font16x24); /* Display Char on the LCD : XXX% */ LCD_DisplayChar(LINE(2),200, (tmp / 100) +0x30); LCD_DisplayChar(LINE(2),180, ((tmp % 100 ) / 10) +0x30); LCD_DisplayChar(LINE(2),160, (tmp % 10) +0x30); LCD_DisplayChar(LINE(2),140, 0x25); } else { /* Disable the RTC Clock */ RCC_RTCCLKCmd(DISABLE); } /* Reinitialize the ALARM variable */ ALARM_Occured = 0; } } }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f0xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file */ /* Initialize the LCD */ STM32072B_LCD_Init(); /* Clear the LCD */ LCD_Clear(LCD_COLOR_WHITE); /* Set the LCD Back Color */ LCD_SetBackColor(Blue); /* Set the LCD Text Color */ LCD_SetTextColor(White); /* Displays MESSAGE1 on line 0 */ LCD_DisplayStringLine(LINE(0), (uint8_t *)MESSAGE1); LCD_SetFont(&Font12x12); /* Display Messages on the the LCD */ LCD_DisplayStringLine(LINE(0x3), (uint8_t *)MESSAGE2); /* Set the LCD Text size */ LCD_SetFont(&Font16x24); /* Configure Push button key */ STM_EVAL_PBInit(BUTTON_TAMPER, BUTTON_MODE_GPIO); /* CAN configuration */ CAN_Config(); /* Infinite loop */ while(1) { while(STM_EVAL_PBGetState(BUTTON_TAMPER) == TAMPER_PRESSED) { if(KeyNumber == 41) KeyNumber = 0; Display_TransmittedMsg(KeyNumber); KeyNumber++; Delay(); while(STM_EVAL_PBGetState(BUTTON_TAMPER) != TAMPER_NOT_PRESSED) { } } if (MsgReceived != 0) { /* Display received the 6 messages on tghe LCD */ Display_ReceivedMsg(); MsgReceived = 0; } } }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f0xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file */ /* Initialize the LCD */ STM32072B_LCD_Init(); /* Clear the LCD */ LCD_Clear(LCD_COLOR_WHITE); /* Set the LCD Back Color */ LCD_SetBackColor(Blue); /* Set the LCD Text Color */ LCD_SetTextColor(White); /* Displays MESSAGE1 on line 0 */ LCD_DisplayStringLine(LINE(0), (uint8_t *)MESSAGE1); /* Set the LCD Text size */ LCD_SetFont(&Font8x12); /* Display */ LCD_DisplayStringLine(LINE(0x13), "CAN CAN_DualFIFO using FIFO 0 and FIFO 1 "); /* Set the LCD Back Color */ LCD_SetBackColor(White); /* Set the LCD Text Color */ LCD_SetTextColor(Blue); /* Set the LCD Text size */ LCD_SetFont(&Font12x12); /* Display Messages on the the LCD */ LCD_DisplayStringLine(LINE(0x7), (uint8_t *)MESSAGE2); LCD_DisplayStringLine(LINE(0x8), (uint8_t *)MESSAGE3); /* Set the LCD Text size */ LCD_SetFont(&Font16x24); /* Configures LED 1..4 */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* Configure Push button key */ STM_EVAL_PBInit(BUTTON_TAMPER, BUTTON_MODE_EXTI); /* Configure Push button sel */ STM_EVAL_PBInit(BUTTON_SEL, BUTTON_MODE_EXTI); /* CAN configuration */ CAN_Config(); /* Infinite loop */ while(1) { } }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f0xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file */ /* Initialize the LCD */ #ifdef USE_STM320518_EVAL STM320518_LCD_Init(); #else STM32072B_LCD_Init(); #endif /* USE_STM320518_EVAL */ /* Initialize LEDs available on STM320518-EVAL board */ /* Configure LED1, LED2, LED3 and LED4 */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); #if defined (DEVICE_1) MyLogicalAddress1 = DEVICE_ADDRESS_1; MyFollowerAddress = DEVICE_ADDRESS_2; #elif defined (DEVICE_2) MyLogicalAddress1 = DEVICE_ADDRESS_2; MyFollowerAddress = DEVICE_ADDRESS_1; #elif defined (DEVICE_3) MyLogicalAddress1 = DEVICE_ADDRESS_3; #endif /* DEVICE_1 */ /* CEC configuration */ CEC_Config(); #if defined (DEVICE_3) LCD_Clear(LCD_COLOR_WHITE); LCD_SetBackColor(LCD_COLOR_BLACK); LCD_SetTextColor(LCD_COLOR_WHITE); LCD_DisplayStringLine(LCD_LINE_0, (uint8_t *)" Spy CEC Device "); #else /* Configure the Joystick button and its associated EXTI Line */ STM_EVAL_PBInit(BUTTON_RIGHT, BUTTON_MODE_EXTI); STM_EVAL_PBInit(BUTTON_LEFT, BUTTON_MODE_EXTI); STM_EVAL_PBInit(Button_UP, BUTTON_MODE_EXTI); STM_EVAL_PBInit(Button_DOWN, BUTTON_MODE_EXTI); /* Build the Header block to send */ HeaderBlockValueToSend = (((MyLogicalAddress1 & 0xF) << 4)|(MyFollowerAddress & 0xF)); /* Clear the LCD */ LCD_Clear(LCD_COLOR_BLUE); LCD_SetBackColor(LCD_COLOR_BLACK); LCD_SetTextColor(LCD_COLOR_WHITE); LCD_DisplayStringLine(LCD_LINE_0, (uint8_t *)" Select CEC Command "); LCD_SetBackColor(LCD_COLOR_BLUE); LCD_SetTextColor(LCD_COLOR_WHITE); LCD_DisplayStringLine(LCD_LINE_2, (uint8_t *)"RIGHT : OSD Name "); LCD_DisplayStringLine(LCD_LINE_3, (uint8_t *)"LEFT : CEC Version "); LCD_DisplayStringLine(LCD_LINE_4, (uint8_t *)"UP : Volume Up "); LCD_DisplayStringLine(LCD_LINE_5, (uint8_t *)"DOWN : Volume Down "); #endif /* DEVICE_3 */ while(1) { /* If a frame has been received */ while(ReceivedFrame1 == 0) {} if (ReceivedFrame1 == 1) { /* OK */ if (ReceiveBuffer[1] ==0x44) /* Test on the opcode value */ { /* Receive command is equal to Volume Up(Button Up) */ if (ReceiveBuffer[2] == 0x41) /* Test on the operand value */ { STM_EVAL_LEDOn(LED1); STM_EVAL_LEDOn(LED2); STM_EVAL_LEDOn(LED3); STM_EVAL_LEDOn(LED4); }/* Test on the operand value */ else if (ReceiveBuffer[2] == 0x42) /* Receive command is equal to Volume Down(Button Down) */ { STM_EVAL_LEDOff(LED1); STM_EVAL_LEDOff(LED2); STM_EVAL_LEDOff(LED3); STM_EVAL_LEDOff(LED4); } } else if (ReceiveBuffer[1] ==0x46) /* Test on the opcode value */ { STM_EVAL_LEDOn(LED1); STM_EVAL_LEDOn(LED2); STM_EVAL_LEDOff(LED3); STM_EVAL_LEDOff(LED4); } else if (ReceiveBuffer[1] ==0x9F) /* Test on the opcode value */ { STM_EVAL_LEDOff(LED1); STM_EVAL_LEDOff(LED2); STM_EVAL_LEDOn(LED3); STM_EVAL_LEDOn(LED4); } LCD_SetBackColor(LCD_COLOR_GREEN); LCD_DisplayStringLine(LCD_LINE_7, (uint8_t *)"Receive : Succeeded "); } else { /* KO */ /* Turn on LED2 */ STM_EVAL_LEDOn(LED3); LCD_SetBackColor(LCD_COLOR_RED); LCD_DisplayStringLine(LCD_LINE_7, (uint8_t *)"Receive : Failed "); } ReceivedFrame1 = 0; for (rcv_inc=0;rcv_inc<10;rcv_inc++) { ReceiveBuffer[rcv_inc]=0; } rcv_inc=0; } }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f0xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file */ /* Configure Clocks */ RCC_Config(); /* Initialize LEDsand LCD available on EVAL board ***************************/ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* Initialize the LCD */ #ifdef USE_STM320518_EVAL STM320518_LCD_Init(); #else STM32072B_LCD_Init(); #endif /* USE_STM320518_EVAL */ /* Display message on LCD ***********************************************/ /* Clear the LCD */ LCD_Clear(White); /* Set the LCD Back Color */ LCD_SetBackColor(Blue); /* Set the LCD Text Color */ LCD_SetTextColor(Yellow); LCD_DisplayStringLine(Line0, MESSAGE1); LCD_DisplayStringLine(Line1, MESSAGE2); /* Set the LCD Back Color */ LCD_SetBackColor(White); /* Set the LCD Text Color */ LCD_SetTextColor(Blue); /* Configure the Push buttons in Polling mode */ STM_EVAL_PBInit(BUTTON_SEL, Mode_GPIO); /* if STM32 device is set as Master */ #ifdef I2C_MASTER /* Configure and enable the systick timer to generate an interrupt each 1 ms */ SysTick_Config((SystemCoreClock / 1000)); /* Deinitialize I2Cx Device */ CPAL_I2C_DeInit(&MASTERSTRUCTURE); /* Initialize CPAL I2C structure parameters values */ CPAL_I2C_StructInit(&MASTERSTRUCTURE); #ifdef CPAL_I2C_DMA_PROGMODEL MASTERSTRUCTURE.wCPAL_Options = CPAL_OPT_NO_MEM_ADDR | CPAL_OPT_DMATX_TCIT; MASTERSTRUCTURE.CPAL_ProgModel = CPAL_PROGMODEL_DMA; #elif defined (CPAL_I2C_IT_PROGMODEL) MASTERSTRUCTURE.wCPAL_Options = CPAL_OPT_NO_MEM_ADDR; MASTERSTRUCTURE.CPAL_ProgModel = CPAL_PROGMODEL_INTERRUPT; #else #error "Please select one of the programming model (in main.h)" #endif /* Set I2C Speed */ MASTERSTRUCTURE.pCPAL_I2C_Struct->I2C_Timing = MASTER_I2C_TIMING; /* Select Master Mode */ MASTERSTRUCTURE.CPAL_Mode = CPAL_MODE_MASTER; /* Initialize I2Cx Device*/ CPAL_I2C_Init(&MASTERSTRUCTURE); /* Infinite loop */ while(1) { /* Initialize Transfer parameters */ MASTERSTRUCTURE.pCPAL_TransferTx = &sTxStructure; sTxStructure.wNumData = BufferSize; sTxStructure.pbBuffer = (uint8_t*)BufferTX; sTxStructure.wAddr1 = OWNADDRESS; /* Update LCD Display */ LCD_SetBackColor(White); LCD_SetTextColor(Blue); LCD_DisplayStringLine(Line8, MEASSAGE_EMPTY); LCD_DisplayStringLine(Line5, MESSAGE4); LCD_DisplayStringLine(Line6, MESSAGE5); /* wait until Key button is pushed */ while(! STM_EVAL_PBGetState(BUTTON_SEL)); /* Update LCD Display */ LCD_DisplayStringLine(Line5, MEASSAGE_EMPTY); LCD_DisplayStringLine(Line6, MEASSAGE_EMPTY); /* Write operation */ CPAL_I2C_Write(&MASTERSTRUCTURE); /* Wait until communication finishes */ while ((MASTERSTRUCTURE.CPAL_State != CPAL_STATE_READY) && (MASTERSTRUCTURE.CPAL_State != CPAL_STATE_ERROR)); if (TransferStatus == PASSED) { /* Update LCD Display */ LCD_SetBackColor(Red); LCD_SetTextColor(White); LCD_DisplayStringLine(Line8, MESSAGE6); } else { TransferStatus = PASSED; } Delay(1000); } #endif /* I2C_MASTER */ /* if STM32 device is set as Slave */ #ifdef I2C_SLAVE /* GPIOA Periph clock enable */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); /* Output System Clock on MCO pin (PA.08) */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); #ifdef USE_STM320518_EVAL RCC_MCOConfig(RCC_MCOSource_SYSCLK); #else RCC_MCOConfig(RCC_MCOSource_SYSCLK, RCC_MCOPrescaler_1); #endif /* USE_STM320518_EVAL */ /* Deinitialize I2Cx Device */ CPAL_I2C_DeInit(&SLAVESTRUCTURE); /* Initialize CPAL I2C structure parameters values */ CPAL_I2C_StructInit(&SLAVESTRUCTURE); #ifdef CPAL_I2C_DMA_PROGMODEL SLAVESTRUCTURE.wCPAL_Options = CPAL_OPT_I2C_NACK_ADD | CPAL_OPT_I2C_WAKEUP_STOP | CPAL_OPT_DMARX_TCIT; SLAVESTRUCTURE.CPAL_ProgModel = CPAL_PROGMODEL_DMA; #elif defined (CPAL_I2C_IT_PROGMODEL) SLAVESTRUCTURE.wCPAL_Options = CPAL_OPT_I2C_NACK_ADD | CPAL_OPT_I2C_WAKEUP_STOP; SLAVESTRUCTURE.CPAL_ProgModel = CPAL_PROGMODEL_INTERRUPT; #else #error "Please select one of the programming model (in main.h)" #endif /* Configure Own address 1 */ SLAVESTRUCTURE.pCPAL_I2C_Struct->I2C_OwnAddress1 = OWNADDRESS; /* Set I2C Speed */ SLAVESTRUCTURE.pCPAL_I2C_Struct->I2C_Timing = SLAVE_I2C_TIMING; /* Select Slave Mode */ SLAVESTRUCTURE.CPAL_Mode = CPAL_MODE_SLAVE; /* Initialize I2Cx Device*/ CPAL_I2C_Init(&SLAVESTRUCTURE); /* Infinite loop */ while(1) { /* Reset BufferRX value */ Reset_bBuffer(BufferRX, (uint16_t)BufferSize); /* Initialize Transfer parameters */ SLAVESTRUCTURE.pCPAL_TransferRx = &sRxStructure; sRxStructure.wNumData = BufferSize; sRxStructure.pbBuffer = (uint8_t*)BufferRX; /* Update LCD Display */ LCD_SetBackColor(White); LCD_SetTextColor(Blue); LCD_DisplayStringLine(Line8, MEASSAGE_EMPTY); LCD_DisplayStringLine(Line9, MEASSAGE_EMPTY); LCD_DisplayStringLine(Line5, MESSAGE7); Delay(1000); /* Update LCD Display */ LCD_DisplayStringLine(Line5, MEASSAGE_EMPTY); LCD_DisplayStringLine(Line6, MESSAGE8); /* Read operation */ CPAL_I2C_Read(&SLAVESTRUCTURE); /* Enter Stop Mode and wait for interrupt to wake up */ PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); /* Wait until communication finishes */ while ((SLAVESTRUCTURE.CPAL_State != CPAL_STATE_READY) && (SLAVESTRUCTURE.CPAL_State != CPAL_STATE_ERROR)); /* Configure SystemClock*/ Restore_Configuration(); /* Configure and enable the systick timer to generate an interrupt each 1 ms */ SysTick_Config((SystemCoreClock / 1000)); /* Update LCD Display */ LCD_DisplayStringLine(Line6, MEASSAGE_EMPTY); LCD_SetBackColor(Red); LCD_SetTextColor(White); LCD_DisplayStringLine(Line8, MESSAGE9); /* If are received correctly */ if (Compare_bBuffer((uint8_t*)BufferTX, BufferRX, BufferSize) == PASSED ) { /* Update LCD Display */ LCD_DisplayStringLine(Line9, MESSAGE6); } else { /* Update LCD Display */ LCD_DisplayStringLine(Line9, MESSAGE10); } Delay(1500); } #endif /* I2C_SLAVE */ }
/** * @brief Main program * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f4xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f4xx.c file */ #if defined (RTC_CLOCK_SOURCE_LSI) /* Enable the LSI OSC */ RCC_LSICmd(ENABLE); #endif /* RTC_CLOCK_SOURCE_LSI */ /* Configure the external interrupt "WAKEUP" and "TAMPER" buttons */ STM_EVAL_PBInit(BUTTON_TAMPER , BUTTON_MODE_EXTI); STM_EVAL_PBInit(BUTTON_SEL , BUTTON_MODE_EXTI); /* Configure LEDs */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDOn(LED1); /* Initialize the LCD */ #ifdef USE_STM320518_EVAL STM320518_LCD_Init(); #else STM32072B_LCD_Init(); #endif /* USE_STM320518_EVAL */ /* Clear the LCD */ LCD_Clear(White); /* Enable The Display */ LCD_DisplayOn(); /* Set the LCD Back Color and Text Color*/ LCD_SetBackColor(Blue); LCD_SetTextColor(White); LCD_DisplayStringLine(LCD_LINE_0,(uint8_t *) " TimeStamp Example " ); /* Set the LCD Text size */ LCD_SetFont(&Font16x24); if (RTC_ReadBackupRegister(RTC_BKP_DR0) != 0x32F2) { /* RTC configuration */ RTC_Config(); /* Configure the time&date register */ RTC_TimeRegulate(); /* Display the Date */ RTC_DateShow(); /* Display the Time */ RTC_TimeShow(); } else { /* Check if the Power On Reset flag is set */ if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET) { /* Set the Back Color */ LCD_SetBackColor(LCD_COLOR_CYAN); /* Set the Text Color */ LCD_SetTextColor(LCD_COLOR_BLACK); LCD_SetFont(&Font12x12); LCD_DisplayStringLine(LCD_LINE_2,(uint8_t *) " Power On Reset occurred " ); } /* Check if the Pin Reset flag is set */ else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET) { /* Set the Back Color */ LCD_SetBackColor(LCD_COLOR_CYAN); /* Set the Text Color */ LCD_SetTextColor(LCD_COLOR_BLACK); LCD_SetFont(&Font12x12); LCD_DisplayStringLine(LCD_LINE_2,(uint8_t *) " External Reset occurred " ); } /* Set the Back Color */ LCD_SetBackColor(LCD_COLOR_CYAN); /* Set the Text Color */ LCD_SetTextColor(LCD_COLOR_BLACK); LCD_SetFont(&Font12x12); LCD_DisplayStringLine(LCD_LINE_3,(uint8_t *) " No need to configure RTC " ); /* Enable the PWR clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Allow access to RTC */ PWR_BackupAccessCmd(ENABLE); /* Wait for RTC APB registers synchronisation */ RTC_WaitForSynchro(); /* Clear the RTC Alarm Flag */ RTC_ClearFlag(RTC_FLAG_ALRAF); /* Clear the EXTI Line 17 Pending bit (Connected internally to RTC Alarm) */ EXTI_ClearITPendingBit(EXTI_Line17); /* Display the RTC Time/Date and TimeStamp Time/Date */ RTC_DateShow(); RTC_TimeShow(); } while (1) { if (Button_State == TAMPER_ON) { /* Turn LED4 ON */ STM_EVAL_LEDOn(LED2); LCD_SetFont(&Font12x12); LCD_DisplayStringLine(LCD_LINE_5,(uint8_t *) " TimeStamp Event Occurred " ); LCD_SetFont(&Font16x24); LCD_ClearLine(LCD_LINE_4); LCD_ClearLine(LCD_LINE_5); LCD_ClearLine(LCD_LINE_6); LCD_ClearLine(LCD_LINE_7); LCD_ClearLine(LCD_LINE_8); /* Display the TimeStamp */ RTC_TimeStampShow(); Button_State = 0; } else if (Button_State == SEL_ON) { /* Turn LED1 ON and LED2 OFF */ STM_EVAL_LEDOn(LED1); STM_EVAL_LEDOff(LED2); /* Clear The TSF Flag (Clear TimeStamp Registers) */ RTC_ClearFlag(RTC_FLAG_TSF); LCD_SetFont(&Font12x12); LCD_ClearLine(LCD_LINE_5); LCD_SetFont(&Font12x12); LCD_DisplayStringLine(LCD_LINE_5,(uint8_t *) " TimeStamp Event Cleared " ); Button_State = 0; } } }