6 Replies Latest reply on Apr 21, 2015 10:28 AM by user_385543602

    LCD with ds1307

    user_444739275

      Hello

         

          

         

                

         

      I have  Psoc 4  KIt.  recentally I have done LED, LCD based  Project. Now I want to interface ds1307 with LCD. I looked  example project. That’s based on Psoc 3. But I am using Psoc 4

         

       I created design.  Design consist of LCD and ds1307. I am attaching my project workspace. please inform me there is any mistake in design 

         

      I am having problem in programming. I saw program in example project. That program was  written for Psoc 3.

         

       

         

      #include <device.h>
      #include "utils.h"

         

      void main()
      {
          uint8 tmpVar = 0u;

          RTC_TIME_DATE Start;

          /* Fill struct with date and time */
          Start.Sec = 55u;
          Start.Min = 59u;
          Start.Hour = 22u;
          Start.DayOfMonth = 31u;
          Start.Month = 12u;
          Start.Year = 2007u;

          /* Enable all interrupts */
          CyGlobalIntEnable;

          /* Set date and time */
          RTC_WriteTime(&Start);

          /* Set alarm date and time */
          RTC_WriteAlarmSecond(5u);
          RTC_WriteAlarmMinute(3u);
          RTC_WriteAlarmHour(1u);
          RTC_WriteAlarmDayOfMonth(1u);
          RTC_WriteAlarmMonth(1u);
          RTC_WriteAlarmYear(2008u);

          /* Set alarm mask */
          RTC_WriteAlarmMask(RTC_ALARM_SEC_MASK   | RTC_ALARM_MIN_MASK        |
                             RTC_ALARM_HOUR_MASK  | RTC_ALARM_DAYOFMONTH_MASK |
                             RTC_ALARM_MONTH_MASK | RTC_ALARM_YEAR_MASK);

          /* Set interval mask - handling of interrupt stubs of the RTC component */
          RTC_WriteIntervalMask(RTC_INTERVAL_SEC_MASK  | RTC_INTERVAL_MIN_MASK   |
                                RTC_INTERVAL_HOUR_MASK | RTC_INTERVAL_DAY_MASK   |
                                RTC_INTERVAL_WEEK_MASK | RTC_INTERVAL_MONTH_MASK |
                                RTC_INTERVAL_YEAR_MASK);

          /* DST start configuration */
          RTC_WriteDSTMode(RTC_DST_ENABLE | RTC_DST_FIXDATE);
          RTC_WriteDSTStartHour(23u);
          RTC_WriteDSTStartDayOfMonth(31u);
          RTC_WriteDSTStartMonth(12u);

          /* DST stop configuration */
          RTC_WriteDSTStopHour(2u);
          RTC_WriteDSTStopDayOfMonth(1u);
          RTC_WriteDSTStopMonth(1u);
          RTC_WriteDSTOffset(123u);

          /* Start RTC */
          RTC_Start();

          /* Start LCD */
          LCD_Start();

          /* Prepare 0th column */
          LCD_Position(0u, 0u);
          LCD_PrintString("RTC    :  :  ");

          /* Print current time */
          tmpVar = RTC_ReadSecond();
          PrintDecNumber(tmpVar, 0u, 11u);
          tmpVar = RTC_ReadMinute();
          PrintDecNumber(tmpVar, 0u, 8u);
          tmpVar = RTC_ReadHour();
          PrintDecNumber(tmpVar, 0u, 5u);

          /* Prepare 1st column */
          LCD_Position(1u, 0u);
          LCD_PrintString("  -  - ");

          /* Get and print day of month */
          tmpVar = RTC_ReadDayOfMonth();
          PrintDecNumber(tmpVar, 1u, 0u);

          /* Get and print month */
          tmpVar = RTC_ReadMonth();
          PrintDecNumber(tmpVar, 1u, 3u);

          /* Get and print year */
          tmpVar = (uint8)(RTC_ReadYear() % 100u);
          PrintDecNumber(tmpVar, 1u, 6u);

          /* Get and print day of week */
          tmpVar = RTC_currentTimeDate.DayOfWeek;
          LCD_Position(1u, 9u);
          LCD_PutChar(tmpVar + 0x30u);

          /* Get status */
          tmpVar = RTC_ReadStatus();

          /* Get and print if year is leap */
          if(RTC_STATUS_LY & tmpVar)
          {
              LCD_Position(1u, 11u);
              LCD_PutChar('L');
          }
          else
          {
              LCD_Position(1u, 11u);
              LCD_PutChar(' ');
          }

          /* Get and print daytime AM/PM */
          if(RTC_STATUS_AM_PM & tmpVar)
          {
              LCD_Position(0u, 14u);
              LCD_PrintString("PM");
          }
          else
          {
              LCD_Position(0u, 14u);
              LCD_PrintString("AM");
          }

          /* Get and print DST status */
          if (RTC_STATUS_DST & tmpVar)
          {
              LCD_Position(1u, 13u);
              LCD_PutChar('D');
          }
          else
          {
              LCD_Position(1u, 13u);
              LCD_PutChar(' ');
          }

          /* Get and print alarm status */
          if (RTC_STATUS_AA & tmpVar)
          {
              LCD_Position(1u, 15u);
              LCD_PutChar('A');
          }
          else
          {
              LCD_Position(1u, 15u);
              LCD_PutChar(' ');
          }

          while(1u)
          {
              /* Make a 100 ms delay */
              CyDelay(100);

              /* Prepare clock tree configuration for low power mode entry */
              CyPmSaveClocks();

              #if(CY_PSOC3)
                  /*******************************************************************
                  * Disable RTC interrupt before entering Sleep mode. The device will
                  * wake up on one pulse-per-second event, but the ISR will be
                  * executed when RTC interrupts will be enabled, after the clocks
                  * configuration will be restores. Potentially, this will allow to
                  * execute RTC ISR quicker, as CyPmSaveClocks() function could
                  * decrease master clock frequency. For PSoC 5 architectures
                  * (PSoC 5LP device), an interrupt is required for the CPU to wake
                  * up, so interrupt is disabled for PSoC3 only.
                  *******************************************************************/
                  RTC_DisableInt();
              #endif /* (CY_PSOC3) */

              /* Entry Sleep low power mode */
              CyPmSleep(PM_SLEEP_TIME_NONE, PM_SLEEP_SRC_ONE_PPS);

              /* Restore clock tree configuration */
              CyPmRestoreClocks();


              #if(CY_PSOC3)
                  /*******************************************************************
                  * Enable RTC interrupt for ISR to be executed on restored clock
                  * frequency.
                  *******************************************************************/
                  RTC_EnableInt();
              #endif /* (CY_PSOC3) */
          }
      }


      /* [] END OF FILE */

        • 1. Re: LCD with ds1307
          user_1377889

          @Vead,

             

          can you please switch to posting complete projects here and not code-snippets only. It makes our lifes a bit easier because we can just compile and debug and so answer your questions. Additionally with the help of the IDE reading your code is really easier than without.

             

          To post your complete project use
          Creator->File->Create Workspace Bundle (minimal)
          and attach the resulting file.



          Bob
           

          • 2. Re: LCD with ds1307
            user_444739275

            hello

               

            ok , I am attaching complete Project

            • 3. Re: LCD with ds1307
              user_1377889

              #include "utils.h" file is missing in your archive

                 

              you deleted by accident a line with "{" after the line "int main()"

                 

              The RTC-component in PSoC3 has nothing to do with the Dallas ds1307 chip

                 

              The ds1307 is interfaced with a I2C communication and is able when powered with a coin cell to keep time and date information.

                 

              What exactly do you want to build? An alarm clock with an LCD? Running on battery? Tell us a bit more, please.

                 

              What you have got as equipment is a "Prototype" Kit which is goog for building a prototype - as the name says - but it will not be easy for the development and testing phase. These are supported best by the "Pioneer" kits as the CY8CKIT-042 or even better the new CY8CKIT-044. So I would suggest you to get hands on one of them for the development and debugging. Then you can use the cheaper CY8CKit-049-42xx and program the tested project into this target.

                 

              A point of criticism I have is your style of programming. You put everything into a now quite lengthy main(). The trick is "divide et impera". When you break your functionality into some modules (Initialization, display clock, set clock, etc) you not only get something more readable, but you are able to debug and test parts of your project until error-free and rely on that code. When all is within one procedure errors can pop-up everywhere especially after changes.

                 

               

                 

              Bob

              • 4. Re: LCD with ds1307
                content.librarian

                ok        I have cy8ckit -049-42xx Psoc 4  KIt. I will  buy prototype kit very  soon. I have LCD and ds1307. recentally I have done two  Projects

                   

                 I am having problem in coding.  when I type utils.h I am getting error.  just tell me how to remove error

                   

                utils.h: No such file or directory

                • 5. Re: LCD with ds1307
                  user_1377889

                  I would suggest you to take a different approach. There is a new version of Creator coming: V 3.2

                     

                  Right now you can take the chance of a beta testing. Download and install Creator 3.2 Early access

                     

                  There you can find an RTC component for PSoC4. Additionally you will find an RTC example for PSoC4 (Watch: one example is for PSoC4, one is for PSoC4 BLE)

                     

                  What you need now is to build an I2C connection to your ds1307 and update the RTC with the chip's time & date.

                     

                   

                     

                  Bob

                  • 6. Re: LCD with ds1307
                    user_385543602

                     In re the RTC component for the PSOC 4, is there any way to back up the time with a battery?  I cannot find anything in the datasheet.  If this is not possible, this component is only useful as a second timer/ alarm, and not really as a clock.

                       

                    Let me know if I am missing something.

                       

                    Thank you,

                       

                    Tom