lcd menu buton algılama sorunu

Başlatan matter, 13 Mayıs 2018, 14:20:15

matter

Merhaba,stm32f103'de 16x02 lcd menu kullanarak sera otomasyonu yapıyorum.Mikrodenetleyici programlamada yeniyim.Ana ekranda saat,tarih,sıcaklık gibi bilgiler bulunuyor.Set butonuna bastığım zaman menu kısmına giriyor.

Benim sorunum menu kısmına geçince menuler arası geçiş yaparken butona basınca bazen algılıyor bazen butonu kaçırıyor.Geçişleri düzgün olarak yapabilmem için butona 1 sn gibi basılı tutmam gerekiyor.Fakat benim istediğim butona bastımmı hiç kaçırmaması.Nerede hata yapıyorum,yardımcı olur musunuz?Teşekkürler...[code]
#include "main.h"
#include "stm32f1xx_hal.h"
#include "Character_LCD.h"

#define up GPIO_PIN_0
#define down GPIO_PIN_1
#define set GPIO_PIN_10
#define esc GPIO_PIN_11

#define relay2 GPIOB,GPIO_PIN_3
#define relay1 GPIOB,GPIO_PIN_4

/* USER CODE BEGIN Includes */

uint8_t Time[3],Date[4];
char Zaman[10],Tarih[10];
char str[10];
char contr[1];//contrast ayarı için ........... 

uint8_t s=1;
uint16_t x;


int8_t saat=15,dakika=20,saniye=30;
uint8_t gun=25, ay=4, yil=18,hafgun=1;

RTC_DateTypeDef sdatestractureget;
RTC_TimeTypeDef stimestractureget;
RTC_TimeTypeDef sTime;
RTC_DateTypeDef sDate;

uint16_t i=0;
uint8_t page=0;
uint8_t menuitem=1;


uint8_t contrast=20;

char st[5];
uint16_t ADC_Data[5];
uint8_t Depo=0;
float u[4];
uint16_t temp[2];
/*--------EEPROM DEGISKENLERI BEGIN-------------*/


uint16_t Eeprom_Data[10];     //flashaın eeprom 
uint16_t data;
volatile uint8_t Relay1_Data=0,Relay2_Data=0,Pwm_Data=0;

/*--------EEPROM DEGISKENLERI END-------------*/

/* USER CODE END Includes */

/* Private variables ---------------------------------------------------------*/
ADC_HandleTypeDef hadc1;
DMA_HandleTypeDef hdma_adc1;

RTC_HandleTypeDef hrtc;

TIM_HandleTypeDef htim4;

/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_DMA_Init(void);
static void MX_RTC_Init(void);
static void MX_TIM4_Init(void);
static void MX_ADC1_Init(void);

void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
                                

/* USER CODE BEGIN PFP */
/* Private function prototypes -----------------------------------------------*/


//////FLASH EEPROM PROGRALAMA /////
#define  Relay1_Data    	epprom_sabitleri[0]
#define  Relay2_Data    epprom_sabitleri[1]
#define  contrast   epprom_sabitleri[2]




uint16_t epprom_sabitleri[500];                     /*x=0;*/


#define EEPROM_START_ADDRESS ((uint32_t)0x0801F800) //126. page

uint16_t Read_Flash(uint32_t  adr)
{
  uint16_t * Pntr = (uint16_t *)adr;
  return(*Pntr);  
}
///////////////// FLASH KILIDI AÇMA ALT PROGRAMI /////////////////////    
void Unlock_Flash (void)
{
  FLASH->KEYR=0x45670123;  //Flash kilidini açmak için FLASH->KEYR registerine KEY1 ve KEY2 sirayla yazilmalidir
  FLASH->KEYR=0xCDEF89AB;
}
///////////////// FLASH KILITLEME ALT PROGRAMI ///////////////////// 
void Lock_Flash (void)
{
  FLASH->CR=0x00000080;  //FLASH_CR registeri resetlendiginde FLASH kiltlenmis olur
}
//////////////// ISTENILEN ADRESTEKI VERIYI FLASHTAN SILME ALT PROGRAMI //////
void Erase_Flash (uint32_t adr)
{
  FLASH->CR|=0x00000002;            //PER enable
  FLASH->AR=adr;                    //FLASH->AR registerine silinmek istenen adres yazilir
  FLASH->CR|=0x00000040;            //STRT anable
  while((FLASH->SR&0x00000001));    //Islem bitene kadar bekle(BUSY kontrol ediliyor)
  FLASH->CR &= ~0x00000042;         //FLASH->CR ilk durumuna aliniyor (kilit hala açik!) 
}
///////////////// ISTENILEN ADRESE VERI YAZMA ALT PROGRAMI /////////////////////
void Write_Flash (uint32_t adr, uint16_t data)
{
  FLASH->CR|=0x00000001;           //PG enable
  *(__IO uint16_t*)adr = data;     //istenen adrese istenen data yaziliyor
  while((FLASH->SR&0x00000001));   //Islem bitene kadar bekle(BUSY kontrol ediliyor)
}
void epprom_yaz()
{
    Unlock_Flash();
    Erase_Flash(EEPROM_START_ADDRESS); 
    for(x=0;x<=499;x++)
    Write_Flash(EEPROM_START_ADDRESS+(uint32_t)(x*2),epprom_sabitleri[x]);
    Lock_Flash(); 
}	

void eeprom_oku()
{
for(x=0;x<=499;x++)
epprom_sabitleri[x]= Read_Flash(EEPROM_START_ADDRESS+(x*2));
}


