STM8'DE if else fonksiyonu

isoment01

Üye
Katılım
26 Haz 2016
Mesajlar
197
Puanları
1
Yaş
31
Arkadaşlar basit bir buton artır, azalt komutum var fakat tutarsız çalışıyor. buton up komutları düzgün işlerken, down komutları işlemiyor vs. kodlarım ve devre şemam burada yardımlarını bekliyorum.
Kod:
/* Includes ------------------------------------------------------------------*/
#include "stm8s.h"
#include "flash.h"
#include "main.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_DIM_UP  (GPIO_PIN_4)
#define BUTTON_DIM_DOWN  (GPIO_PIN_5)
char Dimdizi[10] = {184, 152, 104, 200, 136, 112, 208, 16, 160, 0}; // %0 den %100'e kadar ki dim voltajları
int i;

/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/


/* Private function prototypes -----------------------------------------------*/
void Delay (uint16_t ui16Count);
void ConfigureClock(void);



/* Main program.*/

void main(void)
{

    ConfigureClock();
//enableInterrupts();
//  GPIO_setup();
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_DIM_UP,GPIO_MODE_IN_PU_NO_IT);
GPIO_Init (BUTTON_PORT, (GPIO_Pin_TypeDef)BUTTON_DIM_DOWN, GPIO_MODE_IN_PU_NO_IT);

  int status1= 1;
  int status2= 1;

i= FlashRead(DIM_ADDRESS);
    if(i<0 || i>9)
      {
      i=5;
      }

  while (1)
  {


 
    if ((GPIO_ReadInputData(BUTTON_PORT) & (BUTTON_DIM_UP)) == (u8)0x00 )
    {
      if (status1==1)
      {

     status1=0;
     i++;

     if(i>=9) i=9;          
      }
       Delay(5000);
     FlashWrite(DIM_ADDRESS, i);
 
    }
    else status1=1;
   
     if ((GPIO_ReadInputData(BUTTON_PORT) & (BUTTON_DIM_DOWN)) == (u8)0x00 )
    {
      if (status2==1)
      {
     
      status2=0;
      i--;
     
      if(i<=0) i=0;
      }
       Delay(5000);
     FlashWrite(DIM_ADDRESS, i);
   
    }
     
    else status2=1;


    GPIO_Write( GPIOC,  Dimdizi[i]);
   
   

  }


}

//-********-*-*-*-*-***-*-***************
void ConfigureClock()
{
  CLK_DeInit();
  CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV4);
}
//------------------------
//-----------------------------------
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
Untitled.png
 

Forum istatistikleri

Konular
127,950
Mesajlar
913,847
Kullanıcılar
449,596
Son üye
anilhikmet

Yeni konular

Geri
Üst