You are on page 1of 4

/* Includes ------------------------------------------------------------------*/

#include "main.h"

/** @addtogroup Template_Project


* @{
*/

/* Private typedef -----------------------------------------------------------*/


/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
__IO uint32_t TimingDelay;

/* Private function prototypes -----------------------------------------------*/


/* Private functions ---------------------------------------------------------*/

/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
init_Clock();
init ();
/* Infinite loop */
while (1)
{
led_nyala();
Delay(10);
led_mati();
Delay(10);

}
}

void init_Clock(void)
{
/* SysTick end of count event each 10ms */
RCC_ClocksTypeDef RCC_Clocks;
RCC_GetClocksFreq(&RCC_Clocks);
SysTick_Config(RCC_Clocks.HCLK_Frequency / 100);
}
void init (void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* GPIOG Peripheral clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);

/* Configure PG6 and PG8 in output pushpull mode */


GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOD, &GPIO_InitStructure);
}

void led_nyala (void)


{
/* Forward */
GPIOD->BSRRL = GPIO_Pin_8;
GPIOD->BSRRH = GPIO_Pin_6;

void led_mati (void)


{
/* Reset PD14 and PD15 */
GPIOD->BSRRL = GPIO_Pin_6;
GPIOD->BSRRH = GPIO_Pin_8;
}

/**
* @brief Inserts a delay time.
* @param nTime: specifies the delay time length, in 10 ms.
* @retval None
*/
void Delay(int nTime)
{
TimingDelay = nTime;

while(TimingDelay != 0);
}

/**
* @brief Decrements the TimingDelay variable.
* @param None
* @retval None

*/
void TimingDelay_Decrement(void)
{
if (TimingDelay != 0x00)
{
TimingDelay--;
}

/************************ (C) COPYRIGHT STMicroelectronics *****END OF


FILE****/
MAIN C

/* Define to prevent recursive inclusion -------------------------------------*/


#ifndef __MAIN_H
#define __MAIN_H

/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx.h"

/* Exported types ------------------------------------------------------------*/


/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void init_Clock(void);
void init (void);
void led_nyala (void);
void led_mati (void);
void Delay(int nTime);
void TimingDelay_Decrement(void);
#endif /* __MAIN_H */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF


FILE****/
Main H

You might also like