isoment01
Üye
- Katılım
- 26 Haz 2016
- Mesajlar
- 197
- Puanları
- 1
- Yaş
- 32
Kod:
#include "stm8s.h"
#define LED_GPIO_PORT (GPIOC)
#define LED_GPIO_PINS (GPIO_PIN_7 | GPIO_PIN_6 | GPIO_PIN_5 | GPIO_PIN_4 | GPIO_PIN_3)
#define BUTTON_PORT (GPIOD)
#define BUTTON_PIN_UP (GPIO_PIN_4)
#define BUTTON_PIN_DOWN (GPIO_PIN_5)
//#define PRESSED 0
#define BUTTON_DEBOUNCE_TIME 16000
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
void Delay (uint16_t nCount);
/* Private functions ---------------------------------------------------------*/
/* Public functions ----------------------------------------------------------*/
/**
* @brief Main program.
* @param None
* @retval None
*/
void main(void)
{
/* Initialize I/Os in Output Mode */
GPIO_Init(LED_GPIO_PORT, (GPIO_Pin_TypeDef)LED_GPIO_PINS, GPIO_MODE_OUT_OD_LOW_FAST);
GPIO_Init(BUTTON_PORT, (GPIO_Pin_TypeDef)BUTTON_PIN_UP,GPIO_MODE_IN_PU_NO_IT);
GPIO_Init(BUTTON_PORT, (GPIO_Pin_TypeDef)BUTTON_PIN_DOWN, GPIO_MODE_IN_PU_NO_IT);
int Dimdizi[12] = {248, 56, 152, 232, 40, 136, 112,208, 16, 160, 64, 0}; // %0 den %100'e kadar ki dim voltajları
int i =0;
//int y=0;
char status1= 1;
char status2= 1;
while (1)
{
// Check button status
if ((GPIO_ReadInputData(BUTTON_PORT) & BUTTON_PIN_UP) == (u8)0x00 )
{
Delay(20000);
if( status1==1)
{
status1=0;
i++;
if(i>=11)
{ i=11;}
// GPIO_Write( GPIOC, Dimdizi[i]);
}
}
else
{
status1=1;
}
if ((GPIO_ReadInputData(BUTTON_PORT) & BUTTON_PIN_DOWN) == (u8)0x00)
{
Delay(20000);
if( status2==1)
{
status2=0;
i--;
if(i==0) {i=0;}
// GPIO_Write( GPIOC, Dimdizi[i]);
}
}
else
{
status2=1;
}
GPIO_Write( GPIOC, Dimdizi[i]);
}
}
/**
* @brief Delay
* @param nCount
* @retval None
*/
void Delay(uint16_t nCount)
{
while (nCount != 0)
{
nCount--;
}
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
1. down butonu up gibi çalışmıyor çoğu zaman butona bir kaç kere basmam gerekiyor adım atlaması için
2. down butonunda en düşük dim seviyesine geldiğimde butona art arda bastığımda ise bir bazen iki seviye dim up yapıyor sebebi ne olabilir ??