0% found this document useful (0 votes)
15 views3 pages

Memory LCD Timer Display Code

Uploaded by

Minh Thư
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

Memory LCD Timer Display Code

Uploaded by

Minh Thư
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

/*

* lcd.c
*
* Created on: Nov 4, 2024
* Author: Phat_Dang
*/
#include <stdio.h>

#include "sl_board_control.h"
#include "em_assert.h"
#include "glib.h"
#include "dmd.h"

#ifndef LCD_MAX_LINES
#define LCD_MAX_LINES 11
#endif

/*******************************************************************************
*************************** LOCAL VARIABLES ********************************
******************************************************************************/
static GLIB_Context_t glibContext;
static int currentLine = 0;

/*******************************************************************************
************************** GLOBAL FUNCTIONS *******************************
******************************************************************************/

/***************************************************************************//**
* Initialize example.
******************************************************************************/
void memlcd_app_init(void)
{
uint32_t status;

/* Enable the memory lcd */


status = sl_board_enable_display();
EFM_ASSERT(status == SL_STATUS_OK);

/* Initialize the DMD support for memory lcd display */


status = DMD_init(0);
EFM_ASSERT(status == DMD_OK);

/* Initialize the glib context */


status = GLIB_contextInit(&glibContext);
EFM_ASSERT(status == GLIB_OK);

glibContext.backgroundColor = White;
glibContext.foregroundColor = Black;

/* Fill lcd with background color */


GLIB_clear(&glibContext);
unsigned int second = 0;
unsigned int minute = 0;
unsigned int hour = 0;
/* Use Narrow font */
GLIB_setFont(&glibContext, (GLIB_Font_t *) &GLIB_FontNormal8x8);
for (int i = 0; i < 3661; i++){
if(second == 60){
minute++; second = 0;
}
if(minute == 60){
hour++; minute=0;
}
char time_str[9];

// Convert hour
time_str[0] = (hour / 10) + '0'; // Tens place
time_str[1] = (hour % 10) + '0'; // Ones place
time_str[2] = ':'; // Separator

// Convert minute
time_str[3] = (minute / 10) + '0'; // Tens place
time_str[4] = (minute % 10) + '0'; // Ones place
time_str[5] = ':'; // Separator

// Convert second
time_str[6] = (second / 10) + '0'; // Tens place
time_str[7] = (second % 10) + '0'; // Ones place
time_str[8] = '\0'; // Null-terminate the string

/* Draw text on the memory lcd display*/

GLIB_drawStringOnLine(&glibContext,
"Dong Ho ",
currentLine,
GLIB_ALIGN_LEFT,
5,
5,
true);
GLIB_drawStringOnLine(&glibContext,
"FETEL-HCMUS",
currentLine+1,
GLIB_ALIGN_LEFT,
5,
5,
true);

GLIB_drawStringOnLine(&glibContext,
time_str,
currentLine+3,
GLIB_ALIGN_LEFT,
5,
5,
true);
DMD_updateDisplay();
second++;
sl_sleeptimer_delay_millisecond(1000);
}
}

/***************************************************************************//**
* Ticking function.
******************************************************************************/
void memlcd_app_process_action(void)
{
return;
}

You might also like