/*-----------------------------LCD MENU BEGIN--------------------------------------------------------*/
	void LCD_Menu()
		{
			page=1;
			
			LCD_Cmd(_CLEAR);
			HAL_Delay(20);
			
			LCD_Out(1,1,">");
			LCD_Out(1,2,"CLK SET");
			LCD_Out(2,2,"RELAYS");
			LCD_Out(1,12,"CONT");
			LCD_Out(2,12,"EXIT");
			
			
			while(page != 0)
				
			{
					
				if(page==1)
				{
					for(i=0;i<=250;i++)
					 {
						 
						 if(menuitem==4 && HAL_GPIO_ReadPin(GPIOB,set) )
							{
								
							 while(HAL_GPIO_ReadPin(GPIOB,set));
							 HAL_Delay(20);
								
							 LCD_Cmd(_CLEAR);
								
							 HAL_Delay(5);
									
							 page=0;
							 menuitem=0;		
							 
									
							}	
							
							if(menuitem==2 && HAL_GPIO_ReadPin(GPIOB,set)) //------RELAYS MENUSUNE GIRIS YAPILIRSA-----
						 {
							 while(HAL_GPIO_ReadPin(GPIOB,set));
							 HAL_Delay(20);
							
							 page=2;
							 break;     //eger page=2 olursa donguden cık...
							
						
						 } 
							
							if(menuitem==3 && HAL_GPIO_ReadPin(GPIOB,set)) //------CONTRAST MENUSUNE GIRIS YAPILIRSA-----
						 {
							 while(HAL_GPIO_ReadPin(GPIOB,set));
							 HAL_Delay(20);
							
							 page=3;
							 break;     //eger page=2 olursa donguden cık...
							
						
						 } 
						 
						 
						 


						else if(HAL_GPIO_ReadPin(GPIOB,up))
						{
							while(HAL_GPIO_ReadPin(GPIOB,up));
							HAL_Delay(20);
							
							menuitem--;
							if(menuitem<=0) menuitem=4;
							
						}
						 
						
						else if(HAL_GPIO_ReadPin(GPIOB,down))
						{
							while(HAL_GPIO_ReadPin(GPIOB,down));
							HAL_Delay(20);
							
							menuitem++;
							
						}
						
						else if(menuitem==1)
						{
							while(HAL_GPIO_ReadPin(GPIOB,down));
							HAL_Delay(20);
							
							LCD_Out(1,1,">");
							LCD_Out(2,1," ");
							LCD_Out(1,11," ");
							LCD_Out(2,11," ");
							
							
						
						}
						
						
						
						else if(menuitem==2)
						{
							while(HAL_GPIO_ReadPin(GPIOB,down));
							HAL_Delay(20);
							
							LCD_Out(1,1," ");
							LCD_Out(2,1,">");
							LCD_Out(1,11," ");
							LCD_Out(2,11," ");
							
							
						
						}
						
						
						
						else if(menuitem==3)
						{
							while(HAL_GPIO_ReadPin(GPIOB,down));
							HAL_Delay(20);
							
							LCD_Out(1,1," ");
							LCD_Out(2,1," ");
							LCD_Out(1,11,">");
							LCD_Out(2,11," ");
							
							
						
						}
						
						else if(menuitem==4)
						{
							while(HAL_GPIO_ReadPin(GPIOB,down));
							HAL_Delay(20);
							
							LCD_Out(1,1," ");
							LCD_Out(2,1," ");
							LCD_Out(1,11," ");
							LCD_Out(2,11,">");
							
						}
						
						
					  
						
					
					 }
				
				}
							
				if(page==2) /*-------RELAYS MENUSUNUN SAYFASI---------------------- ---*/
				{
					
					
					
					for(i=0;i<=250;i++)
					
						{
							
							
									
									LCD_Cmd(_CLEAR);
									HAL_Delay(5);
									
									menuitem=1;
									
									LCD_Out(1,1,">");
									LCD_Out(1,2,"RELAY1");
									LCD_Out(1,11,"EXIT");
									LCD_Out(2,2,"RELAY2");
									
									
									for(i=0;i<=250;i++)
									{
									
										HAL_Delay(50);
										
										 if(HAL_GPIO_ReadPin(GPIOB,down))
										{
											while(HAL_GPIO_ReadPin(GPIOB,down));
											HAL_Delay(10);
											LCD_Out(1,1," ");
											LCD_Out(1,10," ");
											LCD_Out(2,1,">");
					            menuitem++;
											if(menuitem>3) menuitem=1;
											
											
										
										}
										
										else if(HAL_GPIO_ReadPin(GPIOB,up))
											 
										 {
											while(HAL_GPIO_ReadPin(GPIOB,up));
											HAL_Delay(10);
											LCD_Out(1,1,">");
											LCD_Out(1,10," "); 
											LCD_Out(2,1," ");
											
											menuitem--;
											if(menuitem<0) menuitem=3;
											 if(menuitem>250) menuitem=3;
											
											 
										
										 }	
										
										
										
										else if(menuitem==2 && HAL_GPIO_ReadPin(GPIOB,set) ) 
										
										 {	
											  while(HAL_GPIO_ReadPin(GPIOB,set));
												HAL_Delay(10);
												HAL_GPIO_TogglePin(relay2);
											  HAL_Delay(10);
											  
										 Relay2_Data=HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_3);
										
										 epprom_yaz();
											  
											 
										 
										 
										 }
										 
										 else if(menuitem==1 && HAL_GPIO_ReadPin(GPIOB,set) ) 
										
										 {	
											  while(HAL_GPIO_ReadPin(GPIOB,set));
												HAL_Delay(10);
												HAL_GPIO_TogglePin(relay1);
											  HAL_Delay(10);
											 
										 Relay1_Data=HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_4);
										
										 epprom_yaz();
											  
										 }
										 
										 
										 else if(menuitem==3  )
										 {
												while(HAL_GPIO_ReadPin(GPIOB,set));
											  HAL_Delay(10);
											  
											  LCD_Out(1,10,">");
											  LCD_Out(2,1," ");
											  LCD_Out(2,1," ");
												
												
										 
										 }
										 
										 if(menuitem==3 && HAL_GPIO_ReadPin(GPIOB,set) )
										 {
												while(HAL_GPIO_ReadPin(GPIOB,set));
											  HAL_Delay(10);
											  
											  LCD_Menu();
											  
										 }
										 
										 
										
									 }
									
									 
							
							
						}	
								
				
				 }	
				
				 
				 
				 
				 
				 
				 

				
				if(page==3)     /*-----CONTRAST MENUSU(START)---------------------------------------------*/
					{
						
						for(i=0;i<=250;i++)
					
						{
							
							
									
									LCD_Cmd(_CLEAR);
									HAL_Delay(5);
									
									menuitem=1;
									
						    	sprintf(contr,"CONTRAST:%d",contrast);
							
									LCD_Out(1,2,contr);
									LCD_Out(2,2,"EXIT");
									LCD_Out(1,1,">");
									menuitem=1;
									
									
									
									for(i=0;i<=250;i++)
									{
									
										HAL_Delay(50);
										
										 if(HAL_GPIO_ReadPin(GPIOB,down))
										{
											while(HAL_GPIO_ReadPin(GPIOB,down));
											HAL_Delay(10);
											menuitem=2;
											LCD_Out(1,1," "); 
											LCD_Out(2,1,">");
											
											if(menuitem>2) menuitem=1;
					            
										
										}
										
										 if(HAL_GPIO_ReadPin(GPIOB,up))
											 
										 {
											while(HAL_GPIO_ReadPin(GPIOB,up));
											HAL_Delay(10);
											LCD_Out(1,1,">"); 
											LCD_Out(2,1," ");
											
											menuitem=1;
											if(menuitem<0) menuitem=2;
											 
										
										 }	
										
										
										
										 if(menuitem==1 && HAL_GPIO_ReadPin(GPIOB,set) ) 
										
										 {	
											  while(HAL_GPIO_ReadPin(GPIOB,set));
												HAL_Delay(10);
											  
												for(i=0;i<=2000;i++)
													{
														
														if(HAL_GPIO_ReadPin(GPIOB,up))
														 {
															while(HAL_GPIO_ReadPin(GPIOB,up));
															HAL_Delay(10);
															contrast=contrast+5;
															if(contrast>100) contrast=100; 
															 
															epprom_yaz(); 
														 }
														 
														 if(HAL_GPIO_ReadPin(GPIOB,down))
														 {
															while(HAL_GPIO_ReadPin(GPIOB,down));
															HAL_Delay(10);
															
															contrast=contrast-5;
															if(contrast<0) contrast=0;
															if(contrast>240) contrast=0;
															
															epprom_yaz();	
															 
														 }
														
														sprintf (st,"%d",contrast);
					                	if(i==240){LCD_Out(1,11,st);}
					                  if(i==120){LCD_Out(1,11,"    ");}
														htim4.Instance-> CCR1 =contrast;
					                  HAL_Delay(2);
														
														if(HAL_GPIO_ReadPin(GPIOB,set))
														{
															while(HAL_GPIO_ReadPin(GPIOB,set));
															HAL_Delay(10);
															LCD_Out(1,11,st);
															break;
														}
													
													}
											 
											 
										 }
										 
										 
										 if(menuitem==2 && HAL_GPIO_ReadPin(GPIOB,set) )
										 {
												while(HAL_GPIO_ReadPin(GPIOB,set));
											  HAL_Delay(10);
											  menuitem=1;
											  LCD_Menu();
											  
										 }
										 
										 
										
								 }
									
						  
							
							
						}	
				
				
				
					}/*-----CONTRAST MENUSU(STOP)-----------------------------------------------------------*/
				

							
			}			
				
		}
			
