sending a variable to lcd

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi,

i'm working with a lcd at the moment, so i can use it in other projects. i have figered out most of the functions, but for some reason i can't send variables to the lcd. only stuff like:

lcd_putsf("test");
delay_ms(200);

does anyone here know how to send a variable?? i searched on google, lots of forums (also here) but i can't find it.

i'm using a HD47780 competible lcd, code is in CodeVisionAVR and the Atmega16L is the processor.

thanks robbin[/code]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Something like:

char lcd_buffer[40];
sprintf(&lcd_buffer,"My variable is %i",variable);
lcd_putsf(lcd_buffer);

There are pointy haired bald people.
Time flies when you have a bad prescaler selected.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

what do i need to include to use sprinft, i get an error when using that function

//i found that one.

sprintf(&lcd_buffer,"My variable is %i",x); 
lcd_putsf(lcd_buffer);

i get 2 errors:
in the first code sentence i get: illega address,
second sentence: function parameter incompatible with it's declaration.

thanks for answering

Last Edited: Fri. Jan 4, 2008 - 01:54 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Posting your code would help. And always post the name of the errors you get. Try including stdio.h and stdlib.h . Sprintf is IIRC located there...

Oh, and RTFM: http://instruct1.cit.cornell.edu...

There are pointy haired bald people.
Time flies when you have a bad prescaler selected.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i was editing the my post :), i figured out that i need stdio.h.

i now have the errors mentioned above yours. do you know how i can fix that?

thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ah! Got it! Instead of

lcd_putsf(lcd_buffer);

use

lcd_puts(lcd_buffer);

putsf loads a constant string from the flash, say

lcd_putsf("This text will never change");

while lcd_puts can insert variable text.

There are pointy haired bald people.
Time flies when you have a bad prescaler selected.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

daqq wrote:
Something like:

char lcd_buffer[40];
sprintf(&lcd_buffer,"My variable is %i",variable);
lcd_putsf(lcd_buffer);

Sorry daqq. With CodeVision you have to distinguish between flash strings and SRAM strings.

So you use:

lcd_puts(lcd_buffer);   // because lcd_buffer is RAM
lcd_putsf("String in flash"); // because in FLASH  

But the principle is the same. Use sprintf() to convert your variable into a string, and send this string to your LCD.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ah, that helped alot :), for some reason i get also the error Illegal address when i use the sprintf:

x = 55;
sprintf(&lcd_buffer,"My variable is %d",x); 

i thought that it maybe was de %i, so i changed it into, %d, %f, %s, but none worked.

many thanks for your help

Robbin

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

oke i have it, i think it was a typo

sprintf(&lcd_buffer,"My variable is %d",x);

that doesn't belong there :P.

thanks for help

bye

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oops. I had not noticed the &lcd_buffer.

You should either do &lcd_buffer[0] or lcd_buffer.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your code was correct, Daqq had the type, but that doesn't matter, the problem is solved.

i combined the lcd with the ADC, i get some value's, but not the right once.

for 5v i get 255 (logic, cause it's 8bit)
for 0v i get 204...(not logic at all).

and when it's not connect i get value's from 0 to 6??.

here is the code:


#include 
#include 
#include   

// Alphanumeric LCD Module functions
#asm
   .equ __lcd_port=0x18 ;PORTB
#endasm
#include 

#define ADC_VREF_TYPE 0x20  

 char lcd_buffer[16];
 int x;  

// Read the 8 most significant bits
// of the AD conversion result
unsigned char read_adc(unsigned char adc_input)
{
ADMUX=adc_input|ADC_VREF_TYPE;
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCH;
}

// Declare your global variables here

void main(void)
{

  DDRB = 0xFF;                                      // We put port D pins in output mode  
  PORTB = 0xFF;                                     // we activate the internal pull-up 
  DDRD = 0xFF;                                      // We put port D pins in output mode  
  PORTD = 0xFF;                                     // we activate the internal pull-up 

// ADC initialization
// ADC Clock frequency: 115,000 kHz
// ADC Voltage Reference: AREF pin
// ADC Auto Trigger Source: Free Running
// Only the 8 most significant bits of
// the AD conversion result are used
ADMUX=ADC_VREF_TYPE;
ADCSRA=0xA5;
SFIOR&=0x1F;

// LCD module initialization
  delay_ms(30);	                                    // delay for lcd
  lcd_init(16);                                     // init for lcd
  lcd_clear();                                      // clean up screen
  
while (1)
      {
      x = read_adc(0x00);                           // x = ADCH
      sprintf(lcd_buffer,"Result: %i",x);           // convert the value to string
      lcd_puts(lcd_buffer);                         // make visible on lcd
      delay_ms(200);                                // delay to see chances
      lcd_gotoxy(0,0);                              // go to the first row/colum   
      
      if(PIND.1 ==0)                                // clean op lcd
          {
          lcd_clear();
          delay_ms(200);
          }
      };
}

hopefully we can get this working, would be nice :)