CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

16x2 LCD displaying multiple data values

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
msananthu



Joined: 20 Sep 2013
Posts: 2
Location: Bangalore

View user's profile Send private message

16x2 LCD displaying multiple data values
PostPosted: Fri Sep 20, 2013 6:12 am     Reply with quote

Hi,


I have an issue with displaying multiple values on the 2nd line of 16x2 LCD. There are 4 channels of ADC which I am using to read the values & display it on LCD. The reading from the ADC is fine, but displaying it in a scroll manner only on the 2nd line is an issue. My first Line is also scrolling.

This is the code i wrote to print the ADC value on the LCD, but sometimes values mix up between 1st & 2nd line, 2 values get overwritten on the same location. Can anybody suggest which is the best way to write multiple values only in the 2nd line which is going back to back.

Code:
void main() {
...
pic_init();
lcd_init();
...
lcd_putc(" GUI SYSTEM \n")

while(1) {
  ...
   current = average_ad(AMP_CHAN)/40.885;                   
   printf(lcd_putc," Solar Current=%6.2fA\n\r",current);

   voltage = average_ad(VOLT_CHAN)/18.2887;             
   lcd_gotoxy(22,2);
   printf(lcd_putc," Solar Voltage=%6.2fV\n\r",voltage);

}


I am using lcd_gotoxy() for moving between the lines. The first line would always display "GUI SYSTEM", while in the 2nd line I need to display 4 different values in a scrolling manner namely

a. Solar Voltage
b. Solar Current
c. Battery Voltage
d. Battery Current

As the 16x2 JHD controller is only 40 characters wide, how can we over come this situation ? I tried with only 2 values of Solar Voltage & Solar Current with the help of lcd_gotoxy(), it works fine but when the 3rd value needs to be displayed, the display is all wrong,
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Fri Sep 20, 2013 6:30 am     Reply with quote

Hi,

So, let me get this straight, your '16x2' LCD is 40 characters wide??? Let me guess, it's also 4 rows tall, right???

'Normally', a character LCD is described in terms of its width times its height. Thus a '16x2' LCD is 16 characters wide by 2 rows tall! It sounds
like you have something else!

If you are going to explicitly position the text on the LCD then you probably don't want to be appending the '\n\r' to your printf statements. You should
also post the full block of code that prints the 4 desired values.

Also, you don't show or tell us which LCD driver you are using. They all have some subtle differences.

John
msananthu



Joined: 20 Sep 2013
Posts: 2
Location: Bangalore

View user's profile Send private message

PostPosted: Fri Sep 20, 2013 10:12 am     Reply with quote

John

I take back 40 characters as it was spelt in a wrong way. It is a 16x2 LCD display.

Let me provide more info on this

Controller : PIC 16F877A
Compiler : CCS C Compiler
LCD : 16x2 Hitachi LCD
LCD Driver : lcd flex_driver

I have provided the code which prints all the 4 values. I call this read_data in the main(). How would you suggest to modify this piece of code to scroll left on the 2nd line in the LCD.

Code:
void read_data(void) {
 
  sol_amps =  ((average_adc(SOL_AMPS_CHAN)  * SOL_AMPS_SCALE) + 5) / 10;    //input of solar amps result scaled by 100
  printf(lcd_putc," SOLAR AMPS:%.2fA\n ",sol_amps);
  sol_volts = ((average_adc(SOL_VOLTS_CHAN) * SOL_VOLTS_SCALE) + 5) / 10;   //input of solar volts result scaled by 100
  lcd_gotoxy(20,2);
  printf(lcd_putc," SOLAR VOLTAGE:%.2fV\n ",sol_volts);
  bat_volts = ((average_adc(BAT_VOLTS_CHAN) * BAT_VOLTS_SCALE) + 5) / 10;   //input of battery volts result scaled by 100
  //lcd_gotoxy(35,2);
  //printf(lcd_putc," BATTERY VOLTAGE:%.2fV\n ",bat_volts); // If this printf is included then the LCD display goes all bad.
  sol_watts = (int)((((long)sol_amps * (long)sol_volts) + 50) / 100);    //calculations of solar watts scaled by 10000 divide by 100 to get scaled by 100 
 //lcd_gotoxy(50,2);
//printf(lcd_putc,"SOLAR WATTS:%.2fW",sol_watts);               
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19447

View user's profile Send private message

PostPosted: Fri Sep 20, 2013 11:20 am     Reply with quote

You can't actually scroll a single line in the LCD. To do this, you have to send 'scrolling data'.

For a simple demo, ignore the values for a moment:
Code:

void rotate_16string(char * str)
{
    char temp;
    temp=str[15];
    memmove(str+1,str,15);
    str[0]=temp;
}


//Then in the main
    char line_buffer[17];
    char second_line[]="Second line";
    int8 ctr;
    while (TRUE)
    {
        memset(line_buffer,0x20,16);
        line_buffer[16]=0;
        sprintf(line_buffer,"%16s", second_line); //Max 16 characters

        lcd_gotoxy(1,1);
        printf(lcd_printf,"First line  ");
   
        for (ctr=0;ctr<16;ctr++)
        {
            lcd_gotoxy(1,2);
            printf(lcd_printf,"%s",line_buffer);
            delay_ms(250);
            rotate_16string(line_buffer);
        }
    }


As as already been pointed out you don't want the line feeds anywhere.
You move to where you want the text, and just display what is needed. In this case a 16 character string, which you rotate to give the 'scroll'.

Trying to print to the 20th character on a 16 character line?....
Think about it.

Best Wishes


Last edited by Ttelmah on Sat Sep 21, 2013 12:42 am; edited 1 time in total
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Fri Sep 20, 2013 11:44 am     Reply with quote

Hi,

Sorry, I was under the impression that your display was much larger, and that you were trying to display text/data statically, and that 'scrolling' was
an undesired effect. It seems that you are trying to fit a lot of text/data onto a small display by scrolling the text/data.... If so, I think this is a poor idea
as scrolling text can be difficult to read, and that's not what you want for
important data!

If you are locked into such a small display, you can scroll text on the LCD using a routine like this:

Code:


char message[21] = "Digital multimeter  ";
   int8 ctr;
   for (ctr=0;ctr<19;ctr++) {
       lcd_gotoxy(1,2);
       printf(lcd_putc,"%s",message+ctr);
       delay_ms(100);
   }


You'll need to assemble your text and data into message arrays that are then scrolled across the display. I'll leave that as an exercise for you!

John
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sat Sep 21, 2013 3:04 am     Reply with quote

Your code for prinitng differs from what you declared in the original post.
That aside, what you are trying to do is unecessarily complex.

Why not simply print each of you four parameters on the second line in turn?
OK. You have to wait to read all four values. That's also the case with your scrolling scheme.

If you must scroll:-

1) Print all four lines into a 64 char array. You then rotate the data in the array as you print only the first 16 chars to the second line of the display. The problem then is updating the data.

OR

2) Print to an 80 char array, with the first line at both the start and end of the array. You then print 16 chars to the LCD second line, starting at char[0] through to char[64].

OR

3) Do as (2) with only 64 char array. Uses less space, but presents a wrap round issue.

Mike
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Sat Sep 21, 2013 3:59 am     Reply with quote

Another obvious approach if there is more data than fits the LCD is to use a timer. The timer displays one LCD page image ( lines) then time elapses and the image (lines) of the next page is displayed.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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