/******************************************************************************* * 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 : EnterSTANDBYMode_RTCAlarm * Description : Enters MCU in STANDBY mode. The wake-up from STANDBY mode is * performed by an RTC Alarm event. * Input : None * Output : None * Return : None *******************************************************************************/ void EnterSTANDBYMode_RTCAlarm(void) { uint32_t tmp = 0; LCD_Clear(White); /* Set the LCD Back Color */ LCD_SetBackColor(Blue); /* Set the LCD Text Color */ LCD_SetTextColor(White); /* Disable the JoyStick interrupts */ IntExtOnOffConfig(DISABLE); if(BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5) { LCD_DisplayStringLine(Line1, "Time and Date are "); LCD_DisplayStringLine(Line2, "not configured, "); LCD_DisplayStringLine(Line3, "please go to the "); LCD_DisplayStringLine(Line4, "calendar menu and "); LCD_DisplayStringLine(Line5, "set the time and "); LCD_DisplayStringLine(Line6, "date parameters. "); LCD_DisplayStringLine(Line7, "Press JoyStick to "); LCD_DisplayStringLine(Line8, "continue... "); while(ReadKey() == NOKEY) { } /* Clear the LCD */ LCD_Clear(White); /* Display the previous menu */ DisplayMenu(); /* Enable the JoyStick interrupts */ IntExtOnOffConfig(ENABLE); return; } tmp = RTC_GetCounter(); /* Save the Alarm value in the Backup register */ BKP_WriteBackupRegister(BKP_DR6, (tmp & 0x0000FFFF)); BKP_WriteBackupRegister(BKP_DR7, (tmp >> 16)); Alarm_PreAdjust(); LCD_DisplayStringLine(Line7, " MCU in STANDBY Mode"); LCD_DisplayStringLine(Line8, " Wait For RTC Alarm "); /* Request to enter STANDBY mode (Wake Up flag is cleared in PWR_EnterSTANDBYMode function) */ PWR_EnterSTANDBYMode(); }
/******************************************************************************* * Function Name : Date_Adjust * Description : Adjusts the current date (MM/DD/YYYY). * Input : None * Output : None * Return : None *******************************************************************************/ void Date_Adjust(void) { IntExtOnOffConfig(DISABLE); while(ReadKey() != NOKEY) { } /* Preadjust the date */ Date_PreAdjust(); /* Clear the LCD */ LCD_Clear(White); /* Display the menu */ DisplayMenu(); /* Enable the JoyStick interrupts */ IntExtOnOffConfig(ENABLE); }
/******************************************************************************* * Function Name : Mass_Storage_Recovery * Description : Erases the NAND Flash Content. * Input : None * Output : None * Return : None *******************************************************************************/ void Mass_Storage_Recovery (void) { /* Disble the JoyStick interrupts */ IntExtOnOffConfig(DISABLE); while(ReadKey() != NOKEY) { } LCD_Clear(White); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE); /* Set the Back Color */ LCD_SetBackColor(Blue); /* Set the Text Color */ LCD_SetTextColor(White); LCD_DisplayStringLine(Line4, " Erase NAND Content "); LCD_DisplayStringLine(Line5, "Please wait... "); /* FSMC Initialization */ FSMC_NAND_Init(); NAND_Format(); /* Display the "To stop Press SEL" message */ LCD_DisplayStringLine(Line4, " NAND Erased "); LCD_DisplayStringLine(Line5, " To exit Press SEL "); /* Loop until SEL key pressed */ while(ReadKey() != SEL) { } LCD_Clear(White); DisplayMenu(); IntExtOnOffConfig(ENABLE); }
/******************************************************************************* * Function Name : main * Description : Main program. * Input : None * Output : None * Return : None *******************************************************************************/ int main(void) { /* Initialize the Demo */ Demo_Init(); while (1) { /* If SEL pushbutton is pressed */ if(SELStatus == 1) { /* External Interrupt Disable */ IntExtOnOffConfig(DISABLE); /* Execute Sel Function */ SelFunc(); /* External Interrupt Enable */ IntExtOnOffConfig(ENABLE); /* Reset SELStatus value */ SELStatus = 0; } } }
/******************************************************************************* * Function Name : Joystick_Init * Description : Joystick_Init. * Input : None * Output : None * Return : None *******************************************************************************/ void Joystick_Init (void) { /*Init Buttons*/ STM_EVAL_PBInit(BUTTON_WAKEUP, BUTTON_MODE_GPIO); STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_GPIO); STM_EVAL_PBInit(BUTTON_RIGHT, BUTTON_MODE_GPIO); STM_EVAL_PBInit(BUTTON_LEFT, BUTTON_MODE_GPIO); STM_EVAL_PBInit(BUTTON_UP, BUTTON_MODE_EXTI); STM_EVAL_PBInit(BUTTON_DOWN, BUTTON_MODE_EXTI); STM_EVAL_PBInit(BUTTON_SEL, BUTTON_MODE_EXTI); IntExtOnOffConfig(ENABLE); }
/******************************************************************************* * Function Name : WavePlayer_StartSpeaker * Description : Starts the wave player application. * Input : None * Output : None * Return : None *******************************************************************************/ void WavePlayer_StartSpeaker(void) { uint8_t MyKey = 0; uint32_t err = 0, Counter = 0x0; LCD_Clear(White); /* Disable the JoyStick interrupts */ IntExtOnOffConfig(DISABLE); while(ReadKey() != NOKEY) { } /* Display the welcome screen and the commands */ LCD_Update(ALL); /* Choose number of repetitions: 0 => infinite repetitions */ I2S_CODEC_ReplayConfig(0); I2S_CODEC_Init(OutputDevice_SPEAKER, AUDIO_FILE_ADDRESS); /* Endless loop */ while(1) { /* Check which key is pressed */ MyKey = ReadKey(); if(Counter == 0) { /* Mask All Interrupts */ __disable_irq(); /* Update the displayed progression information */ LCD_Update(PROGRESS); Counter = 0x5FFFF; /* Disable mask of all interrupts */ __enable_irq(); } Counter--; /* If "UP" pushbutton is pressed */ if(MyKey == UP) { /* Mask All Interrupts */ __disable_irq(); /* Check if the Codec is PLAYING audio file */ if (GetVar_AudioPlayStatus() == AudioPlayStatus_PLAYING) { I2S_CODEC_ControlVolume(VolumeDirection_HIGH, VOLStep); /* Update the display information */ LCD_Update(VOL); } /* UP bottomn pushed in PAUSE mode => Enable the Speaker device output ---*/ else { /* Update the display information */ LCD_Update(PLAY); /* Configure the Speaker as output and reinitialize all devices */ err = I2S_CODEC_SpeakerHeadphoneSwap(OutputDevice_SPEAKER, AUDIO_FILE_ADDRESS); /* Error message display if failure */ if (err != 0) { LCD_DisplayError(err); /* Enable the FSMC that share a pin w/ I2C1 (LBAR) */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE); /* Clear the LCD */ LCD_Clear(White); /* Display the previous menu */ DisplayMenu(); /* Disable mask of all interrupts */ __enable_irq(); /* Enable the JoyStick interrupts */ IntExtOnOffConfig(ENABLE); return; } } /* Disable mask of all interrupts */ __enable_irq(); } /* If "DOWN" pushbutton is pressed */ if(MyKey == DOWN) { /* Mask All Interrupts */ __disable_irq(); /* If the Codec is PLAYING => Decrease Volume*/ if (GetVar_AudioPlayStatus() == AudioPlayStatus_PLAYING) { /* Increase the audio codec digital volume */ I2S_CODEC_ControlVolume(VolumeDirection_LOW, VOLStep); /* Update the LCD display */ LCD_Update(VOL); } else /* If the Codec is PAUSED => Headphone Enable */ { /* Update the LCD display */ LCD_Update(PLAY); /* Enable the Headphone output and reinitialize all devices */ err = I2S_CODEC_SpeakerHeadphoneSwap(OutputDevice_HEADPHONE, AUDIO_FILE_ADDRESS); /* Error message display if failure */ if (err != 0) { LCD_DisplayError(err); /* Enable the FSMC that share a pin w/ I2C1 (LBAR) */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE); /* Clear the LCD */ LCD_Clear(White); /* Display the previous menu */ DisplayMenu(); /* Disable mask of all interrupts */ __enable_irq(); /* Enable the JoyStick interrupts */ IntExtOnOffConfig(ENABLE); return; } } /* Disable mask of all interrupts */ __enable_irq(); } /* If "RIGHT" pushbutton is pressed */ if(MyKey == RIGHT) { /* Mask All Interrupts */ __disable_irq(); /* Check if the Codec is PLAYING audio file */ if (GetVar_AudioPlayStatus() == AudioPlayStatus_PLAYING) { I2S_CODEC_ForwardPlay(STEP_FORWARD); /* Update the display information */ LCD_Update(FRWD); } /* Disable mask of all interrupts */ __enable_irq(); } /* If "LEFT" pushbutton is pressed */ if(MyKey == LEFT) { /* Mask All Interrupts */ __disable_irq(); /* Check if the Codec is PLAYING audio file */ if (GetVar_AudioPlayStatus() == AudioPlayStatus_PLAYING) { I2S_CODEC_RewindPlay(STEP_BACK); /* Update the display information */ LCD_Update(FRWD); } /* Disable mask of all interrupts */ __enable_irq(); } /* If "SEL" pushbutton is pressed */ if(MyKey == SEL) { /* Mask All Interrupts */ __disable_irq(); /* Update the display information */ LCD_Update(STOP); /* Command the Stop of the current audio stream */ SetVar_AudioPlayStatus(AudioPlayStatus_STOPPED); /* Disable mask of all interrupts */ __enable_irq(); I2S_CODEC_Stop(); SPI_I2S_ITConfig(SPI2, SPI_I2S_IT_TXE, DISABLE); /* Enable the FSMC that share a pin w/ I2C1 (LBAR) */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE); /* Clear the LCD */ LCD_Clear(White); /* Display the previous menu */ DisplayMenu(); /* Enable the JoyStick interrupts */ IntExtOnOffConfig(ENABLE); return; } /* If "KEY" pushbutton is pressed */ if(MyKey == KEY) { /* Mask All Interrupts */ __disable_irq(); /* If the Codec is Playing => PAUSE */ if (GetVar_AudioPlayStatus() == AudioPlayStatus_PLAYING) { /* Update the display information */ LCD_Update(PAUSE); /* Command the Pause of the current stream */ SetVar_AudioPlayStatus(AudioPlayStatus_PAUSED); } /* If the Codec is PAUSED => Resume PLAYING */ else if (GetVar_AudioPlayStatus() == AudioPlayStatus_PAUSED) { /* Update the LCD display */ LCD_Update(PLAY); /* Start playing from the last saved position */ I2S_CODEC_Play(GetVar_AudioDataIndex()); } /* If the Codec is STOPPED => PLAY from the file start address */ else if (GetVar_AudioPlayStatus() == AudioPlayStatus_STOPPED) { /* Update the display information */ LCD_Update(PLAY); /* Initialize all devices w/choosen parameters */ err = I2S_CODEC_Init(GetVar_CurrentOutputDevice(), AUDIO_FILE_ADDRESS); /* Error message display if failure */ if (err != 0) { LCD_DisplayError(err); /* Enable the FSMC that share a pin w/ I2C1 (LBAR) */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE); /* Clear the LCD */ LCD_Clear(White); /* Display the previous menu */ DisplayMenu(); /* Disable mask of all interrupts */ __enable_irq(); /* Enable the JoyStick interrupts */ IntExtOnOffConfig(ENABLE); return; } /* Enable Playing the audio file */ I2S_CODEC_Play(GetVar_DataStartAddr()); } /* Disable mask of all interrupts */ __enable_irq(); } } }
/******************************************************************************* * Function Name : Date_Show * Description : Shows date in a graphic mode on LCD. * Input : None * Output : None * Return : None *******************************************************************************/ void Date_Show(void) { uint32_t tmpValue = 0; uint32_t MyKey = 0, ValueMax = 0; uint32_t firstdaycolumn = 0, lastdaycolumn = 0, lastdayline = 0; uint32_t testvalue = 0, pressedkey = 0; /* Disable the JoyStick interrupts */ IntExtOnOffConfig(DISABLE); LCD_Clear(White); while(ReadKey()!= NOKEY) { } LCD_SetBackColor(Blue); LCD_SetTextColor(White); 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_Clear(White); /* Display the menu */ DisplayMenu(); /* Enable the JoyStick interrupts */ IntExtOnOffConfig(ENABLE); return; } } } /* Clear the LCD */ LCD_Clear(White); LCD_DisplayStringLine(Line9, " To Exit Press SEL "); /* Display the current date */ Date_Display(date_s.year, date_s.month, date_s.day); if(date_s.month == 2) { if(IsLeapYear(date_s.year)) { ValueMax = 29; } else { ValueMax = (MonLen[date_s.month - 1] - 1); } } else { ValueMax = (MonLen[date_s.month - 1] - 1); } firstdaycolumn = 0x13F - (0x30 * dn); lastdaycolumn = ValueMax - (7 - dn); lastdayline = lastdaycolumn / 7; lastdaycolumn %= 7; if(lastdaycolumn == 0) { lastdayline = Line3 + (lastdayline * 24); lastdaycolumn = 31; } else { lastdayline = Line4 + (lastdayline * 24); lastdaycolumn = 0x13F -(0x30 * (lastdaycolumn - 1)); } /* Initialize tmpValue */ tmpValue = date_s.day; /* Endless loop */ while(1) { /* Check which key is pressed */ MyKey = ReadKey(); /* If "RIGHT" pushbutton is pressed */ if(MyKey == RIGHT) { LCD_SetTextColor(White); LCD_DrawRect(dayline, daycolumn, 24, 32); /* Increase the value of the digit */ if(tmpValue == ValueMax) { tmpValue = 0; dayline = Line3; daycolumn = firstdaycolumn + 48; } if(daycolumn == 31) { daycolumn = 367; dayline += 24; } daycolumn -= 48; LCD_SetTextColor(Red); LCD_DrawRect(dayline, daycolumn, 24, 32); tmpValue++; WeekDayNum(date_s.year, date_s.month, tmpValue); LCD_SetBackColor(Blue2); LCD_SetTextColor(White); LCD_DisplayStringLine(Line1, " WEEK DAY N: "); if(wn/10) { LCD_DisplayChar(Line1, 223, ((wn/10)+ 0x30)); LCD_DisplayChar(Line1, 207, ((wn%10)+ 0x30)); } else { LCD_DisplayChar(Line1, 223, ((wn%10)+ 0x30)); } if(dc/100) { LCD_DisplayChar(Line1, 47, ((dc/100)+ 0x30)); LCD_DisplayChar(Line1, 31, (((dc%100)/10)+ 0x30)); LCD_DisplayChar(Line1, 15, (((dc%100)%10)+ 0x30)); } else if(dc/10) { LCD_DisplayChar(Line1, 47, ((dc/10)+ 0x30)); LCD_DisplayChar(Line1, 31, ((dc%10)+ 0x30)); } else { LCD_DisplayChar(Line1, 47, ((dc%10)+ 0x30)); } LCD_SetBackColor(White); } /* If "LEFT" pushbutton is pressed */ if(MyKey == LEFT) { LCD_SetTextColor(White); LCD_DrawRect(dayline, daycolumn, 24, 32); /* Decrease the value of the digit */ if(tmpValue == 1) { tmpValue = ValueMax + 1; dayline = lastdayline; daycolumn = lastdaycolumn - 48; } if(daycolumn == 319) { daycolumn = 0xFFEF; dayline -= 24; } daycolumn += 48; LCD_SetTextColor(Red); LCD_DrawRect(dayline, daycolumn, 24, 32); tmpValue--; WeekDayNum(date_s.year, date_s.month, tmpValue); LCD_SetBackColor(Blue2); LCD_SetTextColor(White); LCD_DisplayStringLine(Line1, " WEEK DAY N: "); if(wn/10) { LCD_DisplayChar(Line1, 223, ((wn/10)+ 0x30)); LCD_DisplayChar(Line1, 207, ((wn%10)+ 0x30)); } else { LCD_DisplayChar(Line1, 223, ((wn%10)+ 0x30)); } if(dc/100) { LCD_DisplayChar(Line1, 47, ((dc/100)+ 0x30)); LCD_DisplayChar(Line1, 31, (((dc%100)/10)+ 0x30)); LCD_DisplayChar(Line1, 15, (((dc%100)%10)+ 0x30)); } else if(dc/10) { LCD_DisplayChar(Line1, 47, ((dc/10)+ 0x30)); LCD_DisplayChar(Line1, 31, ((dc%10)+ 0x30)); } else { LCD_DisplayChar(Line1, 47, ((dc%10)+ 0x30)); } LCD_SetBackColor(White); } /* If "UP" pushbutton is pressed */ if(MyKey == UP) { LCD_SetTextColor(White); LCD_DrawRect(dayline, daycolumn, 24, 32); if(tmpValue == 1) { dayline = lastdayline; daycolumn = lastdaycolumn; tmpValue = ValueMax; } else if(tmpValue < 8) { tmpValue = 1; dayline = Line3; daycolumn = firstdaycolumn; } else { dayline -= 24; tmpValue -= 7; } LCD_SetTextColor(Red); LCD_DrawRect(dayline, daycolumn, 24, 32); WeekDayNum(date_s.year, date_s.month, tmpValue); LCD_SetBackColor(Blue2); LCD_SetTextColor(White); LCD_DisplayStringLine(Line1, " WEEK DAY N: "); if(wn/10) { LCD_DisplayChar(Line1, 223, ((wn/10)+ 0x30)); LCD_DisplayChar(Line1, 207, ((wn%10)+ 0x30)); } else { LCD_DisplayChar(Line1, 223, ((wn%10)+ 0x30)); } if(dc/100) { LCD_DisplayChar(Line1, 47, ((dc/100)+ 0x30)); LCD_DisplayChar(Line1, 31, (((dc%100)/10)+ 0x30)); LCD_DisplayChar(Line1, 15, (((dc%100)%10)+ 0x30)); } else if(dc/10) { LCD_DisplayChar(Line1, 47, ((dc/10)+ 0x30)); LCD_DisplayChar(Line1, 31, ((dc%10)+ 0x30)); } else { LCD_DisplayChar(Line1, 47, ((dc%10)+ 0x30)); } LCD_SetBackColor(White); } /* If "DOWN" pushbutton is pressed */ if(MyKey == DOWN) { LCD_SetTextColor(White); LCD_DrawRect(dayline, daycolumn, 24, 32); if(tmpValue == ValueMax) { dayline = Line3; daycolumn = firstdaycolumn; tmpValue = 1; } else { dayline += 24; tmpValue += 7; } if(tmpValue > ValueMax) { tmpValue = ValueMax; dayline = lastdayline; daycolumn = lastdaycolumn; } LCD_SetTextColor(Red); LCD_DrawRect(dayline, daycolumn, 24, 32); WeekDayNum(date_s.year, date_s.month, tmpValue); LCD_SetBackColor(Blue2); LCD_SetTextColor(White); LCD_DisplayStringLine(Line1, " WEEK DAY N: "); if(wn/10) { LCD_DisplayChar(Line1, 223, ((wn/10)+ 0x30)); LCD_DisplayChar(Line1, 207, ((wn%10)+ 0x30)); } else { LCD_DisplayChar(Line1, 223, ((wn%10)+ 0x30)); } if(dc/100) { LCD_DisplayChar(Line1, 47, ((dc/100)+ 0x30)); LCD_DisplayChar(Line1, 31, (((dc%100)/10)+ 0x30)); LCD_DisplayChar(Line1, 15, (((dc%100)%10)+ 0x30)); } else if(dc/10) { LCD_DisplayChar(Line1, 47, ((dc/10)+ 0x30)); LCD_DisplayChar(Line1, 31, ((dc%10)+ 0x30)); } else { LCD_DisplayChar(Line1, 47, ((dc%10)+ 0x30)); } LCD_SetBackColor(White); } /* If "SEL" pushbutton is pressed */ if(MyKey == SEL) { /* Clear the LCD */ LCD_Clear(White); /* Display the menu */ DisplayMenu(); /* Enable the JoyStick interrupts */ IntExtOnOffConfig(ENABLE); return; } } }
/******************************************************************************* * 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 : 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 : EnterSTOPMode_EXTI * Description : Enters MCU in STOP mode. The wake-up from STOP mode is * performed by an external interrupt. * Input : None * Output : None * Return : None *******************************************************************************/ void EnterSTOPMode_EXTI(void) { NVIC_InitTypeDef NVIC_InitStructure; EXTI_InitTypeDef EXTI_InitStructure; STOPModeStatus = 0; /* Clear the LCD */ LCD_Clear(White); /* Set the LCD Back Color */ LCD_SetBackColor(Blue); /* Set the LCD Text Color */ LCD_SetTextColor(White); /* Disable the JoyStick interrupts */ IntExtOnOffConfig(DISABLE); /* Configure the EXTI Line 9 */ EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Line = EXTI_Line9; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); /* Enable the EXTI9_5 Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); LCD_DisplayStringLine(Line4, " MCU in STOP Mode "); LCD_DisplayStringLine(Line5, "To exit press Key "); LCD_DisplayStringLine(Line6, "push button "); /* Clear the RTC Alarm flag */ RTC_ClearFlag(RTC_FLAG_ALR); /* Save the GPIO pins current configuration then put all GPIO pins in Analog Input mode ...*/ GPIO_SaveConfig(); /* ... and keep PB.09 configuration which will be used as EXTI Line9 source */ GPIOB->CRH = 0x40; /* Request to enter STOP mode with regulator in low power */ PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); /* Restore the GPIO Configurations*/ GPIO_RestoreConfig(); /* At this stage the system has resumed from STOP mode ************************/ EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Line = EXTI_Line9; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd = DISABLE; EXTI_Init(&EXTI_InitStructure); /* Enable the EXTI9_5 Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Configures system clock after wake-up from STOP: enable HSE, PLL and select PLL as system clock source (HSE and PLL are disabled in STOP mode) */ SYSCLKConfig_STOP(); if(STOPModeStatus != RESET) { LCD_DisplayStringLine(Line4, " STOP Mode "); LCD_DisplayStringLine(Line5, "Wake-Up by RTC Alarm"); LCD_DisplayStringLine(Line6, "Press JoyStick to "); LCD_DisplayStringLine(Line7, "continue... "); } else { LCD_DisplayStringLine(Line4, " STOP Mode "); LCD_DisplayStringLine(Line5, "WakeUp by Key Button"); LCD_DisplayStringLine(Line6, "Press JoyStick to "); LCD_DisplayStringLine(Line7, "continue... "); } while(ReadKey() == NOKEY) { } /* Clear the LCD */ LCD_Clear(White); /* Display the previous menu */ DisplayMenu(); /* Enable the JoyStick interrupts */ IntExtOnOffConfig(ENABLE); }
/******************************************************************************* * Function Name : EnterSTOPMode_RTCAlarm * Description : Enters MCU in STOP mode. The wake-up from STOP mode is * performed by an RTC Alarm. * Input : None * Output : None * Return : None *******************************************************************************/ void EnterSTOPMode_RTCAlarm(void) { uint32_t tmp = 0; /* Clear the LCD */ LCD_Clear(White); /* Set the LCD Back Color */ LCD_SetBackColor(Blue); /* Set the LCD Text Color */ LCD_SetTextColor(White); /* Disable the JoyStick interrupts */ IntExtOnOffConfig(DISABLE); if(BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5) { LCD_DisplayStringLine(Line1, "Time and Date are "); LCD_DisplayStringLine(Line2, "not configured, "); LCD_DisplayStringLine(Line3, "please go to the "); LCD_DisplayStringLine(Line4, "calendar menu and "); LCD_DisplayStringLine(Line5, "set the time and "); LCD_DisplayStringLine(Line6, "date parameters. "); LCD_DisplayStringLine(Line7, "Press JoyStick to "); LCD_DisplayStringLine(Line8, "continue... "); while(ReadKey() == NOKEY) { } /* Clear the LCD */ LCD_Clear(White); /* Display the previous menu */ DisplayMenu(); /* Enable the JoyStick interrupts */ IntExtOnOffConfig(ENABLE); return; } tmp = RTC_GetCounter(); /* Save the Alarm value in the Backup register */ BKP_WriteBackupRegister(BKP_DR6, (tmp & 0x0000FFFF)); BKP_WriteBackupRegister(BKP_DR7, (tmp >> 16)); Alarm_PreAdjust(); LCD_ClearLine(Line8); LCD_DisplayStringLine(Line6, " MCU in STOP Mode "); LCD_DisplayStringLine(Line7, " Wait For RTC Alarm "); /* Save the GPIO pins current configuration then put all GPIO pins in Analog Input mode */ GPIO_SaveConfig(); /* Request to enter STOP mode with regulator in low power */ PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); /* Restore the GPIO Configurations*/ GPIO_RestoreConfig(); /* Configures system clock after wake-up from STOP: enable HSE, PLL and select PLL as system clock source (HSE and PLL are disabled in STOP mode) */ SYSCLKConfig_STOP(); LCD_DisplayStringLine(Line4, " STOP Mode "); LCD_DisplayStringLine(Line5, "Wake-Up by RTC Alarm"); LCD_DisplayStringLine(Line6, "Press JoyStick to "); LCD_DisplayStringLine(Line7, "continue... "); while(ReadKey() == NOKEY) { } /* Clear the LCD */ LCD_Clear(White); /* Display the previous menu */ DisplayMenu(); /* Enable the JoyStick interrupts */ IntExtOnOffConfig(ENABLE); }
/******************************************************************************* * 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]); } } }