 |
 |
| View previous topic :: View next topic |
| Author |
Message |
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Sat May 12, 2012 2:39 pm |
|
|
Hi,
Yes, there are a couple of things you can do. First, test the variable you are about to display against the existing value, and only write to the display if it's different. That will stop the display from flickering. Some 'Pseudocode' here:
| Code: |
While(1)
{
Temp = GetTemp();
If (Temp != OldTemp)
GDispPixFontAt(80, 1, c, 1, black);
OldTemp = Temp
delay_ms(1000);
}
|
You must also modify the GDispPixFontAt routine to explicitly turn OFF unused pixels in addition to turning ON used pixels. Study this routine, and you should see what is required!
Another solution, but not as nice, is to erase the variable on the screen before writing the new data. Do this by rewriting the old variable with the color parameter in the function call set to 'white', before writing the new data with this parameter set to 'black'.
John |
|
 |
adrix
Joined: 04 May 2012 Posts: 24
|
|
Posted: Sat May 12, 2012 3:49 pm |
|
|
Thanks for the help. I managed to clear the flickering here's my code:
| Code: | While(1)
{
temperature1 = ds1820_read();
sprintf(temp1, "Temperature: %.2f", temperature1);
If (temp != temp1)
GDispPixFontAt(80, 1, temp1, 1, black);
delay_ms(100);
} |
I tried to put GDispPixFontAt(80, 1, temp, 1, white) line before GDispPixFontAt(80, 1, temp1, 1, black), but it would still print the new pixels on old ones. Regarding the "cleaner" way, I tried to understand the code, but I can't think of the way to correctly edit GDispPixFontAt, everything just confuses me
| Code: | void GDispPixFontAt(unsigned int16 X, unsigned int16 Y, unsigned char* textptr, unsigned char size, int1 color)
{
const BYTE bytes_per_char = 5;
int i, j, k, l, m; // Loop counters
BYTE pixelData[bytes_per_char]; // Stores character data
for(i=0; textptr[i] != '\0'; ++i, ++X) // Loop through the passed string
{
if(textptr[i] < 'S') // Checks if the letter is in the first or second array
memcpy(pixelData, FONT1[textptr[i]-' '], bytes_per_char);
else if(textptr[i] <= '~') // Check if the letter is in the second array
memcpy(pixelData, FONT2[textptr[i]-'S'], bytes_per_char);
else // Default to space if character out of range
memcpy(pixelData, FONT1[0], bytes_per_char);
if(X+5*size >= MAX_COL_PIXEL) // Performs character wrapping
{
X = 0; // Set X at far left position
Y += 7*size + 1; // Set Y at next position down
}
for(j=0; j<bytes_per_char; ++j, X+=size) // 5 bytes per character
{
for(k=0; k<7*size; ++k) // Loop through the vertical pixels
{
if(bit_test(pixelData[j], k)) // Check if the pixel should be set
{
for(l=0; l<size; ++l) // The next two loops change the character's size
{
for(m=0; m<size; ++m)
{ // Draws the pixel
GDispSetPixel(X+m, Y+k*size+l, color);
}
}
}
}
}
} //for(i = 0; textptr[i] != '\0';...)
}
|
|
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat May 12, 2012 6:04 pm |
|
|
| Quote: | While(1)
{
temperature1 = ds1820_read();
sprintf(temp1, "Temperature: %.2f", temperature1);
If (temp != temp1)
GDispPixFontAt(80, 1, temp1, 1, black);
delay_ms(100);
} |
Right here, it looks like you are trying to compare the contents of
two arrays by testing for inequality of the addresses of the arrays.
That won't work in C. The code above is not doing what you think it is. |
|
 |
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Sat May 12, 2012 6:09 pm |
|
|
Hi,
It's important to understand how a character is generated on a GLCD display. Once you understand that, you can easily modify the code to do what you want. I answered exactly this question within the last month or so, so you should be able to find it. I laid out exactly how 5 bytes of data are used to define a 5x7 character, and (hopefully) how to modify the routine you posted to explicitly turn ON needed pixels, and explicitly turn OFF unneeded pixels. This modification will solve the problem you are having.
Here is a hint. This line of the routine is where you should start looking:
| Code: |
if(bit_test(pixelData[j], k)) // Check if the pixel should be set
|
John |
|
 |
adrix
Joined: 04 May 2012 Posts: 24
|
|
Posted: Sun May 13, 2012 4:45 am |
|
|
| ezflyr wrote: | Hi,
It's important to understand how a character is generated on a GLCD display. Once you understand that, you can easily modify the code to do what you want. I answered exactly this question within the last month or so, so you should be able to find it. I laid out exactly how 5 bytes of data are used to define a 5x7 character, and (hopefully) how to modify the routine you posted to explicitly turn ON needed pixels, and explicitly turn OFF unneeded pixels. This modification will solve the problem you are having.
Here is a hint. This line of the routine is where you should start looking:
| Code: |
if(bit_test(pixelData[j], k)) // Check if the pixel should be set
|
John |
I made it work. Thanks for the hint, it was a big help. |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|