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
Solved! Go to Solution.
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
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
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!
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); }}
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