/*-----------------------------LCD MENU END--------------------------------------------------------*/
		


/* USER CODE END PFP */

/* USER CODE BEGIN 0 */


 

/* USER CODE END 0 */

/**
  * @brief  The application entry point.
  *
  * @retval None
  */
int main(void)
{
  /* USER CODE BEGIN 1 */
	
	
  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_RTC_Init();
  MX_TIM4_Init();
  MX_ADC1_Init();
  /* USER CODE BEGIN 2 */
	
	
	LCD_Init(_LCD_4BIT, _LCD_FONT_5x8, _LCD_2LINE);
	HAL_ADC_Start_DMA(&hadc1,(uint32_t*)&ADC_Data,5); //adc dma baslatma...
	
	
	HAL_TIM_PWM_Start(&htim4,TIM_CHANNEL_1); //timer4 kanal 1 pwm başlat..
	HAL_TIM_PWM_Start(&htim4,TIM_CHANNEL_2); //timer4 kanal 2 pwm başlat..
	
	
	
	
	//Set time, data and alarm
	//1) Set time 
	sTime.Hours = saat;
	sTime.Minutes = dakika;
	sTime.Seconds = saniye;
	HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN);
	
	//2) Set date 
	sDate.Date = gun;
	sDate.Month = ay;
	sDate.WeekDay = RTC_WEEKDAY_SUNDAY;
	sDate.Year = yil;
	HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BIN);

  /* USER CODE END 2 */
	/*MENU SIMULASYONU(START)--------------------------------------------------------------------------*/
	contrast=Read_Flash(0x0801F804);
	htim4.Instance-> CCR1 =contrast;
	HAL_Delay(20);
	LCD_Cmd(_CLEAR);
	HAL_Delay(20);
	LCD_Out(1,5,"Loading.");
	HAL_Delay(300);
	LCD_Out(1,5,"Loading..");
	HAL_Delay(300);
	LCD_Out(1,5,"Loading...");
	HAL_Delay(500);
	LCD_Cmd(_CLEAR);
	
	
	/*MENU SIMULASYONU(STOP)--------------------------------------------------------------------------*/
	
	
  
	
	

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
		/*---CONTRAST PROCESS(START)--------------------------------------------------------------------------*/
		contrast=Read_Flash(0x0801F804);
		HAL_Delay(5);
		htim4.Instance-> CCR1 =contrast;
	
	 /*---CONTRAST PROCESS(STOP)----------------------------------------------------------------------------*/

  /* USER CODE END WHILE */
		
		HAL_RTC_GetTime(&hrtc,&stimestractureget,RTC_FORMAT_BIN);
		HAL_RTC_GetDate(&hrtc,&sdatestractureget,RTC_FORMAT_BIN);
		
		Time[0]=stimestractureget.Hours;
		Time[1]=stimestractureget.Minutes;
		Time[2]=stimestractureget.Seconds;
		
		Date[0]=sdatestractureget.Year;
		Date[1]=sdatestractureget.Month;
		Date[2]=sdatestractureget.Date;
		Date[3]=sdatestractureget.WeekDay;
		
		
		
		
		
	  HAL_Delay(10);
		sprintf(Zaman,"%02d:%02d",Time[0],Time[1],Time[2]);    //lcd de yer olmadigi icin :%02d sn kullanılmadı... 
		sprintf(Tarih,"%02d/%02d/%04d",Date[2],Date[1],2000+Date[0]);
		
		//LCD_Out(2,4,Tarih);
		LCD_Out(1,12,Zaman);
	
		LCD_Out(1,6,"M:%"); //---------------------MOTOR YUK BILGISI-------------------------------------
		
		/* ADC ISLEMLERI(START) --------------------------------------------------------------------------*/
		
		Depo=(ADC_Data[0]*98)/2600;
		
		u[0]=ADC_Data[2]*3.3/4040;                //LM35 in ürettiği gerilim degeri mv cinsinden...
		
		
		
		sprintf(str,"D:%02d",Depo);         //ADC_Data[0] depo yuzdesi.....
		LCD_Out(1,1,str);
		HAL_Delay(20);
		
		sprintf(str,"%04d",ADC_Data[1]);    //ADC_Data[1] deki veri(bos)....
		LCD_Out(2,1,str);
		HAL_Delay(5);
		
		
		sprintf(str,"T:%.2f",u[0]);    //ADC_Data[2] deki veri (lm35) ....
		LCD_Out(2,11,str);
		HAL_Delay(5);
		
		/* ADC ISLEMLERI(STOP) --------------------------------------------------------------------------*/
		
		
		
		/*DONGU ISLEMLERI(START) ------------------------------------------------------------------------*/
		
		if(HAL_GPIO_ReadPin(GPIOB,set))
		{
			while(HAL_GPIO_ReadPin(GPIOB,set))
			HAL_Delay(20);
			LCD_Menu();	
		
		}
		
		/*DONGU ISLEMLERI(STOP) -------------------------------------------------------------------------*/
		Relay2_Data=Read_Flash(0x0801F802);
		Relay1_Data=Read_Flash(0x0801F800);
		
		if(Relay1_Data == 1)
		 {
			HAL_GPIO_WritePin(GPIOB,GPIO_PIN_4,GPIO_PIN_SET);
		 
		 }
    
    else
		{
			HAL_GPIO_WritePin(GPIOB,GPIO_PIN_4,GPIO_PIN_RESET);
		
		}
		
		
		if(Relay2_Data == 1)
		 {
			HAL_GPIO_WritePin(GPIOB,GPIO_PIN_3,GPIO_PIN_SET);
		 
		 }
    
    else
		{
			HAL_GPIO_WritePin(GPIOB,GPIO_PIN_3,GPIO_PIN_RESET);
		
		}
		
		
		
		
		
		
    //Eeprom_Data[1]=Read_Flash(0x0801F802);
		
		
		
		
		

  /* USER CODE BEGIN 3 */

  }
  /* USER CODE END 3 */

}

