PageRenderTime 26ms CodeModel.GetById 37ms RepoModel.GetById 1ms app.codeStats 0ms

/libraries/STM32F10x_StdPeriph_Lib_V3.1.2/Project/STM32F10x_StdPeriph_Examples/GPIO/IOToggle/main.c

https://github.com/jwithee/bearboard
C | 165 lines | 62 code | 23 blank | 80 comment | 4 complexity | adcbe6b65d19fc1288131e0423331f69 MD5 | raw file
  1. /**
  2. ******************************************************************************
  3. * @file GPIO/IOToggle/main.c
  4. * @author MCD Application Team
  5. * @version V3.1.2
  6. * @date 09/28/2009
  7. * @brief Main program body.
  8. ******************************************************************************
  9. * @copy
  10. *
  11. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  12. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  13. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  14. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  15. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  16. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  17. *
  18. * <h2><center>&copy; COPYRIGHT 2009 STMicroelectronics</center></h2>
  19. */
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "stm32f10x.h"
  22. #include "stm32_eval.h"
  23. /** @addtogroup STM32F10x_StdPeriph_Examples
  24. * @{
  25. */
  26. /** @addtogroup GPIO_IOToggle
  27. * @{
  28. */
  29. /* Private typedef -----------------------------------------------------------*/
  30. /* Private define ------------------------------------------------------------*/
  31. /* Private macro -------------------------------------------------------------*/
  32. /* Private variables ---------------------------------------------------------*/
  33. GPIO_InitTypeDef GPIO_InitStructure;
  34. /* Private function prototypes -----------------------------------------------*/
  35. void RCC_Configuration(void);
  36. void Delay(__IO uint32_t nCount);
  37. /* Private functions ---------------------------------------------------------*/
  38. /**
  39. * @brief Main program.
  40. * @param None
  41. * @retval None
  42. */
  43. int main(void)
  44. {
  45. /* System Clocks Configuration **********************************************/
  46. RCC_Configuration();
  47. /* Configure all unused GPIO port pins in Analog Input mode (floating input
  48. trigger OFF), this will reduce the power consumption and increase the device
  49. immunity against EMI/EMC *************************************************/
  50. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
  51. RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD |
  52. RCC_APB2Periph_GPIOE, ENABLE);
  53. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
  54. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
  55. GPIO_Init(GPIOA, &GPIO_InitStructure);
  56. GPIO_Init(GPIOB, &GPIO_InitStructure);
  57. GPIO_Init(GPIOC, &GPIO_InitStructure);
  58. GPIO_Init(GPIOD, &GPIO_InitStructure);
  59. GPIO_Init(GPIOE, &GPIO_InitStructure);
  60. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
  61. RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD |
  62. RCC_APB2Periph_GPIOE, DISABLE);
  63. #ifdef USE_STM3210E_EVAL
  64. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF | RCC_APB2Periph_GPIOG, ENABLE);
  65. GPIO_Init(GPIOF, &GPIO_InitStructure);
  66. GPIO_Init(GPIOG, &GPIO_InitStructure);
  67. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF | RCC_APB2Periph_GPIOG, DISABLE);
  68. #endif /* USE_STM3210E_EVAL */
  69. /* Initialize Leds mounted on STM3210X-EVAL board */
  70. STM_EVAL_LEDInit(LED1);
  71. STM_EVAL_LEDInit(LED2);
  72. STM_EVAL_LEDInit(LED3);
  73. STM_EVAL_LEDInit(LED4);
  74. while (1)
  75. {
  76. /* Turn on LD1 */
  77. STM_EVAL_LEDOn(LED1);
  78. /* Insert delay */
  79. Delay(0xAFFFF);
  80. /* Turn on LD2 and LD3 */
  81. STM_EVAL_LEDOn(LED2);
  82. STM_EVAL_LEDOn(LED3);
  83. /* Turn off LD1 */
  84. STM_EVAL_LEDOff(LED1);
  85. /* Insert delay */
  86. Delay(0xAFFFF);
  87. /* Turn on LD4 */
  88. STM_EVAL_LEDOn(LED4);
  89. /* Turn off LD2 and LD3 */
  90. STM_EVAL_LEDOff(LED2);
  91. STM_EVAL_LEDOff(LED3);
  92. /* Insert delay */
  93. Delay(0xAFFFF);
  94. /* Turn off LD4 */
  95. STM_EVAL_LEDOff(LED4);
  96. }
  97. }
  98. /**
  99. * @brief Configures the different system clocks.
  100. * @param None
  101. * @retval None
  102. */
  103. void RCC_Configuration(void)
  104. {
  105. /* Setup the microcontroller system. Initialize the Embedded Flash Interface,
  106. initialize the PLL and update the SystemFrequency variable. */
  107. SystemInit();
  108. }
  109. /**
  110. * @brief Inserts a delay time.
  111. * @param nCount: specifies the delay time length.
  112. * @retval None
  113. */
  114. void Delay(__IO uint32_t nCount)
  115. {
  116. for(; nCount != 0; nCount--);
  117. }
  118. #ifdef USE_FULL_ASSERT
  119. /**
  120. * @brief Reports the name of the source file and the source line number
  121. * where the assert_param error has occurred.
  122. * @param file: pointer to the source file name
  123. * @param line: assert_param error line source number
  124. * @retval None
  125. */
  126. void assert_failed(uint8_t* file, uint32_t line)
  127. {
  128. /* User can add his own implementation to report the file name and line number,
  129. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  130. /* Infinite loop */
  131. while (1)
  132. {
  133. }
  134. }
  135. #endif
  136. /**
  137. * @}
  138. */
  139. /**
  140. * @}
  141. */
  142. /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/