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

LCD scrolling a Message!!

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



Joined: 17 Oct 2005
Posts: 68
Location: Brisbane

View user's profile Send private message

LCD scrolling a Message!!
PostPosted: Sat Mar 25, 2006 10:34 pm     Reply with quote

the following function give an error when called from main().The error measage is"ATTEMPT TO CREATE CONST TO POINTER SPRINTF".
All I want is a function to scroll a measage. This function is modified from the a function presented in the PICCLITE I googled recently.
Code:
void scroll_Msg(unsigned char rowz, char Msg[]){
char Tmp_Msg[21];
unsigned in k,flag,Msg_Head;
flag=Msg_Head=0;
if(rowz>1) rowz=1;
rowz*=40;
while(flag==0){
for(k=0; k<20; k++){
Tmp_Msg[k]=Msg[Msg_Head+k];
   if(Msg[Msg_Head+k+1]==0)
     flag=1;
     }
     Msg_Head++;
     lcd_goto_xy(rowz,1); //go to line 1 first row
     lcd_putc(Tmp_Msg);
     delay_ms(100);       //delay 100 ms
   }
}


void main(void)
{

//All initiallisations done here
while(1){
   scroll_Msg(0,"A final year project!");   
}

}

this function compiled without error.However when I called from the main() as shown above, there is an error.
Code:
ATTEMPT TO CREATE CONST TO  POINTER  SPRINTF

My version is 3.24;
why is the compiler giving this error.Is there a problem with my compiler?
Can anyone help me out here! Shocked
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Mar 25, 2006 11:21 pm     Reply with quote

Kel,
If you read the forum regularly, you would have seen some of the
many, many posts on this topic. Here is one of them:
http://www.ccsinfo.com/forum/viewtopic.php?t=21588


If you want to do side-scrolling with an LCD, here is a demo program:
This one works with a 16x2 LCD.
Code:

#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)

// Put your LCD driver here.
#include <lcd.c>


void lcd_scroll_right(void)
{
lcd_send_byte(0, 0x1E);
}
//-------------------------

void lcd_scroll_left(void)
{
lcd_send_byte(0, 0x18);
}

   
//=======================
void main()
{
int8 i;

lcd_init();

lcd_putc("\f");  // Clear the LCD
delay_ms(100);   

// The LCD memory is 40 characters wide, so fill it
// up with data for two screens.  Each line below must
// contain 40 characters (excluding the newline).   
lcd_putc("Hello to the        Side scrolling      \n");
lcd_putc("world.              demo.               ");

while(1)
  {
   for(i = 0; i < 20; i++)  // Scroll for 20 chars
      {
       lcd_scroll_left();
       delay_ms(350);   // This sets the scroll speed
      }

   delay_ms(2000);   // Wait 2 seconds between scrolling
                     // each screen.
  }

}
kel



Joined: 17 Oct 2005
Posts: 68
Location: Brisbane

View user's profile Send private message

Thanks PCM Programmer!
PostPosted: Sun Mar 26, 2006 3:03 am     Reply with quote

I believe you are highly qualified and respected member of this forum.Thanks you and those who have attempted.
Y couldn't my code work?
Ttelmah
Guest







PostPosted: Sun Mar 26, 2006 3:17 am     Reply with quote

It is important to understand that the actual 'architecture' of a PIC, is not like most other processors. The PIC, has seperate 'code', and 'data' memories, with different addressing needed for each. Now, if you declare:
Code:

   scroll_Msg(0,"A final year project!");   

The message "A final year project!", is generated and stored in _code_ memory, as a constant string. Now CCS, only supports 'pointers' to the _data_ memory. The thread that PCM Programmer points you to, explains this, and some of the approaches used to get round this.
In your case, if you declared:
Code:

   char message[] = "A final year project!";


Then the compiler would take the code declarations, and _automatically copy them into data memory_, to generate a character array, which can then be used in your function.
Similarly, you could do this yourself, by declaring a data array, and copying the array with 'strcpy', which is capable of moving arrays from the code memory to the data memory.

Best Wishes
kel



Joined: 17 Oct 2005
Posts: 68
Location: Brisbane

View user's profile Send private message

Guess this should work now!!
PostPosted: Sun Mar 26, 2006 9:13 pm     Reply with quote

I guess this should work now.I haven't tried it yet.
Code:
void scroll_Msg(unsigned char rowz, char Msg[]){
char Tmp_Msg[21];
unsigned in k,flag,Msg_Head;
flag=Msg_Head=0;
if(rowz>1) rowz=1;
rowz*=40;
while(flag==0){
for(k=0; k<20; k++){
Tmp_Msg[k]=Msg[Msg_Head+k];
   if(Msg[Msg_Head+k+1]==0)
     flag=1;
     }
     Msg_Head++;
     lcd_goto_xy(rowz,1); //go to line 1 first row
     lcd_putc(Tmp_Msg);
     delay_ms(100);       //delay 100 ms
   }
}


void main(void)
{

//All initiallisations done here
char message[] = "A final year project!";
while(1){
   scroll_Msg(0,message);   
}

}

Will the compiler still complain?
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