stm8s003f3 buton ile dim kontrol

isoment01

Üye
Katılım
26 Haz 2016
Mesajlar
197
Puanları
1
Yaş
32
C:
/**
  ******************************************************************************
  * @file    GPIO_Toggle\main.c
  * @author  MCD Application Team
  * @version V2.0.4
  * @date    26-April-2018
  * @brief   This file contains the main function for GPIO Toggle example.
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
  *
  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  * You may not use this file except in compliance with the License.
  * You may obtain a copy of the License at:
  *
  *        http://www.st.com/software_license_agreement_liberty_v2
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  *
  ******************************************************************************
  */

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

/**
  * @addtogroup GPIO_Toggle
  * @{
  */

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Evalboard I/Os configuration */

#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 macro -------------------------------------------------------------*/
/* 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_FL_NO_IT);
  GPIO_Init(BUTTON_PORT, (GPIO_Pin_TypeDef)BUTTON_PIN_DOWN, GPIO_MODE_IN_FL_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) == PRESSED     )
    {
      for(y=0; y<BUTTON_DEBOUNCE_TIME; y++);
      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) == PRESSED    )
    {
      for(y=0; y<BUTTON_DEBOUNCE_TIME; y++);
      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)
{
  /* Decrement nCount value */
  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****/
butona bır kere basıldığında bir seviye basılı tutulduğunda ise sıralı seviye atlayacak bir buton dim kontrol devresi yapmak istedim stm8s003f3 ile fakat yapamadım yardımcı olabilecek arkadaşlar var mıdır ?
 
burada up yapabiliyorum bir kere bastığımda bir dim seviyesi atlıyor fakat down tarafında sorunlarım var.
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 ??
 

Yeni mesajlar

Forum istatistikleri

Konular
129,801
Mesajlar
930,219
Kullanıcılar
452,603
Son üye
MFK12123

Yeni konular

Geri
Üst