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

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

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

跳至解决方案
3,466 次查看
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
标签 (1)
标记 (1)
0 项奖励
回复
1 解答
1,972 次查看
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 项奖励
回复
4 回复数
1,973 次查看
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 项奖励
回复
1,972 次查看
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 项奖励
回复
1,972 次查看
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
1,972 次查看
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 项奖励
回复