Haberler:

Forum kuralları güncellendi LÜTFEN  okuyunuz:  https://bit.ly/2IjR3ME

Ana Menü

STM32F4 RTC ile LCD Sorunu

Başlatan yagizhanyakali, 04 Aralık 2016, 13:37:33

yagizhanyakali

Merhaba herkese;

Ben RTC kullanarak LCD'ye saat yazdırmak istiyorum fakat bunu başaramadım. Kodları yazıp cihaza yolluyorum fakat hiçbir tepki vermiyor. Yardım edebilir misiniz acaba ?

Teşekkürler...

Yazdığım kodlar
#include "main.h"
#include "lcd.h"
#include <stm32f4xx.h>
#include "stm32f4xx_rtc.h"
#include "stm32f4xx_pwr.h"

RTC_TimeTypeDef RTC_TimeStructure;
RTC_DateTypeDef RTC_DateStructure;
RTC_AlarmTypeDef RTC_AlarmStructure;
RTC_InitTypeDef RTC_InitStructure;
char b[16];
static int8_t  sec, min, hour;
static __IO uint32_t TimingDelay;
void Delay(__IO uint32_t nTime);

void RTC_Kur()
{
  /* Enable the PWR clock */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
  /* Allow access to RTC */
  PWR_BackupAccessCmd(ENABLE);
  // #if defined (RTC_CLOCK_SOURCE_LSI) /* LSI used as RTC source clock*/
  /* The RTC Clock may varies due to LSI frequency dispersion */
  /* Enable the LSI OSC */
  RCC_LSICmd(ENABLE);
  /* Wait till LSI is ready */
  while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET)
  {
  }
  /* Select the RTC Clock Source */
  RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
  /* Enable the RTC Clock */
  RCC_RTCCLKCmd(ENABLE);
  /* Wait for RTC APB registers synchronisation */
  RTC_WaitForSynchro();
  /* Configure the RTC data register and RTC prescaler */
  RTC_InitStructure.RTC_AsynchPrediv = 0x7F;
  RTC_InitStructure.RTC_SynchPrediv = 0xFF;
  RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
  RTC_Init(&RTC_InitStructure);
  /* Set the date: */
  RTC_DateStructure.RTC_Year = 14; //Year Set
  RTC_DateStructure.RTC_Month = RTC_Month_November ; //Month date 
  RTC_DateStructure.RTC_Date = 9; // Day count set
  RTC_DateStructure.RTC_WeekDay = RTC_Weekday_Saturday; //Day set
  RTC_SetDate(RTC_Format_BCD, &RTC_DateStructure);
  /* Set the time to */
  //RTC_TimeStructure.RTC_H12 = RTC_H12_PM;
  RTC_TimeStructure.RTC_Hours = 01;
  RTC_TimeStructure.RTC_Minutes = 37;
  RTC_TimeStructure.RTC_Seconds = 30;
  RTC_SetTime(RTC_Format_BIN, &RTC_TimeStructure);
  RTC_SetDate(RTC_Format_BIN, &RTC_DateStructure);
  /* Indicator for the RTC configuration */
  RTC_WriteBackupRegister(RTC_BKP_DR0, 0x32F2);
}

 

void Init_GPIO()
{
 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOC,ENABLE);
 
 GPIO_InitTypeDef GPIO_InitStructure;
 
 GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT;
 GPIO_InitStructure.GPIO_Pin=GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
 GPIO_Init(GPIOC, &GPIO_InitStructure);
 
 GPIO_InitStructure.GPIO_Pin =GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
 GPIO_Init(GPIOA, &GPIO_InitStructure);
}
 

void setLCD(int display,int cursor,int blink);
void setCursor(int x,int y);
void clrLCD(void);
void initLCD (int row,int data,int size);
void printLCD(char *c);
void s_init();
void s_data();
void s_latch();
 
int main()
{
 clrLCD();
 Init_GPIO();
 RTC_Kur();
 initLCD(2,8,1);
 setLCD(1,0,0); 
 setCursor(0,0); 
 printLCD(" YAGIZHAN  "); 
 setCursor(0,1);
 printLCD(" YAKALI ");
 Delay(5000);
 clrLCD();
 if (SysTick_Config(SystemCoreClock / 1000))
 {
 while (1);
 }
 while(1)
 {
      RTC_GetTime(RTC_Format_BCD, &RTC_TimeStructure);
      sec = RTC_TimeStructure.RTC_Seconds;
      min = RTC_TimeStructure.RTC_Minutes;
      hour = RTC_TimeStructure.RTC_Hours;
      
      b[4]=(((hour & 0xF0)>>4) +'0');
      b[5]=((hour & 0x0F) +'0');
      b[6]=':';
      b[7]=(((min & 0xF0)>>4) +'0');
      b[8]=((min & 0x0F) +'0');
      b[9]=':';
      b[10]=(((sec & 0xF0)>>4) +'0');
      b[11]=((sec & 0x0F) +'0');
      b[0]=' ';b[1]=' ';b[2]=' ';b[3]=' ';b[12]=' ';b[13]=' ';b[14]=' ';b[15]=' ';
      setCursor(0,0);
      printLCD(b);
 }
}
 
void Delay(__IO uint32_t nTime)
{
 TimingDelay = nTime;
 
while(TimingDelay != 0);
}
 
void TimingDelay_Decrement(void)
{
 if (TimingDelay != 0x00)
 {
 TimingDelay--;
 }
}


RTC tanımlamasında yada kullanışında bir hata yapmış olabilirim fakat main fonksiyonunun başındaki LCD ekranına yazı yazdırma kodlarıda çalışmıyor.

lcd.c
#include "lcd.h"

static __IO uint32_t TimingDelay;
void Delay(__IO uint32_t nTime);

void s_init(){
  GPIOC->BSRRL=0;
  GPIOC->BSRRH=RS;
  GPIOC->BSRRH=RW;
}
void s_data(){
  GPIOC->BSRRL=RS;
  GPIOC->BSRRH=RW;
}
void s_latch(){
  GPIOC->BSRRL=EN;
  Delay(1);
  GPIOC->BSRRL=0x0000;
  GPIOC->BSRRH=EN;
  Delay(1);  
}

void initLCD (int row,int data,int size)
{
  GPIOC->BSRRL=0;
  GPIOC->BSRRH=RS;
  GPIOC->BSRRH=RW;
  GPIOC->BSRRL=EN;

  Delay(10);

  s_init();
  GPIOA->ODR=0x0001; //LCD Temizle ve Başlangıça Git
  s_latch();
  if(row==1)
  {
    if(data==4)
    {
      
      if(size==1)
      {
        GPIOA->ODR=0x0020;
      }
      else if(size==2)
      {
        GPIOA->ODR=0x0024;
      }
    }
    else if(data==8)
    {
      if(size==1)
      {
        GPIOA->ODR=0x0030;
      }
      else if(size==2)
      {
        GPIOA->ODR=0x0034;
      }
    }
  }
  if(row==2)
  {
    if(data==4)
    {
      if(size==1)
      {
        GPIOA->ODR=0x0028;
      }
      else if(size==2)
      {
        GPIOA->ODR=0x002C;
      }
    }
    else if(data==8)
    {
      if(size==1)
      {
        GPIOA->ODR=0x0038;
      }
      else if(size==2)
      {
        GPIOA->ODR=0x003C;
      }
    }
  }
  
  for(int i=0;i<4;i++) s_latch();
}

void clrLCD()
{
  s_init();
  GPIOA->ODR=0x0001;
  s_latch();
}

void setCursor(int x,int y)
{
  s_init();
  if(y==0)
  {
    GPIOA->ODR=0x0002; // Cursor 1.Satıra Taşındı.
    s_latch();
    for(int i=0;i<x;i++){
      GPIOA->ODR=0x00014;
      s_latch();
    }
    GPIOA->ODR=0x0006;
    s_latch();
  }
  if(y==1)
  {
    GPIOA->ODR=0x00C0; // Cursor 2.Satıra Taşındı.
    s_latch();
    for(int i=0;i<x;i++){
      GPIOA->ODR=0x00014;
      s_latch();
    }
    GPIOA->ODR=0x0006;
    s_latch();
  }
}

void setLCD(int display,int cursor,int blink)
{
  s_init(); 
  if(display==0)
  {
    GPIOA->ODR=0x0008;
  }
  if(display==1)
  {
    if(cursor==0){
      GPIOA->ODR=0x000C;
    }else{
      if(blink==0){
        GPIOA->ODR=0x000E;
      }else{
        GPIOA->ODR=0x000F;
      }
    }
  }
  s_latch();
}

void printLCD(char *c){
  s_data();
  
  for(int k=0;c[k];k++)
  {
    GPIOA->ODR=c[k];
    
    s_latch();
  }
}


lcd.h
#include "stm32f4xx.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"

#define RS GPIO_Pin_13 // RS is named as Port 13
#define RW GPIO_Pin_14 // RW is named as Port 14
#define EN GPIO_Pin_15 // EN is named as Port 15

Andromeda

Programı parçalara bölebilirsin..
lcd ye yazma,rtc den okunan verilerin olduğu değişken satırı,verileri alan satır gibi..
sonra bunları sırayla test et..mesela önce lcd ye sabit birşey yazdır..
" Tanrı, iradesini hakim kılmak için yeryüzündeki iyi insanları kullanır, yeryüzündeki kötü insanlar ise kendi iradelerini hakim kılmak için Tanrı'yı kullanırlar." ..." Tanrı'dan mesaj gelmiyor, biz Tanrı'ya mesaj gönderiyoruz"

yagizhanyakali

Sorunu buldum;

if (SysTick_Config(SystemCoreClock / 1000))
 {
 while (1);
 }

kodunu main fonksiyonunun en başına aldım ve program çalıştı. Basit bir çözümü varmış. Teşekkür ederim ilginiz için...