Last active
November 4, 2019 08:48
-
-
Save ozturkib/8a7661d3b049f02abf4994bb1f8c591e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Created on 25 Oct 2019 | |
@author: Ibrahim Ozturk | |
@link : http://oku.ozturkibrahim.com/ | |
STM32F4DISCOVERY kitindeki 4 pine bagli 4 ledin sabit ve değişken aralikli yakılıp söndürülmesi. | |
Ödev içeriğine dair daha detaylı bilgi için aşağıdaki linki tıklayınız: | |
http://oku.ozturkibrahim.com/docs/Microprocessors_HW02_GPIO_LED.pdf | |
Ders esnasında elde ettigimiz optimize gerçekleme. | |
''' | |
#include "stdint.h" | |
#include "main.h" | |
static void LED_GPIO_Init(void); | |
static void LED_Yak_Sondur_Degisken_Aralikli(void); | |
static void LED_Yak_Sondur_Sabit_Aralikli(uint16_t sure); | |
#define BEKLEME_SURESI_SABIT 300 //BEKLEME_SURESI=300 -> Beleme suresi 300 milisaniyedir. | |
#define BEKLEME_SURESI_ARTIS 50 | |
#define BEKLEME_SURESI_MIN 50 | |
#define BEKLEME_SURESI_MAX 500 | |
int main(void) | |
{ | |
HAL_Init(); | |
SystemClock_Config(); | |
LED_GPIO_Init(); | |
while (1) | |
{ | |
//LED_Yak_Sondur_Sabit_Aralikli(BEKLEME_SURESI_SABIT); | |
LED_Yak_Sondur_Degisken_Aralikli(); | |
} | |
} | |
static void LED_Yak_Sondur_Degisken_Aralikli(void){ | |
/* | |
4 ledin ayni anda yakilip ayni anda sondurulmesi | |
Ve her bir yanis-sonus arasinda asagidaki araliklarda zaman gecer (sirasina gore): | |
50ms, 100ms, 150ms, 200ms, ...., 500ms, 50ms, ... | |
*/ | |
uint16_t sure; | |
for(sure = BEKLEME_SURESI_MIN; sure <= BEKLEME_SURESI_MAX; sure += BEKLEME_SURESI_ARTIS) | |
LED_Yak_Sondur_Sabit_Aralikli(sure); | |
} | |
static void LED_Yak_Sondur_Sabit_Aralikli(uint16_t sure){ | |
/* | |
4 ledin ayni anda yakilip ayni anda sondurulmesi | |
Ve her bir yanis-sonus arasinda BEKLEME_SURESI kadar zaman gecirilir. | |
*/ | |
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15, GPIO_PIN_SET); | |
HAL_Delay(sure); | |
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15, GPIO_PIN_RESET); | |
HAL_Delay(sure); | |
} | |
/** | |
* @brief GPIO Initialization Function | |
* @param None | |
* @retval None | |
*/ | |
static void LED_GPIO_Init(void) | |
{ | |
GPIO_InitTypeDef GPIO_InitStruct = {0}; | |
/* GPIO Ports Clock Enable */ | |
__HAL_RCC_GPIOD_CLK_ENABLE(); | |
/*Configure GPIO pin Output Level */ | |
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15, GPIO_PIN_RESET); | |
/*GPIO PD12, PD13, PD14 ve PD15 pinlerine bagli LED'lerin konfigure edilmesi/oncul tanimlamasi*/ | |
GPIO_InitStruct.Pin = GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15; | |
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; | |
GPIO_InitStruct.Pull = GPIO_NOPULL; | |
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; | |
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment