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

STM8S/A

STM8S_StdPeriph_Examples/TIM2/TIM2_OC_InactiveMode/main.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    TIM2_OC_InactiveMode\main.c
00004   * @author  MCD Application Team
00005   * @version  V2.2.0
00006   * @date     30-September-2014
00007   * @brief   This file contains the main function for TIM2 OC_InactiveMode Example .
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 
00031 /**
00032   * @addtogroup TIM2_OC_InactiveMode
00033   * @{
00034   */
00035 
00036 /* Private typedef -----------------------------------------------------------*/
00037 /* Private define ------------------------------------------------------------*/
00038 #define CCR1_Val ((uint16_t)976)
00039 #define CCR2_Val ((uint16_t)488)
00040 #define CCR3_Val  ((uint16_t)244)
00041 /* Private macro -------------------------------------------------------------*/
00042 /* Private variables ---------------------------------------------------------*/
00043 /* Private function prototypes -----------------------------------------------*/
00044 static void TIM2_Config(void);
00045 static void GPIO_Config(void);
00046 /* Private functions ---------------------------------------------------------*/
00047 /* Public functions ----------------------------------------------------------*/
00048 
00049 /**
00050   * @brief  Main program.
00051   * @param  None
00052   * @retval None
00053   */
00054 void main(void)
00055 {
00056   /* GPIO configuration -----------------------------------------*/
00057   GPIO_Config();  
00058 
00059   /* TIM2 configuration -----------------------------------------*/
00060   TIM2_Config();
00061 
00062         
00063   enableInterrupts();
00064 
00065   while (1)
00066   {}
00067 }
00068 
00069 /**
00070   * @brief  Configure GPIO
00071   * @param  None
00072   * @retval None
00073   */
00074 static void GPIO_Config(void)
00075 {
00076   /* Set pin PG.5 & PG.6 & PG.7 to high state */
00077   GPIO_Init(GPIOG, (GPIO_Pin_TypeDef)(GPIO_PIN_5|GPIO_PIN_6| GPIO_PIN_7), GPIO_MODE_OUT_PP_LOW_FAST);
00078   GPIO_WriteHigh(GPIOG, (GPIO_Pin_TypeDef)(GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7));
00079 }
00080 
00081 /**
00082   * @brief  Configure Output Compare Active Mode for TIM2 Channel1, Channel2 and 
00083   *         channel3  
00084   * @param  None
00085   * @retval None
00086   */
00087 static void TIM2_Config(void)
00088 {
00089   /* Time base configuration */
00090   TIM2_TimeBaseInit(TIM2_PRESCALER_2048, 65535);
00091 
00092   /* Prescaler configuration */
00093   TIM2_PrescalerConfig(TIM2_PRESCALER_2048, TIM2_PSCRELOADMODE_IMMEDIATE);
00094 
00095   /* Output Compare Active Mode configuration: Channel1 */
00096   /*
00097           TIM2_OCMode = TIM2_OCMODE_INACTIVE
00098        TIM2_OCPolarity = TIM2_OCPOLARITY_HIGH
00099        TIM2_Pulse = CCR1_Val
00100         */
00101   TIM2_OC1Init(TIM2_OCMODE_INACTIVE, TIM2_OUTPUTSTATE_ENABLE,CCR1_Val, TIM2_OCPOLARITY_HIGH); 
00102   TIM2_OC1PreloadConfig(DISABLE);
00103 
00104   /* Output Compare Active Mode configuration: Channel2 */
00105   
00106   /*TIM2_Pulse = CCR2_Val;  */
00107   TIM2_OC2Init(TIM2_OCMODE_INACTIVE, TIM2_OUTPUTSTATE_ENABLE,CCR2_Val, TIM2_OCPOLARITY_HIGH); 
00108   TIM2_OC2PreloadConfig(DISABLE);
00109 
00110   /* Output Compare Active Mode configuration: Channel3 */
00111   /*TIM2_Pulse = CCR3_Val  */
00112   TIM2_OC3Init(TIM2_OCMODE_INACTIVE, TIM2_OUTPUTSTATE_ENABLE,CCR3_Val, TIM2_OCPOLARITY_HIGH); 
00113   TIM2_OC3PreloadConfig(DISABLE);
00114 
00115   TIM2_ARRPreloadConfig(ENABLE);
00116   
00117   /* TIM IT enable */
00118   TIM2_ITConfig(TIM2_IT_CC1, ENABLE);
00119   TIM2_ITConfig(TIM2_IT_CC2, ENABLE);
00120   TIM2_ITConfig(TIM2_IT_CC3, ENABLE);
00121   
00122   /* TIM2 enable counter */
00123   TIM2_Cmd(ENABLE);
00124 }
00125 
00126 #ifdef USE_FULL_ASSERT
00127 
00128 /**
00129   * @brief  Reports the name of the source file and the source line number
00130   *   where the assert_param error has occurred.
00131   * @param file: pointer to the source file name
00132   * @param line: assert_param error line source number
00133   * @retval None
00134   */
00135 void assert_failed(uint8_t* file, uint32_t line)
00136 { 
00137   /* User can add his own implementation to report the file name and line number,
00138      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00139 
00140   /* Infinite loop */
00141   while (1)
00142   {
00143   }
00144 }
00145 #endif
00146 
00147 /**
00148   * @}
00149   */
00150 
00151 
00152 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
STM8 Standard Peripherals Library: Footer

 

 

 

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