/**
  * @brief System Clock Configuration
  * @retval None
  */
void SystemClock_Config(void)
{

  RCC_OscInitTypeDef RCC_OscInitStruct;
  RCC_ClkInitTypeDef RCC_ClkInitStruct;
  RCC_PeriphCLKInitTypeDef PeriphClkInit;

    /**Initializes the CPU, AHB and APB busses clocks 
    */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE|RCC_OSCILLATORTYPE_LSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  RCC_OscInitStruct.LSEState = RCC_LSE_ON;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL7;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }

    /**Initializes the CPU, AHB and APB busses clocks 
    */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }

  PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC|RCC_PERIPHCLK_ADC;
  PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
  PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV4;
  if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }

    /**Configure the Systick interrupt time 
    */
  HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

    /**Configure the Systick 
    */
  HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

  /* SysTick_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
}

/* ADC1 init function */
static void MX_ADC1_Init(void)
{

  ADC_ChannelConfTypeDef sConfig;

    /**Common config 
    */
  hadc1.Instance = ADC1;
  hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE;
  hadc1.Init.ContinuousConvMode = ENABLE;
  hadc1.Init.DiscontinuousConvMode = DISABLE;
  hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  hadc1.Init.NbrOfConversion = 5;
  if (HAL_ADC_Init(&hadc1) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }

    /**Configure Regular Channel 
    */
  sConfig.Channel = ADC_CHANNEL_3;
  sConfig.Rank = ADC_REGULAR_RANK_1;
  sConfig.SamplingTime = ADC_SAMPLETIME_71CYCLES_5;
  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }

    /**Configure Regular Channel 
    */
  sConfig.Channel = ADC_CHANNEL_4;
  sConfig.Rank = ADC_REGULAR_RANK_2;
  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }

    /**Configure Regular Channel 
    */
  sConfig.Channel = ADC_CHANNEL_5;
  sConfig.Rank = ADC_REGULAR_RANK_3;
  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }

    /**Configure Regular Channel 
    */
  sConfig.Channel = ADC_CHANNEL_6;
  sConfig.Rank = ADC_REGULAR_RANK_4;
  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }

    /**Configure Regular Channel 
    */
  sConfig.Channel = ADC_CHANNEL_7;
  sConfig.Rank = ADC_REGULAR_RANK_5;
  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }

}

/* RTC init function */
static void MX_RTC_Init(void)
{

  RTC_TimeTypeDef sTime;
  RTC_DateTypeDef DateToUpdate;

    /**Initialize RTC Only 
    */
  hrtc.Instance = RTC;
  if(HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR1) != 0x32F2){
  hrtc.Init.AsynchPrediv = RTC_AUTO_1_SECOND;
  hrtc.Init.OutPut = RTC_OUTPUTSOURCE_ALARM;
  if (HAL_RTC_Init(&hrtc) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }

    /**Initialize RTC and set the Time and Date 
    */
  sTime.Hours = 1;
  sTime.Minutes = 0;
  sTime.Seconds = 0;

  if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }

  DateToUpdate.WeekDay = RTC_WEEKDAY_MONDAY;
  DateToUpdate.Month = RTC_MONTH_JANUARY;
  DateToUpdate.Date = 1;
  DateToUpdate.Year = 0;

  if (HAL_RTC_SetDate(&hrtc, &DateToUpdate, RTC_FORMAT_BIN) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }

    HAL_RTCEx_BKUPWrite(&hrtc,RTC_BKP_DR1,0x32F2);
  }

}

/* TIM4 init function */
static void MX_TIM4_Init(void)
{

  TIM_ClockConfigTypeDef sClockSourceConfig;
  TIM_MasterConfigTypeDef sMasterConfig;
  TIM_OC_InitTypeDef sConfigOC;

  htim4.Instance = TIM4;
  htim4.Init.Prescaler = 72-1;
  htim4.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim4.Init.Period = 100-1;
  htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  htim4.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  if (HAL_TIM_Base_Init(&htim4) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }

  sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  if (HAL_TIM_ConfigClockSource(&htim4, &sClockSourceConfig) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }

  if (HAL_TIM_PWM_Init(&htim4) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }

  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  if (HAL_TIMEx_MasterConfigSynchronization(&htim4, &sMasterConfig) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }

  sConfigOC.OCMode = TIM_OCMODE_PWM1;
  sConfigOC.Pulse = 0;
  sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
  sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
  if (HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }

  if (HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }

  HAL_TIM_MspPostInit(&htim4);

}

