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
please look datasheet. there is API RTC_GetDateAndTime(), how to use this API in my code to see current time and date on LCD
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:
*/
#include <project.h>
#include <stdio.h>
/* Time: 02:59:50 */
#define TIME_HOUR (0x23u)
#define TIME_MIN (0x59u)
#define TIME_SEC (0x55u)
#define TIME_HR_MIN_SEC ((uint32)(TIME_HOUR << RTC_HOURS_OFFSET) | \
(uint32)(TIME_MIN << RTC_MINUTES_OFFSET) | \
TIME_SEC)
/* Date: 03/22/2016 */
#define DATE_MONTH (RTC_MARCH)
#define DATE_DAY (0x22u)
#define DATE_YEAR (0x2016u)
#define DATE_MONTH_DAY_YEAR ((uint32)(DATE_MONTH << RTC_MONTH_OFFSET) | \
(uint32)(DATE_DAY << RTC_DAY_OFFSET) | \
DATE_YEAR)
#define SYSTICK_EACH_10_HZ (10u)
#define SYSTICK_RELOAD (CYDEV_BCLK__SYSCLK__HZ / SYSTICK_EACH_10_HZ)
/* Interrupt prototype */
CY_ISR_PROTO(SysTickIsrHandler);
int main()
{
/* Place your initialization/startup code here (e.g. MyInst_Start()) */
char timeBuffer[16u];
char dateBuffer[16u];
uint32 time;
uint32 date;
uint32 i;
/* Starts SysTick component */
CySysTickStart();
/* Configure SysTick timer to generate interrupt every 100 ms */
CySysTickSetReload(SYSTICK_RELOAD);
/* Find unused callback slot. */
for (i = 0u; i < CY_SYS_SYST_NUM_OF_CALLBACKS; ++i)
{
if (CySysTickGetCallback(i) == NULL)
{
/* Set callback */
CySysTickSetCallback(i, SysTickIsrHandler);
break;
}
}
/* Starts RTC component */
RTC_Start();
/* Start LCD */
LCD_Start();
/* Set Date and Time */
RTC_SetDateAndTime(TIME_HR_MIN_SEC,DATE_MONTH_DAY_YEAR);
/* Set RTC time update period */
RTC_SetPeriod(1u, SYSTICK_EACH_10_HZ);
/* Enable global interrupts */
CyGlobalIntEnable;
while(1)
{
/* Get Date and Time from RTC */
time = RTC_GetTime();
date = RTC_GetDate();
/* Print Date and Time to LCD */
sprintf(timeBuffer, "%02lu:%02lu:%02lu", RTC_GetHours(time), RTC_GetMinutes(time), RTC_GetSecond(time));
sprintf(dateBuffer, "%02lu/%02lu/%02lu", RTC_GetMonth(date), RTC_GetDay(date), RTC_GetYear(date));
LCD_Position( 0u, 2u);
LCD_PrintString(timeBuffer);
LCD_Position( 1u, 2u );
LCD_PrintString(dateBuffer);
CyDelay(200u);
}
}
void SysTickIsrHandler(void)
{
RTC_Update();
}
Attachments
-
203.3 KB Views: 3
Last edited: