|
|
View previous topic :: View next topic |
Author |
Message |
The Puma
Joined: 23 Apr 2004 Posts: 227 Location: The Netherlands
|
Question about glcd_text57 routine |
Posted: Fri Nov 23, 2007 1:23 pm |
|
|
I want do the following, but this did't work, why???
Code: |
char info_text[];
glcd_text57(20,25,sprintf(info_text,"%04.3fv %4LU Value",volts,adc_value),2,ON) |
The following works.
Is there a method to get it to work??
Code: | sprintf(info_text,"%04.3fv %4LU Value",volts,adc_value);
glcd_text57(20,25,info_text,2,ON);
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Nov 23, 2007 1:34 pm |
|
|
Look at the function definition for glcd_text57() in the GLCD.c file.
What does it expect as the 3rd parameter ?
Quote: |
void glcd_text57(int x, int y, char* textptr, int size, int1 color)
|
Look at the function definition for sprintf() in the CCS manual.
What does it return ?
Quote: |
SPRINTF( )
Syntax: sprintf(string, cstring, values...);
Parameters: string is an array of characters.
cstring is a constant string or an array of characters null terminated.
Values are a list of variables separated by commas.
Returns: Nothing |
|
|
|
The Puma
Joined: 23 Apr 2004 Posts: 227 Location: The Netherlands
|
|
Posted: Fri Nov 23, 2007 2:30 pm |
|
|
Ok, thats is clear.
Is there another way to do that? (return a string to glcd_text57)
Like the charaterlcd method with lcd_putc or so? |
|
|
Dimlow Guest
|
|
Posted: Sat Nov 24, 2007 3:22 am |
|
|
Yes, there is another way . i redirect the output of printf with your own putc routine. here is the code i use.
Code: |
#ifndef GLCD_PUTC_FOR_PRINTF
#define GLCD_PUTC_FOR_PRINTF
#define GLCD_PUTC_LCD_WIDTH 128
#define GLCD_PUTC_LCD_HEIGHT 64
#define GLCD_PUTC_CHARWIDTH 5+1
#define GLCD_PUTC_CHARHEIGHT 7+1
int glcd_putc_x=0,glcd_putc_y=0;
char glcd_putc_text[2]=" ";
void glcd_putc (char c)
{
switch(c)
{
case '\n' : {
glcd_putc_x=0;
glcd_putc_y+=GLCD_PUTC_CHARHEIGHT;
break;
}
default : {
*glcd_putc_text=c;
glcd_text57(glcd_putc_x,glcd_putc_y,glcd_putc_text,1,1);
glcd_putc_x+=GLCD_PUTC_CHARWIDTH;
break;
}
}
if(glcd_putc_x>=GLCD_PUTC_LCD_WIDTH-GLCD_PUTC_CHARWIDTH) {glcd_putc_x=0;glcd_putc_y+=GLCD_PUTC_CHARHEIGHT;}
if(glcd_putc_y>=GLCD_PUTC_LCD_HEIGHT) glcd_putc_y=0;
}
#endif |
use it like this
Code: | printf(glcd_putc,"Hello World");
|
it does not handle many control character, you will have to code that yourself
Hope that helps
Gary[/code] |
|
|
The Puma
Joined: 23 Apr 2004 Posts: 227 Location: The Netherlands
|
|
Posted: Sat Nov 24, 2007 3:29 am |
|
|
Ok, thanks i will try
The glcd_text57 did not clear unused pixels
Then you must always clear area when updated value comes,
this gives flickering
Is it possible to change the glcd_text57 routine to do that
maybe someone has already change it
Code: | void main() {
long int adc_value;
float volts;
char text[];
setup_adc_ports(AN0|VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL|ADC_TAD_MUL_20);
set_adc_channel(0);
glcd_init(ON);
sprintf(text,"PIC18 10-bits ADC Sampling Ch AN0:");
glcd_text57(5,10,text,1,ON);
while(TRUE) {
delay_ms(1000);
adc_value=read_adc();
volts=(float)(adc_value*5)/1023.0;
sprintf(text,"%04.3fv %4LU Value",volts,adc_value);
glcd_text57(5,50,text,2,ON);
}
} |
The code sprintf(text,"%04.3fv %4LU Value",volts,adc_value) overwrite only the new values (volts and adv_value) and is unreadeble
Is there an solution? |
|
|
Dimlow Guest
|
|
Posted: Sat Nov 24, 2007 3:39 am |
|
|
Well i wrote that routine last week so i don't think anyone has already done it with my code. But I'm sure if you work hard enough at it you can do it.
If you get stuck i will help out. As I'm sure i will useone day.
Gary |
|
|
Dimlow Guest
|
|
Posted: Sat Nov 24, 2007 3:43 am |
|
|
what you will have to do is store that old values, then when you come to print the new one , erase the old value with glcd_text57(5,50,text,2,OFF); then print the new values, etc.
Gary |
|
|
The Puma
Joined: 23 Apr 2004 Posts: 227 Location: The Netherlands
|
|
Posted: Sat Nov 24, 2007 4:00 am |
|
|
I change it to this
Code: | delay_ms(1000);
adc_value=read_adc();
volts=(float)(adc_value*5)/1023.0;
sprintf(text,"%04.3fv %4LU Value",volts,adc_value);
glcd_text57(5,50,text,2,OFF);
delay_ms(1);
glcd_text57(5,50,text,2,ON); |
But this overwrite the new values |
|
|
Dimlow
Joined: 24 Nov 2007 Posts: 9
|
|
Posted: Sat Nov 24, 2007 4:13 am |
|
|
try something like this
Code: |
adc_value=read_adc();
volts=(float)(adc_value*5)/1023.0;
sprintf(text,"%04.3fv %4LU Value",old_volts,old_adc_value);
glcd_text57(5,50,text,2,OFF);
sprintf(text,"%04.3fv %4LU Value",volts,adc_value);
glcd_text57(5,50,text,2,ON);
old_volts=volts;old_adc_value=adc_value;
delay_ms(100);
|
Gary |
|
|
The Puma
Joined: 23 Apr 2004 Posts: 227 Location: The Netherlands
|
|
Posted: Sat Nov 24, 2007 6:24 am |
|
|
This works
Code: |
delay_ms(1000);
glcd_text57(5,50,text,2,OFF);
adc_value=read_adc();
volts=(float)(adc_value*5)/1023.0;
sprintf(text,"%04.3fv %4LU Value",volts,adc_value);
glcd_text57(5,50,text,2,ON);
|
|
|
|
Dimlow
Joined: 24 Nov 2007 Posts: 9
|
|
Posted: Sat Nov 24, 2007 7:05 am |
|
|
Yep will do, i was assuming you would reuse the text variable for other texts.
Gary |
|
|
MegatroniC
Joined: 08 Dec 2009 Posts: 35
|
|
Posted: Thu Mar 15, 2012 8:40 am |
|
|
Hello
excuse me, that lift so old topic ...
My test code, pic18f4620 and TG12864D0 (KS0108):
Code: | void main() {
long int adc_value, old_adc_value;
float volts;
char text[20];
char time[9];
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_INTERNAL|ADC_TAD_MUL_16);
set_adc_channel(0);
porta=0;
trisa=0x3F;
glcd_init(ON);
delay_ms(200);
sprintf(text,"Voltage: ACD:");
glcd_text57(0,10,text,1,ON);
sprintf(text,"Time is:");
glcd_text57(0,30,text,1,ON);
while(TRUE) {
adc_value=read_adc();
volts=(float)(adc_value*5)/1023.0;
if(adc_value != old_adc_value){
old_adc_value=adc_value;
glcd_text57(0,20,text,1,OFF);
sprintf(text,"%04.3fv %4LU units",volts,adc_value);
glcd_text57(0,20,text,1,ON);
}
ds1307_get_time(hrs,min,sec);
if(sec != old_sec){
old_sec=sec;
glcd_text57(0,40,time,1,OFF);
sprintf(time,"%02d:%02d:%02d" hrs,min,sec);
glcd_text57(0,40,time,1,ON);
}
}
} |
When change the time value does not flicker, this code works perfectly.
But when changing the voltage, value on the display flickers.
How to prevent this flickering? |
|
|
|
|
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
|