STM8S/A Standard Peripherals Firmware Library: main.c Source File

STM8S/A

STM8S_StdPeriph_Examples/CLK/CLK_ClockSelection/main.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    CLK_ClockSelection\main.c
00004   * @brief   This file contains the main function for the CLK Clock Selection example.
00005   * @author  MCD Application Team
00006   * @version  V2.2.0
00007   * @date     30-September-2014
00008   ******************************************************************************
00009   * @attention
00010   *
00011   * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
00012   *
00013   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
00014   * You may not use this file except in compliance with the License.
00015   * You may obtain a copy of the License at:
00016   *
00017   *        http://www.st.com/software_license_agreement_liberty_v2
00018   *
00019   * Unless required by applicable law or agreed to in writing, software 
00020   * distributed under the License is distributed on an "AS IS" BASIS, 
00021   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00022   * See the License for the specific language governing permissions and
00023   * limitations under the License.
00024   *
00025   ******************************************************************************
00026   */ 
00027 
00028 /* Includes ------------------------------------------------------------------*/
00029 #include "stm8s.h"
00030 #include "stm8s_eval.h"
00031 #include "stm8s_eval_lcd.h"
00032 
00033 /**
00034   * @addtogroup CLK_ClockSelection
00035   * @{
00036   */
00037 
00038 /* Private typedef -----------------------------------------------------------*/
00039 /* Private define ------------------------------------------------------------*/
00040 /* Private macro -------------------------------------------------------------*/
00041 /* Private variables ---------------------------------------------------------*/
00042 __IO uint8_t OscillatorStatus = 0x00;
00043 /* Private function prototypes -----------------------------------------------*/
00044 static void CLK_Config(void);
00045 static void GPIO_Config(void);
00046 static void LCD_Config(void);
00047 /* Public functions ----------------------------------------------------------*/
00048 
00049 /**
00050   * @brief Example  main entry point.
00051   * @param  None
00052   * @retval None
00053   */
00054 void main(void)
00055 {
00056   uint8_t state = 0x00;
00057   
00058   /* GPIO Configuration  -----------------------------------------------------*/
00059   GPIO_Config();  
00060   
00061   /* Configure LCD mounted on STM8-128 EVAL board ----------------------------*/
00062   LCD_Config();
00063   
00064   /* Clock configuration -----------------------------------------------------*/
00065   CLK_Config();
00066   
00067   enableInterrupts();
00068   
00069   while (1)
00070   {
00071     while(state == OscillatorStatus)
00072     {}
00073     state = OscillatorStatus; /* Update the selected master clock oscillator */
00074     
00075     /* joystick right */
00076     if(OscillatorStatus == 0x00)
00077     {
00078       CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSI, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);
00079       
00080       /* Print on LCD line2*/
00081       LCD_SetCursorPos(LCD_LINE2, 0);
00082       LCD_Print("   CLK = HSI    ");
00083     }
00084     
00085     /* joystick up */
00086     if(OscillatorStatus == 0x01)
00087     {
00088       CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSE, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);
00089       
00090       /* Print on LCD line2*/
00091       LCD_SetCursorPos(LCD_LINE2, 0);
00092       LCD_Print("   CLK = HSE    ");
00093     }
00094     
00095     /* joystick down */
00096     if(OscillatorStatus == 0x02)
00097     {
00098       CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_LSI, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);
00099       
00100       /* Print on LCD line2*/
00101       LCD_SetCursorPos(LCD_LINE2, 0);
00102       LCD_Print("   CLK = LSI    ");
00103     }
00104   }
00105 }
00106 
00107 /**
00108   * @brief  Configure GPIO for buttons available on the evaluation board
00109   * @param  None
00110   * @retval None
00111   */
00112 static void GPIO_Config(void)
00113 {
00114   /* Configure GPIO used to drive the joystick
00115   JOYSTICK_UP    --> PB6
00116   JOYSTICK_DOWN  --> PB7
00117   JOYSTICK_RIGHT --> PB5
00118   */
00119   STM_EVAL_PBInit(BUTTON_UP, BUTTON_MODE_EXTI);
00120   STM_EVAL_PBInit(BUTTON_DOWN, BUTTON_MODE_EXTI);
00121   STM_EVAL_PBInit(BUTTON_RIGHT, BUTTON_MODE_EXTI);
00122 }
00123 
00124 /**
00125   * @brief  Configure system clock to run at 16Mhz and output the system clock on
00126   *         CCO pin
00127   * @param  None
00128   * @retval None
00129   */
00130 static void CLK_Config(void)
00131 {
00132   CLK_DeInit();
00133   
00134   /* Clock divider to HSI/1 */
00135   CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
00136   
00137   /* Output Fcpu on CLK_CCO pin */
00138   CLK_CCOConfig(CLK_OUTPUT_MASTER);
00139 }
00140 
00141 /**
00142   * @brief  Configure the LCD available on the evaluation board
00143   * @param  None
00144   * @retval None
00145   */
00146 static void LCD_Config(void)
00147 {
00148   /* Init the Eval board LCD */
00149   STM8S_EVAL_LCD_Init();
00150   
00151   /* Clear LCD */
00152   LCD_Clear();
00153   
00154   /* Print on LCD line1*/
00155   LCD_SetCursorPos(LCD_LINE1, 0);
00156   LCD_Print("Clock Selection");
00157   /* Print on LCD line2*/
00158   LCD_SetCursorPos(LCD_LINE2, 0);
00159   LCD_Print("  Use joystick  ");
00160 }
00161 
00162 #ifdef USE_FULL_ASSERT
00163 
00164 /**
00165   * @brief  Reports the name of the source file and the source line number
00166   *   where the assert_param error has occurred.
00167   * @param file: pointer to the source file name
00168   * @param line: assert_param error line source number
00169   * @retval None
00170   */
00171 void assert_failed(uint8_t* file, uint32_t line)
00172 { 
00173   /* User can add his own implementation to report the file name and line number,
00174      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00175 
00176   /* Infinite loop */
00177   while (1)
00178   {
00179   }
00180 }
00181 #endif
00182 
00183 /**
00184   * @}
00185   */
00186 
00187 
00188 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
STM8 Standard Peripherals Library: Footer

 

 

 

      For complete documentation on STM8 8-bit Microcontrollers platform visit www.st.com