Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

128x64 GLCD sprintf problem PIC18F45K22

Status
Not open for further replies.

ahpan

New Member
Hi All,

I have been working on project in which I have to display the ADC value on GLCD. I have the GLCD library which is able to draw the bitmap image on display. What I am doing that storing the ADC result in prdefined variable.

GLCD has a four functions which is being used to print string on display.

PutMessage // print any string
PutChar // prints only sngle byte on Display,argv = ASCII equivalent
PutMessage32x20
PutChar32x20
Please refer below example the working of the above function.

Code:
PutMessage((rom char*) "hello world ") // Prints the hello world string 
 PutChar unsigned data char)) //where data is ASCII equivalent of desired characted wants to print

The other functions PutMessage32x20 and PutChar32x20 are not displaying anything on Display. I felt, there must be a problem with the function definition. Please if you could help to correct those functions would be really appreciated..

The snippet of main code for the program as below:

Code:
char adc_val [11];
 float V;
 ADCResult = ReadADC(); // Storing ADC output in ADCResult
 V= (ADCResult*5)/1024; // desired output 
 sprintf(adc_val,"%f ",V); // want to display  
 PutChar adc_val); //

I want to print the adc_val on the display using the sprintf , Am I using the correct function to print on display ? To be fair with you I am not an expert in C as you might had feel from my code and explanation of the code.

It would be very helpful if you help me with the GLCD library functions. Your suggestions are always welcome if is there any other way to print the output on display.
 
Please see the library I am using
 

Attachments

  • fonts_GLCD.txt
    6.6 KB · Views: 221
  • GLCD (3).c
    14.3 KB · Views: 283
That code is for the C18 compiler (I know because I wrote it!!) and C18 doesn't support FP in sprintf.

Mike.
 
Ah!! Mike.. At least its being put to some use.... ???

I think I'll write a decent float to ascii routine that I can post in my tutorials....

Mike.... On a side note I have just migrated from C18 to XC8 for free.... Now I have all pic10's, 16's and 18's... Good deal or what..
 
You don't need to float to ascii, for that job anyway.

Instead of *5v /1024 you can do *500 /1024, and now the result will be in volts*100, so a ADC reading of 4v will come out as a result of 400.

Then it's just a display text formatting issue, adding a decimal point and moving the last 2 chars;
400 -> 4.00
 
You don't need to float to ascii, for that job anyway.

Instead of *5v /1024 you can do *500 /1024, and now the result will be in volts*100, so a ADC reading of 4v will come out as a result of 400.

Then it's just a display text formatting issue, adding a decimal point and moving the last 2 chars;
400 -> 4.00


I know he doesn't... But this comes up time and time again.... I wrote a small simple ftoa... Only to find out that it was almost exactly the same as ftoa() in the maths library...
 
GLCD Library... What GLCD library... You'll have to find some code on the net..

The printing of a float has nothing to do with the GLCD coding..

Just write this
Code:
V= (ADCResult*5)/1024; // desired output 
sprintf(adc_val,"%s ", ftoa(V)); // want to display .

Or do what roman has shown you...
 
Hi All,

I have been working on project in which I have to display the ADC value on GLCD. I have the GLCD library which is able to draw the bitmap image on display. What I am doing that storing the ADC result in prdefined variable.

GLCD has a four functions which is being used to print string on display.

PutMessage // print any string
PutChar // prints only sngle byte on Display,argv = ASCII equivalent
PutMessage32x20
PutChar32x20
Please refer below example the working of the above function.

Code:
PutMessage((rom char*) "hello world ") // Prints the hello world string 
 PutChar unsigned data char)) //where data is ASCII equivalent of desired characted wants to print

The other functions PutMessage32x20 and PutChar32x20 are not displaying anything on Display. I felt, there must be a problem with the function definition. Please if you could help to correct those functions would be really appreciated..

The snippet of main code for the program as below:

Code:
char adc_val [11];
 float V;
 ADCResult = ReadADC(); // Storing ADC output in ADCResult
 V= (ADCResult*5)/1024; // desired output 
 sprintf(adc_val,"%f ",V); // want to display  
 PutChar adc_val); //

I want to print the adc_val on the display using the sprintf , Am I using the correct function to print on display ? To be fair with you I am not an expert in C as you might had feel from my code and explanation of the code.

It would be very helpful if you help me with the GLCD library functions. Your suggestions are always welcome if is there any other way to print the output on display.

two things...
1. I'm using the C30 compiler, but here's what worked for me:

double V; // compiler asked for type "double"

char adc_val [11];
V = (float)(2000*5)/1024; // I used a arbitrary value here. For this example
// the math output is typed to "float", otherwise
// the value is rounded.

sprintf(adc_val,"%f", V); // adc_val = 9.765625

2. maybe its obvious but in your code snippet:

// PutChar adc_val); // <---missing open parenth
PutChar (adc_val); //

eT
 
Thanks to all of you.

Still i am struggling to display the value on GLCD. I have used PutChar but it is printing a garbage value.

I am really stuck now. Please help me.

Help is appreciated.

Cheers
 
Thanks to all of you.

Still i am struggling to display the value on GLCD. I have used PutChar but it is printing a garbage value.

I am really stuck now. Please help me.

Help is appreciated.

Cheers

So...can you give specifics?

Where is the garbage present? In a variable? On LCD?

eT
 
Many Thanks for all of your valuable response.

I have attached my code.

Cheers
 

Attachments

  • ADC.rar
    72.6 KB · Views: 177
@eTech

Garbage values Iam getting on the LCD but when I debug I can see the values in the variable assigned to store the ADC value.

@Ian
PIC18F45K22
 
eTech,

I have attached all the files related to project.

Cheers
 

Attachments

  • fonts_GLCD.h
    6.6 KB · Views: 261
  • GLCD.c
    14.4 KB · Views: 223
  • GLCD.h
    1.6 KB · Views: 231
  • image_logo.h
    54.7 KB · Views: 198
  • main.c
    6.2 KB · Views: 306
  • sys_init.c
    2.1 KB · Views: 282
  • sys_init.h
    24 bytes · Views: 203
Putmessage is casting a rom char*... The message is already a const rom char* so it isn't needed... Saying that it should still chuck out the message.

I noticed you have four ftoa routines..... You have included the math.h... There is already a good one in there...

Putchar only outputs ONE character...

you need to ..

Code:
char* str;

ftoa(V,str);

while(*str++ !=0)
   putchar(*str);
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top