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

How to shift left string on lcd module

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



Joined: 28 Jun 2008
Posts: 24

View user's profile Send private message

How to shift left string on lcd module
PostPosted: Sat Jul 19, 2008 8:38 am     Reply with quote

Code:
#include <16f877a.h>
#fuses hs,nolvp,nowdt,noprotect
#use delay(clock = 20000000)
#use fast_io(B)
#define use_portb_lcd
#include <lcd.c>

#define maxchar 16

char buff[maxchar] = "batman        " ;
char c;
int i;

void rotate_string(void)
{
   c = buff[0];
   for(i=0;i<maxchar-1;i++)
   {
   buff[i] = buff[i+1];

   }
   buff[maxchar-1] = c;
}

void display_string(void)
{
  printf(lcd_putc," %c ",  buff[i]  );

}

void main()
{
   set_tris_b(0x00);
   lcd_init();

   while(true)
   {
      display_string();
      rotate_string();
      delay_ms(500);

   }
}

this is my code , but i think it is wrong , please help me

ps. i want to shift left string all time on lcd module in the 2 line of lcd
but my code it cannot shift left because a new character is occur in the
same position as old character

ps. in the 1 line of lcd i would like to show another string on the middle of
lcd i can us command :
lcd_gotoxy( , );

ps. i cannot use command 0x07 (shift left) because it shift my string
in the 1 and 2 line of lcd

who know about this , Help me please.
Thank you very much
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sat Jul 19, 2008 5:13 pm     Reply with quote

The rotate_string() function looks OK to me.
The display_String () function however is wrong:
Code:
printf(lcd_putc," %c ",  buff[i]  );
This will print: a space, a single random character, and a space.
The printed character is more or less random because when you execute this line the global variable 'i' is at value maxchar and buf[maxchar] is outside of the array.

try:
Code:
void display_string(void)
{
  lcd_gotoxy(1,2);     // move to first position of line 2
  for(i=0;i<maxchar-1;i++)
  {
    lcd_putc( buff[i] );
  }
}


Another problem:
Code:
#define maxchar 16

char buff[maxchar] = "batman        " ;
The string contains only 14 characters + a terminating zero = 15.
Ther terminating zero is not readable text and might give strange results on your display. Fix by adding an extra space character to your string.
atomy_kwang



Joined: 28 Jun 2008
Posts: 24

View user's profile Send private message

PostPosted: Sat Jul 19, 2008 11:07 pm     Reply with quote

thank you very much for edit code , i can do it successfully
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