View previous topic :: View next topic |
Author |
Message |
marcoelmejor
Joined: 19 Jan 2017 Posts: 3
|
lcd Function...i need a little tip |
Posted: Thu Jan 19, 2017 11:36 am |
|
|
(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
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: 19480
|
|
Posted: Thu Jan 19, 2017 11:53 am |
|
|
Try searching the forum.
This has been explained hundreds of times, as have the fixes. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jan 19, 2017 6:27 pm |
|
|
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: 1342
|
|
Posted: Thu Jan 19, 2017 8:47 pm |
|
|
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: 19480
|
|
Posted: Fri Jan 20, 2017 12:30 am |
|
|
'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
|
:) |
Posted: Fri Jan 20, 2017 7:56 pm |
|
|
pass_strings works :D thanky everybody |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19480
|
|
Posted: Sat Jan 21, 2017 2:03 am |
|
|
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
|
|
Posted: Mon Jan 23, 2017 8:24 pm |
|
|
I'm reading books, some book recommendation? some advice to more knowledge? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
|