|
|
View previous topic :: View next topic |
Author |
Message |
cool121
Joined: 16 Mar 2011 Posts: 10 Location: US
|
are there any easy way to do this LCD work |
Posted: Mon May 16, 2011 3:22 am |
|
|
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: 19539
|
|
Posted: Mon May 16, 2011 3:41 am |
|
|
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
|
|
Posted: Mon May 16, 2011 11:18 am |
|
|
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
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Mon May 16, 2011 2:44 pm |
|
|
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
|
|
Posted: Mon May 16, 2011 11:47 pm |
|
|
Thank you Ttelmah now I understood what is going on |
|
|
|
|
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
|