/** 
  * Enable DMA controller clock
  */
static void MX_DMA_Init(void) 
{
  /* DMA controller clock enable */
  __HAL_RCC_DMA1_CLK_ENABLE();

  /* DMA interrupt init */
  /* DMA1_Channel1_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn);

}

/** Configure pins as 
        * Analog 
        * Input 
        * Output
        * EVENT_OUT
        * EXTI
*/
static void MX_GPIO_Init(void)
{

  GPIO_InitTypeDef GPIO_InitStruct;

  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOC_CLK_ENABLE();
  __HAL_RCC_GPIOD_CLK_ENABLE();
  __HAL_RCC_GPIOA_CLK_ENABLE();
  __HAL_RCC_GPIOB_CLK_ENABLE();

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_2|LCD_EN_Pin|LCD_RS_Pin|GPIO_PIN_15, GPIO_PIN_RESET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOB, LCD_D4_Pin|LCD_D5_Pin|LCD_D6_Pin|LCD_D7_Pin 
                          |GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5, GPIO_PIN_RESET);

  /*Configure GPIO pins : PA0 PA1 */
  GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /*Configure GPIO pins : PA2 LCD_EN_Pin LCD_RS_Pin PA15 */
  GPIO_InitStruct.Pin = GPIO_PIN_2|LCD_EN_Pin|LCD_RS_Pin|GPIO_PIN_15;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /*Configure GPIO pins : PB0 PB1 PB10 PB11 */
  GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_10|GPIO_PIN_11;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  /*Configure GPIO pins : LCD_D4_Pin LCD_D5_Pin LCD_D6_Pin LCD_D7_Pin 
                           PB3 PB4 PB5 */
  GPIO_InitStruct.Pin = LCD_D4_Pin|LCD_D5_Pin|LCD_D6_Pin|LCD_D7_Pin 
                          |GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

}

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */

/**
  * @brief  This function is executed in case of error occurrence.
  * @param  file: The file name as string.
  * @param  line: The line in file as a number.
  * @retval None
  */
void _Error_Handler(char *file, int line)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */
  while(1)
  {
  }
  /* USER CODE END Error_Handler_Debug */
}

#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 CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
     tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */

/**
  * @}
  */

/**
  * @}
  */

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