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

lcd Function...i need a little tip

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



Joined: 19 Jan 2017
Posts: 3

View user's profile Send private message Send e-mail

lcd Function...i need a little tip
PostPosted: Thu Jan 19, 2017 11:36 am     Reply with quote

(my english is bad)
I'm just trying to do a function to show
letter by letter, just writing ("the sentence", delay time) in the function
but appears an error:
- attempt to create a pointer to a constant Crying or Very sad

Below is the indication where is the compiler error:
Code:

#include <16f877a.h>
#include <stdio.h>
#include <string.h>
#fuses xt,nowdt,put,nobrownout,nocpd
#use delay(clock=4000000)

#define LCD_DB4   PIN_B2
#define LCD_DB5   PIN_B3
#define LCD_DB6   PIN_B4
#define LCD_DB7   PIN_B5
#define LCD_RS    PIN_D3
#define LCD_RW    PIN_D2
#define LCD_E     PIN_B1
#include <lcd1.c>

#define ms delay_ms

void des(char f[],long t);

void main()
{
lcd_init();

while(1)
  {
   des("jojos", 500); // HERE: Attempt to create a pointer to a constant.
   ms(300);
  }
}

void des(char f[], long t)
{ //funcion (frase a desplazar:letras, tiempo de retardo por letra: tiempo)
int y=1;//posicion y lcd
int x=1;//posicion x lcd

for(int i=1; i<sizeof(f); i++) //bucle for para colocar letra por letra
  {
   lcd_gotoxy(x,y); //posicion lcd
   lcd_putc(f[i-1]); //que letra se colocara
   ms(t);//retardo por letra, dato introducido desde la funcion desplazar
   x++;//aumento posicion "X" del lcd
 
   if((x>16)&&(y==1))
     {//si la posicion "X" alcanza los 16 cuadros que continue la frase desde x=1,y=2
      y=2;
      x=1;
     }

   if((x>16)&&(y==2))//Si alcanza los 16 cuadros de arriba y abajo, que  limpie lcd y continue escribiendo desde x=1,y=1
    {
     lcd_putc("\f");
     x=1;
     y=1;
    }

   if(i==sizeof(f)-1)//que limpie lcd cuando termine la frase y vuelva a comenzar
    {
     lcd_putc("\f");
    }
  }
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19440

View user's profile Send private message

PostPosted: Thu Jan 19, 2017 11:53 am     Reply with quote

Try searching the forum.
This has been explained hundreds of times, as have the fixes.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jan 19, 2017 6:27 pm     Reply with quote

The answer is to add the line in bold below, just after the #include line:
Quote:
#include <16f877a.h>
#device PASS_STRINGS=IN_RAM
#include <stdio.h>
#include <string.h>
#fuses xt,nowdt,put,nobrownout,nocpd
#use delay(clock=4000000)



Ttelmah, I tried searching for "attempt to create a pointer to a constant"
with CCS and Google and it's not that easy to find the accurate answer,
and I even know what I'm looking for. The CCS search engine ignores
quoted strings and just searches on individual words.

If you use Google, the very first one that comes up has a long disertation
by you, but not the simple answer. Other Google responses in the same
list for the 1st one, are also not giving the short, simple answer.

-------------
Edit: He has informed me in a PM that this fixed his compilation problem.
jeremiah



Joined: 20 Jul 2010
Posts: 1336

View user's profile Send private message

PostPosted: Thu Jan 19, 2017 8:47 pm     Reply with quote

Unrelated but:

your "sizeof(f)" isn't going to work out very well in that function. It'll just return the size of a pointer to your array, not the size of the array itself. Even though you specify it as an array in the function params, it is actually passed as a pointer under the hood, so that is what the sizeof() will measure.
Ttelmah



Joined: 11 Mar 2010
Posts: 19440

View user's profile Send private message

PostPosted: Fri Jan 20, 2017 12:30 am     Reply with quote

'Search for all terms' only gives one page of answers, and over half of these have pointers to others. I hoped he would look, because rather than giving the 'modern' answer (PASS_STRINGS), it would also give the explanations of 'why', and the other solutions, which may be better in some cases.
marcoelmejor



Joined: 19 Jan 2017
Posts: 3

View user's profile Send private message Send e-mail

:)
PostPosted: Fri Jan 20, 2017 7:56 pm     Reply with quote

pass_strings works :D thanky everybody
Ttelmah



Joined: 11 Mar 2010
Posts: 19440

View user's profile Send private message

PostPosted: Sat Jan 21, 2017 2:03 am     Reply with quote

Have you looked though, to understand 'why', and what the implications of this are?.
It is important 'long term', or you will find things like this coming back to 'bite you'.
marcoelmejor



Joined: 19 Jan 2017
Posts: 3

View user's profile Send private message Send e-mail

PostPosted: Mon Jan 23, 2017 8:24 pm     Reply with quote

I'm reading books, some book recommendation? some advice to more knowledge?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jan 23, 2017 8:41 pm     Reply with quote

These two threads contain more explanation of the PIC architecture
by Ttelmah:
https://www.ccsinfo.com/forum/viewtopic.php?p=71942
http://www.ccsinfo.com/forum/viewtopic.php?t=34302&start=5
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