Is there any way to display RTC (real-time clock) on a LCD without the LCD "flickering"?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Is there any way to display RTC (real-time clock) on a LCD without the LCD "flickering"?

Jump to solution
2,228 Views
admin
Specialist II

Hi. I'm able to display a RTC (real-time clock) on my LCD. The function I'm using to do this is called "clock()" for this case. However, the LCD screen flickers randomly due to the clock() function being inside an infinite loop as shown below.

 

for(;; )

{

    clock();

}

 

If I don't put the clock() into an infinite loop, the RTC on the LCD screen will never count up because the RTC will only be read once. Help is appreciated. Thx

Message Edited by Cryptical on 2009-03-17 09:38 AM
Message Edited by Cryptical on 2009-03-17 09:41 AM
Labels (1)
Tags (1)
0 Kudos
1 Solution
734 Views
stanish
NXP Employee
NXP Employee

Cryptical,

 

I assume the clock() function reads the RTC and updates LCD display.

In order to avoid screen flickers you shouldn't update the LCD display in the infinite loop.

You can e.g. update the LCD only in case the second couter changes:

 

unsingned char sec, sec_old=0;

 

for(;; )

{

   sec = clock();

   if (sec != sec_old)

   {

     UpdateLCD();

     sec_old = sec;

   }

}

 

Stanish

View solution in original post

0 Kudos
4 Replies
735 Views
stanish
NXP Employee
NXP Employee

Cryptical,

 

I assume the clock() function reads the RTC and updates LCD display.

In order to avoid screen flickers you shouldn't update the LCD display in the infinite loop.

You can e.g. update the LCD only in case the second couter changes:

 

unsingned char sec, sec_old=0;

 

for(;; )

{

   sec = clock();

   if (sec != sec_old)

   {

     UpdateLCD();

     sec_old = sec;

   }

}

 

Stanish

0 Kudos
734 Views
admin
Specialist II

stanish wrote:

Cryptical,

 

I assume the clock() function reads the RTC and updates LCD display.

In order to avoid screen flickers you shouldn't update the LCD display in the infinite loop.

You can e.g. update the LCD only in case the second couter changes:


 

Thx for the help stanish. I followed your advice and only updated the LCD when the second counter incremented by 1. The flickering reduced significantly! :smileyhappy:

0 Kudos
734 Views
nonarKitten
Contributor II

An additional option is to use a buffer; make all your changes and only update the parts of the buffer that have changed. Most LCDs should allw either setting the row/column or address, so in you loop you'd have something like this:

 

// lcdBuffer is shared (e.g., "public"unsigned char lcdBuffer[COLUMNS][ROWS];// printf redirects to display chars to the bufferprintf_toLcd("blablah");//...// this function will copy the contents of// lcdBuffer into lcdDisplay; and changes will// be copied to the LCD controllervoid updateLcd(void) {  // lcdDisplay is private and should not be used directly  static unsigned char lcdDisplay[COLUMNS][ROWS];  int nextx; x, y;  for(y=0;y<ROWS;y++) {    nextx=-1;    x=0;    do {      // check if the buffer and display are different      if(lcdBuffer[x][y]!=lcdDisplay[x][y]) {        if(nextx!=x) {          // if we're not immediately after the last          // position, we need to reset our cursor          // this takes advanatge of most LCD's ability          // to autoincrement when writing          lcdSetCursor(x,y);        }        // write the data to LCD        lcdWriteData(lcdBuffer[x][y]);        // update our display buffer        lcdDisplay[x][y]=lcdBuffer[x][y];        // and keep track of our next position        nextx = ++x;      }    } while(x!=COLUMNS);  }}

 

Message Edited by nonarKitten on 2009-06-26 05:37 PM
734 Views
little_egg_tart
Contributor I

Hello there!

I am also doing a similar project but I have no idea how to write the code for the clock function. How to implement Real-Time clock?

 

little.eggtart

0 Kudos