Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

lcd using pointers - help needed

Status
Not open for further replies.

garg29

Advanced Member level 1
Joined
Nov 17, 2004
Messages
443
Helped
25
Reputation
50
Reaction score
10
Trophy points
1,298
Activity points
3,593
lcd using pointers

I am trying to combine some charaters to show on lcd using pointers but it's showing me error...."only lvalues may be assigned to or modified"



Code:
unsigned char  buf[6];

lcd_clear();
		lcd_goto(0x80);
		*buf ='1';
		*buf++ ='2';
		*buf++ ='.';
		*buf++ ='4';
		*buf++ ='a';
		
		
	lcd_puts(buf);


I know i can do this with other simpler methods but i want to do this by using pointers. Actually I'm trying to learn pointers.

I'm doing it on 16F688 with Hitech Picc compiler.


Thanks

Regards
 

Re: lcd using pointers

buf is a name of an array that is statically defined in the code.
In other words, it is assigned to the stack, you can't change the value of buf as you doing in the code.

For you code to work correctly as you wrote it here, you have to define buf as a char pointer then allocate the storage for it using malloc function. By this, buf will be allocated in the heap and you will avoid this error.

--
Amr Ali
 

    garg29

    Points: 2
    Helpful Answer Positive Rating
lcd using pointers

Thanks a lot for replying. I'm just a bit confused.... then how does buf work with sprintf like:
Code:
sprintf(buf, "%d", 123);

sorry, if I'm asking something wrong.
And can you, Please, tell me a small example on how to write Malloc for this type of application.

Thanks once again,

regards
 

Re: lcd using pointers

It works with sprintf because you copy to the contents of buf not modifying buf itself as your original code was doing.

How to use malloc?
I prefer to refer to opengroup.org when I have questions about functions and their usage"http://www.opengroup.org/onlinepubs/009695399/functions/malloc.html"

You use it like this:
char * buf;

buf = (char*) malloc(required size in bytes);


--
Amr Ali
 

    garg29

    Points: 2
    Helpful Answer Positive Rating
lcd using pointers

Thanks a lofor your immidiate reply. I tried doing this. First it gave me error malloc function missing Then I added malloc.c file from hitech picc folder to my source file list now it's giving me error :-
Code:
Error   [480] ; . function signatures do not match: _malloc (malloc.obj): 0x1079/0x42
Error   [499] ; . undefined symbol:
	_sbrk (malloc.obj)

What to do, sir?
 

Re: lcd using pointers

just include stdlib.h to your project do not add any other files.
--
Amr Ali
 

Re: lcd using pointers

You have several errors in your original code.

Buf is an array variable. When using buf without an index, it's equivalent to a constant pointer, that holds the address of
the array, but it can't be changed. You need to use a real pointer variable. Also you must add a string terminator to
print the string.

Code:
unsigned char  buf[6]; 
unsigned char  *pbuf; 
  pbuf = buf;
  *pbuf ='1'; 
  *pbuf++ ='2'; 
  *pbuf++ ='.'; 
  *pbuf++ ='4'; 
  *pbuf++ ='a'; 
  *pbuf = 0;
 

    garg29

    Points: 2
    Helpful Answer Positive Rating
lcd using pointers

I tried that also...... It's not working.... It's giving
Code:
Error   [499] ; . undefined symbol:
	_malloc
 

lcd using pointers

You have to link the correct library to your code and make sure that malloc is defined for you platform.
--
Amr Ali
 

    garg29

    Points: 2
    Helpful Answer Positive Rating
lcd using pointers

amraldo: how should i link it ????

FvM: Thanks. Your method is working but it's missing out the first value...i.e. *pbuf ='1'; on display I'm getting "2.4a" instead of "12.4a"
 

lcd using pointers

what is your compiler and target chip?
--
Amr Ali
 

    garg29

    Points: 2
    Helpful Answer Positive Rating
lcd using pointers

Hitech PICC & Chip is PIC16F688
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top