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 CCS Technical Support

are there any easy way to do this LCD work

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



Joined: 16 Mar 2011
Posts: 10
Location: US

View user's profile Send private message

are there any easy way to do this LCD work
PostPosted: Mon May 16, 2011 3:22 am     Reply with quote

hello
I want to move the word "digital multimeter" in a 16x2 LCD display.So I try the following one. But I suppose there may be much easier way to do this. Can somebody help me please
Code:
while(1){


lcd_gotoxy(1,2);
 printf(lcd_putc,"Digital multimeter ");
delay_ms(100);
lcd_gotoxy(1,2);
 printf(lcd_putc,"igital multimeter ");
delay_ms(100);
lcd_gotoxy(1,2);
 printf(lcd_putc,"gital multimeter ");
delay_ms(100);
lcd_gotoxy(1,2);
 printf(lcd_putc,"ital multimeter ");
delay_ms(100);
lcd_gotoxy(1,2);
 printf(lcd_putc,"tal multimeter ");
delay_ms(100);
lcd_gotoxy(1,2);
 printf(lcd_putc,"al multimeter ");
delay_ms(100);
lcd_gotoxy(1,2);
 printf(lcd_putc,"l multimeter ");
delay_ms(100);
lcd_gotoxy(1,2);
 printf(lcd_putc," multimeter ");
delay_ms(100);
lcd_gotoxy(1,2);
 printf(lcd_putc,"multimeter ");
delay_ms(100);
lcd_gotoxy(1,2);
 printf(lcd_putc,"ultimeter ");
delay_ms(100);
lcd_gotoxy(1,2);
 printf(lcd_putc,"ltimeter ");
delay_ms(100);
lcd_gotoxy(1,2);
 printf(lcd_putc,"timeter ");
delay_ms(100);
lcd_gotoxy(1,2);
 printf(lcd_putc,"imeter ");
delay_ms(100);
lcd_gotoxy(1,2);
 printf(lcd_putc,"meter ");
delay_ms(100);
lcd_gotoxy(1,2);
 printf(lcd_putc,"eter ");
delay_ms(100);
lcd_gotoxy(1,2);
 printf(lcd_putc,"ter ");
delay_ms(100);
lcd_gotoxy(1,2);
 printf(lcd_putc,"er ");
delay_ms(100);
lcd_gotoxy(1,2);
 printf(lcd_putc,"r ");
delay_ms(100);
lcd_gotoxy(1,2);
 printf(lcd_putc," ");
delay_ms(100);
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Mon May 16, 2011 3:41 am     Reply with quote

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);
   }


Best Wishes
cool121



Joined: 16 Mar 2011
Posts: 10
Location: US

View user's profile Send private message

PostPosted: Mon May 16, 2011 11:18 am     Reply with quote

Ttelmah thanks, your code is working
but I didn't understand how it happens can you explain it for me little bit
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon May 16, 2011 1:25 pm     Reply with quote

Also see this thread about side scrolling the lcd:
http://www.ccsinfo.com/forum/viewtopic.php?t=42792
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Mon May 16, 2011 2:44 pm     Reply with quote

On the code I posted, key is that a 'string', is an array of characters, terminated with a 'null' ('\0')/.
So 'message', is an array, with:
[0] D
[1] i
[2] g
[3] i
[4] t
[5] a
[6] l
[7]
[8] m
[9] u
[10] l
[11] t
[12] i
[13] m
[14] e
[15] t
[16] e
[17] r
[18]
[19]
[20] '/0'

0 to 20 elements, so 21 in all.
Now the '%s' printf format, takes the _address_ of an element in such an array, and prints all the elements from this point, till it gets to the '\0'.

'message', is the address of the array (C shorthand, the name of an array, is it's address).

So the first time round the loop, the printf is called with this address+0 (the start of the array), and prints the whole array till the end. next time, it starts at element '1', and as ctr increments, it moves through the array printing less and less of the characters.

Best Wishes
cool121



Joined: 16 Mar 2011
Posts: 10
Location: US

View user's profile Send private message

PostPosted: Mon May 16, 2011 11:47 pm     Reply with quote

Thank you Ttelmah now I understood what is going on
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