PSoC 4 Real-Time Clock

Discussion in 'Embedded Systems and Microcontrollers' started by abhimanyu143, Sep 8, 2015.

  1. abhimanyu143

    Thread Starter Member

    Aug 25, 2014
    211
    1
    Hello

    frustrated, I need help in Programming . I have psoc 4200 device. when I burn below code. I see the current time and date on LCD
    Code (Text):
    1. */
    2. #include <project.h>
    3. #include <stdio.h>
    4.  
    5. /* Time: 02:59:50 */
    6. #define TIME_HOUR           (0x23u)
    7. #define TIME_MIN            (0x59u)
    8. #define TIME_SEC            (0x55u)
    9. #define TIME_HR_MIN_SEC     ((uint32)(TIME_HOUR << RTC_HOURS_OFFSET) | \
    10.                             (uint32)(TIME_MIN << RTC_MINUTES_OFFSET)    | \
    11.                              TIME_SEC)
    12.  
    13.  
    14.                        
    15. /* Date: 03/22/2016 */
    16. #define DATE_MONTH          (RTC_MARCH)
    17. #define DATE_DAY            (0x22u)
    18. #define DATE_YEAR           (0x2016u)
    19. #define DATE_MONTH_DAY_YEAR ((uint32)(DATE_MONTH << RTC_MONTH_OFFSET)   | \
    20.                             (uint32)(DATE_DAY << RTC_DAY_OFFSET)        | \
    21.                              DATE_YEAR)  
    22.  
    23. #define SYSTICK_EACH_10_HZ  (10u)
    24. #define SYSTICK_RELOAD      (CYDEV_BCLK__SYSCLK__HZ / SYSTICK_EACH_10_HZ)
    25.  
    26. /* Interrupt prototype */
    27. CY_ISR_PROTO(SysTickIsrHandler);
    28.  
    29.  
    30. int main()
    31. {
    32.     /* Place your initialization/startup code here (e.g. MyInst_Start()) */
    33.     char timeBuffer[16u];
    34.     char dateBuffer[16u];
    35.  
    36.     uint32 time;
    37.     uint32 date;
    38.     uint32 i;
    39.  
    40.     /* Starts SysTick component */
    41.     CySysTickStart();
    42.  
    43.     /* Configure SysTick timer to generate interrupt every 100 ms */
    44.     CySysTickSetReload(SYSTICK_RELOAD);
    45.  
    46.     /* Find unused callback slot. */
    47.     for (i = 0u; i < CY_SYS_SYST_NUM_OF_CALLBACKS; ++i)
    48.     {
    49.         if (CySysTickGetCallback(i) == NULL)
    50.         {
    51.             /* Set callback */
    52.             CySysTickSetCallback(i, SysTickIsrHandler);
    53.             break;
    54.         }
    55.     }
    56.  
    57.     /* Starts RTC component */
    58.     RTC_Start();
    59.     /* Start LCD */
    60.  
    61.     LCD_Start();
    62.  
    63.     /* Set Date and Time */
    64.     RTC_SetDateAndTime(TIME_HR_MIN_SEC,DATE_MONTH_DAY_YEAR);
    65.  
    66.  
    67.  
    68.  
    69.  
    70.     /* Set RTC time update period */
    71.     RTC_SetPeriod(1u, SYSTICK_EACH_10_HZ);
    72.  
    73.     /* Enable global interrupts */
    74.     CyGlobalIntEnable;
    75.  
    76.  
    77.  
    78.     while(1)
    79.     {
    80.         /* Get Date and Time from RTC */
    81.         time = RTC_GetTime();
    82.         date = RTC_GetDate();
    83.  
    84.         /* Print Date and Time to LCD */
    85.         sprintf(timeBuffer, "%02lu:%02lu:%02lu", RTC_GetHours(time), RTC_GetMinutes(time), RTC_GetSecond(time));
    86.         sprintf(dateBuffer, "%02lu/%02lu/%02lu", RTC_GetMonth(date), RTC_GetDay(date), RTC_GetYear(date));
    87.    
    88.         LCD_Position( 0u, 2u);
    89.         LCD_PrintString(timeBuffer);
    90.         LCD_Position( 1u, 2u );
    91.         LCD_PrintString(dateBuffer);
    92.    
    93.  
    94.         CyDelay(200u);
    95.     }
    96. }
    97.  
    98.  
    99.    
    100.     void SysTickIsrHandler(void)
    101. {
    102.     RTC_Update();
    103. }
    104.  
    105.  
    please look datasheet. there is API RTC_GetDateAndTime(), how to use this API in my code to see current time and date on LCD
     
    Last edited: Sep 8, 2015
  2. jayanthd

    Member

    Jul 4, 2015
    274
    29
Loading...