/******************************************************************************* * Function Name : Alarm_Adjust * Description : Adjusts an alarm event to occurs within the current day. * Input : None * Output : None * Return : None *******************************************************************************/ void Alarm_Adjust(void) { /* Disable the JoyStick interrupts */ IntExtOnOffConfig(DISABLE); while(ReadKey() != NOKEY) { } RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE); /* Clear the LCD screen */ LCD_Clear(White); LCD_SetDisplayWindow(160, 223, 128, 128); LCD_NORDisplay(ALARM_ICON); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE); /* Disable LCD Window mode */ LCD_WindowModeDisable(); Alarm_PreAdjust(); /* Clear the LCD */ LCD_Clear(White); /* Display the menu */ DisplayMenu(); /* Enable the JoyStick interrupts */ IntExtOnOffConfig(ENABLE); }
/******************************************************************************* * Function Name : Mass_Storage_Start * Description : Starts the mass storage demo. * Input : None * Output : None * Return : None *******************************************************************************/ void Mass_Storage_Start (void) { /* Disble the JoyStick interrupts */ IntExtOnOffConfig(DISABLE); /* Clear the LCD screen */ LCD_Clear(White); LCD_SetDisplayWindow(160, 223, 128, 128); LCD_DrawBMP(0x00647C00); /* Disable LCD Window mode */ LCD_WindowModeDisable(); /* Set the Back Color */ LCD_SetBackColor(Blue); /* Set the Text Color */ LCD_SetTextColor(White); if(MSD_Init() != 0x00) { LCD_DisplayStringLine(Line8, " No MSD Card Present"); LCD_DisplayStringLine(Line9, " To exit Press SEL "); /* Loop until SEL key pressed */ while(ReadKey() != SEL) { } } else { Get_Medium_Characteristics(); /* Display the " Plug the USB " message */ LCD_DisplayStringLine(Line8, " Plug the USB Cable "); LCD_DisplayStringLine(Line9, "Exit: Push JoyStick"); /* Intialize the USB cell */ USB_Init(); LCD_ClearLine(Line9); /* Display the "To stop Press SEL" message */ LCD_DisplayStringLine(Line8, " To stop Press SEL "); /* Loop until SEL key pressed */ while(ReadKey() != SEL) { } PowerOff(); } LCD_Clear(White); DisplayMenu(); IntExtOnOffConfig(ENABLE); /* Flush SPI1 Data Register */ SPI_I2S_ReceiveData(SPI1); }
/******************************************************************************* * Function Name : LCD_DrawRect * Description : Displays a rectangle. * Input : - Xpos: specifies the X position. * - Ypos: specifies the Y position. * - Height: display rectangle height. * - Width: display rectangle width. * Output : None * Return : None *******************************************************************************/ void LCD_DrawRectFill(u8 Xpos, u16 Ypos, u8 Width, u16 Height,u16 fill){ u8 j; LCD_SetDisplayWindow(Xpos,Ypos,Width,Height); LCD_WriteRAM_Prepare(); for(Height=Height;Height>0;Height--) for(j=Width;j>0;j--) LCD_WriteRAM(fill); LCD_WriteRAM_Ready(); LCD_WindowModeDisable(); }
/** * @brief RCR receiver demo exec. * @param None * @retval None */ void Menu_RC5Decode_Func(void) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_OCInitTypeDef TIM_OCInitStructure; /* Disable the TIM15, LED Toggling */ TIM_Cmd(TIM15, DISABLE); /* Disable the JoyStick interrupt */ Demo_IntExtOnOffCmd(DISABLE); while (Menu_ReadKey() != NOKEY) {} /* Clear the LCD */ LCD_Clear(LCD_COLOR_WHITE); /* Display Image */ LCD_SetDisplayWindow(120, 192, 64, 64); Storage_OpenReadFile(120, 192, "STFILES/TV.BMP"); LCD_WindowModeDisable(); /* Set the LCD Back Color */ LCD_SetBackColor(LCD_COLOR_BLUE); /* Set the LCD Text Color */ LCD_SetTextColor(LCD_COLOR_WHITE); LCD_DisplayStringLine(LCD_LINE_9, " To exit press UP "); /* Initialize the InfraRed application: RC5 */ RFDemoStatus = RC5DEMO; RC5_Init(); while(Menu_ReadKey() != UP) { /* Decode the RC5 frame */ RC5_Decode(&RC5_FRAME); } LCD_Clear(LCD_COLOR_WHITE); TIM_DeInit(TIM2); /* Time Base configuration 100ms*/ TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); TIM_TimeBaseStructure.TIM_Prescaler = 1000; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseStructure.TIM_Period = 0x0C80; TIM_TimeBaseStructure.TIM_ClockDivision = 0x0; TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); /* Channel 1, 2, 3 and 4 Configuration in Timing mode */ TIM_OCStructInit(&TIM_OCInitStructure); TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = 0x0; TIM_OC1Init(TIM2, &TIM_OCInitStructure); Demo_LedShow(ENABLE); /* Exit the RF5 demo */ RFDemoStatus = 0; /* Enable the JoyStick interrupt */ Demo_IntExtOnOffCmd(ENABLE); /* Display menu */ Menu_DisplayMenu(); }
/******************************************************************************* * Function Name : Time_Show * Description : Shows the current time (HH/MM/SS) on LCD. * Input : None * Output : None * Return : None ******************************************************************************/ void Time_Show(void) { uint32_t testvalue = 0, pressedkey = 0; /* Set the Back Color */ LCD_SetBackColor(White); /* Set the Text Color */ LCD_SetTextColor(Blue); /* Disable the JoyStick interrupts */ IntExtOnOffConfig(DISABLE); while(ReadKey()!= NOKEY) { } RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE); /* Clear the LCD screen */ LCD_Clear(White); LCD_SetDisplayWindow(160, 223, 128, 128); LCD_NORDisplay(WATCH_ICON); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE); /* Disable LCD Window mode */ LCD_WindowModeDisable(); if(BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5) { LCD_DisplayStringLine(Line7, "Time and Date Config"); LCD_DisplayStringLine(Line8, "Select: Press SEL "); LCD_DisplayStringLine(Line9, "Abort: Press Any Key"); while(testvalue == 0) { pressedkey = ReadKey(); if(pressedkey == SEL) { /* Adjust Time */ Time_PreAdjust(); /* Clear the LCD */ LCD_Clear(White); testvalue = 0x01; } else if (pressedkey != NOKEY) { /* Clear the LCD */ LCD_ClearLine(Line8); /* Display the menu */ DisplayMenu(); /* Enable the JoyStick interrupts */ IntExtOnOffConfig(ENABLE); return; } } /* Display time separators ":" on Line8 */ LCD_DisplayChar(Line8, 212, ':'); LCD_DisplayChar(Line8, 166, ':'); /* Wait a press on any JoyStick pushbuttons */ while(ReadKey() == NOKEY) { /* Display current time */ Time_Display(RTC_GetCounter()); } } else { while(ReadKey() != NOKEY) { } /* Display time separators ":" on Line8 */ LCD_DisplayChar(Line8, 212, ':'); LCD_DisplayChar(Line8, 166, ':'); /* Wait a press on any JoyStick pushbuttons */ while(ReadKey() == NOKEY) { /* Display current time */ Time_Display(RTC_GetCounter()); } } /* Clear the LCD */ LCD_ClearLine(Line8); /* Display the menu */ DisplayMenu(); /* Enable the JoyStick interrupts */ IntExtOnOffConfig(ENABLE); }
/******************************************************************************* * Function Name : Time_PreAdjust * Description : Returns the time entered by user, using demoboard keys. * Input : None * Output : None * Return : None *******************************************************************************/ static void Time_PreAdjust(void) { RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE); /* Clear the LCD screen */ LCD_Clear(White); LCD_SetDisplayWindow(160, 223, 128, 128); LCD_NORDisplay(WATCH_ICON); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE); /* Disable LCD Window mode */ LCD_WindowModeDisable(); if(BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5) { RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); /* Allow access to BKP Domain */ PWR_BackupAccessCmd(ENABLE); LCD_DisplayStringLine(Line7, "RTC Config PLZ Wait."); /* RTC Configuration */ RTC_Configuration(); LCD_DisplayStringLine(Line7, " TIME "); /* Clear Line8 */ LCD_ClearLine(Line8); /* Display time separators ":" on Line4 */ LCD_DisplayChar(Line8, 212, ':'); LCD_DisplayChar(Line8, 166, ':'); /* Display the current time */ Time_Display(RTC_GetCounter()); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); /* Change the current time */ RTC_SetCounter(Time_Regulate()); BKP_WriteBackupRegister(BKP_DR1, 0xA5A5); /* Clear Line7 */ LCD_ClearLine(Line7); /* Clear Line8 */ LCD_ClearLine(Line8); /* Adjust Date */ Date_PreAdjust(); } else { /* Clear Line8 */ LCD_ClearLine(Line8); /* Display time separators ":" on Line4 */ LCD_DisplayChar(Line8, 212, ':'); LCD_DisplayChar(Line8, 166, ':'); /* Display the current time */ Time_Display(RTC_GetCounter()); /* Wait until last write operation on RTC registers has finished */ RTC_WaitForLastTask(); /* Change the current time */ RTC_SetCounter(Time_Regulate()); } }
/******************************************************************************* * Function Name : Alarm_Show * Description : Shows alarm time (HH/MM/SS) on LCD. * Input : None * Output : None * Return : None *******************************************************************************/ void Alarm_Show(void) { uint32_t tmp = 0; /* Disable the JoyStick interrupts */ IntExtOnOffConfig(DISABLE); while(ReadKey() != NOKEY) { } RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE); /* Clear the LCD screen */ LCD_Clear(White); LCD_SetDisplayWindow(160, 223, 128, 128); LCD_NORDisplay(ALARM_ICON); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE); /* Disable LCD Window mode */ LCD_WindowModeDisable(); /* Set the LCD Back Color */ LCD_SetBackColor(Blue); /* Set the LCD Text Color */ LCD_SetTextColor(White); if(BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5) { LCD_DisplayStringLine(Line8, "Time not configured "); LCD_DisplayStringLine(Line9, " Press SEL "); while(ReadKey() == NOKEY) { } /* Clear the LCD */ LCD_Clear(White); /* Display the menu */ DisplayMenu(); /* Enable the JoyStick interrupts */ IntExtOnOffConfig(ENABLE); return; } /* Read the alarm value stored in the Backup register */ tmp = BKP_ReadBackupRegister(BKP_DR6); tmp |= BKP_ReadBackupRegister(BKP_DR7) << 16; LCD_ClearLine(Line8); /* Display alarm separators ":" on Line2 */ LCD_DisplayChar(Line8, 212, ':'); LCD_DisplayChar(Line8, 166, ':'); /* Display actual alarm value */ Alarm_Display(tmp); /* Wait a press on pushbuttons */ while(ReadKey() != NOKEY) { } /* Wait a press on pushbuttons */ while(ReadKey() == NOKEY) { } /* Clear the LCD */ LCD_Clear(White); /* Display the menu */ DisplayMenu(); /* Enable the JoyStick interrupts */ IntExtOnOffConfig(ENABLE); }
/******************************************************************************* * Function Name : Mass_Storage_Start * Description : Starts the mass storage demo. * Input : None * Output : None * Return : None *******************************************************************************/ void Mass_Storage_Start (void) { NVIC_InitTypeDef NVIC_InitStructure; /* Disble the JoyStick interrupts */ IntExtOnOffConfig(DISABLE); while(ReadKey() != NOKEY) { } RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE); /* Clear the LCD screen */ LCD_Clear(White); LCD_SetDisplayWindow(160, 223, 128, 128); LCD_NORDisplay(USB_ICON); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE); /* Disable LCD Window mode */ LCD_WindowModeDisable(); /* Set the Back Color */ LCD_SetBackColor(Blue); /* Set the Text Color */ LCD_SetTextColor(White); /* Display the " Plug the USB " message */ LCD_DisplayStringLine(Line8, " Plug the USB Cable "); LCD_DisplayStringLine(Line9, "Exit: Push JoyStick"); /* Enable and GPIOD clock */ USB_Disconnect_Config(); /* MAL configuration */ MAL_Config(); Set_USBClock(); NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = USB_HP_CAN1_TX_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = SDIO_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); USB_Init(); while (bDeviceState != CONFIGURED) { if(ReadKey() != NOKEY) { PowerOff(); LCD_Clear(White); DisplayMenu(); IntExtOnOffConfig(ENABLE); return; } } LCD_ClearLine(Line9); /* Display the "To stop Press SEL" message */ LCD_DisplayStringLine(Line8, " To stop Press SEL "); /* Loop until SEL key pressed */ while(ReadKey() != SEL) { } PowerOff(); LCD_Clear(White); DisplayMenu(); IntExtOnOffConfig(ENABLE); }
/******************************************************************************* * Function Name : NMI_Handler * Description : This function handles NMI exception. * Input : None * Output : None * Return : None *******************************************************************************/ void NMI_Handler(void) { uint32_t tmp = 318, index = 0; /* Disable LCD Window mode */ LCD_WindowModeDisable(); /* If HSE is not detected at program startup or HSE clock failed during program execution */ if((Get_HSEStartUpStatus() == ERROR) || (RCC_GetITStatus(RCC_IT_CSS) != RESET)) { /* Clear the LCD */ LCD_Clear(White); /* Set the LCD Back Color */ LCD_SetBackColor(Blue); /* Set the LCD Text Color */ LCD_SetTextColor(White); /* Display " No Clock Detected " message */ LCD_DisplayStringLine(Line0, "No HSE Clock "); LCD_DisplayStringLine(Line1, "Detected. STANDBY "); LCD_DisplayStringLine(Line2, "mode in few seconds. "); LCD_DisplayStringLine(Line5, "If HSE Clock "); LCD_DisplayStringLine(Line6, "recovers before the "); LCD_DisplayStringLine(Line7, "time out, a System "); LCD_DisplayStringLine(Line8, "Reset is generated. "); LCD_ClearLine(Line9); /* Clear Clock Security System interrupt pending bit */ RCC_ClearITPendingBit(RCC_IT_CSS); GPIO_SetBits(GPIOC, GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9); /* Enable HSE */ RCC_HSEConfig(RCC_HSE_ON); LCD_ClearLine(Line4); /* Set the Back Color */ LCD_SetBackColor(White); /* Set the Text Color */ LCD_SetTextColor(Red); LCD_DrawRect(71, 319, 25, 320); LCD_SetBackColor(Green); LCD_SetTextColor(White); /* Wait till HSE is ready */ while(RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET) { if(index == 0x3FFFF) { LCD_DisplayChar(Line3, tmp, 0x20); tmp -= 16; index = 0; } index++; /* Enters the system in STANDBY mode */ if(tmp < 16) { LCD_SetBackColor(Blue); LCD_ClearLine(Line3); LCD_ClearLine(Line4); LCD_ClearLine(Line5); LCD_ClearLine(Line6); LCD_DisplayStringLine(Line7, " MCU in STANDBY Mode"); LCD_DisplayStringLine(Line8, "To exit press Wakeup"); /* Request to enter STANDBY mode */ PWR_EnterSTANDBYMode(); } } /* Generate a system reset */ NVIC_SystemReset(); } }
/******************************************************************************* * Function Name : Thermometer_Temperature * Description : Displays the temperature in Celsius and fahrenheit degree. * Input : None * Output : None * Return : None *******************************************************************************/ void Thermometer_Temperature(void) { uint32_t i = 0; while(ReadKey() != NOKEY) { } if(I2C_LM75_Status() == SUCCESS) { /* Disable the JoyStick Interrupts */ IntExtOnOffConfig(DISABLE); /* Clear the LCD */ LCD_Clear(White); /* Set the Icon display window */ LCD_SetDisplayWindow(150, 210, 64, 84); /* Display the Thermometer icon */ LCD_DrawBMP(0x0062A300); /* Disable LCD Window mode */ LCD_WindowModeDisable(); /* Set the Back Color */ LCD_SetBackColor(Red); /* Set the Text Color */ LCD_SetTextColor(White); LCD_DisplayStringLine(Line2, " Temperature "); /* Set the Back Color */ LCD_SetBackColor(Blue); /* Set the Text Color */ LCD_SetTextColor(Green); /* Wait until no key is pressed */ while(ReadKey() != NOKEY) { } /* Wait until a key is beiing pressed */ while(ReadKey() == NOKEY) { /* Get double of Temperature value */ TempCelsius_Value = I2C_LM75_Temp_Read(); if(TempCelsius_Value <= 1023) { /* Positive temperature measured */ TempCelsius_Display[5] = '+'; TempFahrenheit_Display[5] = '+'; } else { /* Negative temperature measured */ TempCelsius_Display[5] = '-'; TempFahrenheit_Display[5] = '-'; /* Remove temperature value sign */ TempCelsius_Value = 0x800 - TempCelsius_Value; } /* Calculate temperature digits in °C */ Temp_Decimal = ((TempCelsius_Value & 7) * 1000 / 8); TempCelsius_Display[10] = (Temp_Decimal / 100) + 0x30; TempCelsius_Display[11] = ((Temp_Decimal % 100) / 10) + 0x30; TempCelsius_Display[12] = ((Temp_Decimal % 100) % 10) + 0x30; TempCelsius_Value >>= 3; TempCelsius_Display[6] = (TempCelsius_Value / 100) + 0x30; TempCelsius_Display[7] = ((TempCelsius_Value % 100) / 10) + 0x30; TempCelsius_Display[8] = ((TempCelsius_Value % 100) % 10) + 0x30; /* Convert temperature °C to Fahrenheit */ Temp_Value_Fahrenheit = ((9 * ((TempCelsius_Value * 1000) + Temp_Decimal)) / 5) + 32000; /* Calculate temperature digits in °F */ TempFahrenheit_Display[6] = (Temp_Value_Fahrenheit / 100000) + 0x30; TempFahrenheit_Display[7] = ((Temp_Value_Fahrenheit % 100000) /10000) + 0x30; TempFahrenheit_Display[8] = ((Temp_Value_Fahrenheit % 100000) %10000/1000) + 0x30; TempFahrenheit_Display[10] = ((((Temp_Value_Fahrenheit % 100000) %10000) %1000) /100) + 0x30; TempFahrenheit_Display[11] = (((((Temp_Value_Fahrenheit % 100000) %10000) %1000) %100) /10) + 0x30; TempFahrenheit_Display[12] = (((((Temp_Value_Fahrenheit % 100000) %10000) %1000) %100) %10) + 0x30; /* Display Fahrenheit value on LCD */ for(i = 0; i < 20; i++) { LCD_DisplayChar(Line7, (319 - (16 * i)), TempCelsius_Display[i]); LCD_DisplayChar(Line8, (319 - (16 * i)), TempFahrenheit_Display[i]); } } }