|
|
View previous topic :: View next topic |
Author |
Message |
proggy Guest
|
Pointer to string problem |
Posted: Mon Jul 14, 2003 12:00 pm |
|
|
I'm trying to pass a string to my LCDPrint function. LCDPrint should print the offsetted characters (string) to the LCD screen, but it doesn't work. Can anyone explain why this does not work with the CCS compiler or if there is another way around this?
void LCDPrint(char *pch)
{
while(*pch)
{
AutoOut(*pch - 0x20); //output offset character
pch++; //point to next character
}
}
I'm using version 3.168.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515961 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: Pointer to string problem |
Posted: Mon Jul 14, 2003 12:56 pm |
|
|
:=I'm trying to pass a string to my LCDPrint function. LCDPrint should print the offsetted characters (string) to the LCD screen, but it doesn't work. Can anyone explain why this does not work with the CCS compiler or if there is another way around this?
:=
:=void LCDPrint(char *pch)
:={
:= while(*pch)
:= {
:= AutoOut(*pch - 0x20); //output offset character
:= pch++; //point to next character
:= }
:=}
:=
:=I'm using version 3.168.
-----------------------------------------------
I don't have an LCD on my test board, currently, so I
just directed the output to putc() instead, but this
test program worked OK with PCM vs. 3.168.
Because you're subtracting 0x20 from each char, I had
to use lower case chars and the @ symbol, in order to
get some readable output on my terminal window.
It displays: "HELLO WORLD"
#include "c:\Program Files\Picc\Devices\16F877.H"
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 8000000)
#use rs232(baud = 9600, xmit=PIN_C6, rcv = PIN_C7, ERRORS)
void LCDPrint(char *pch);
void AutoOut(char value);
//=============================================================
void main()
{
char buffer[20];
strcpy(buffer, "hello@world");
LCDPrint(buffer);
while(1);
}
//=============================================================
void LCDPrint(char *pch)
{
while(*pch)
{
AutoOut(*pch - 0x20); //output offset character
pch++; //point to next character
}
}
void AutoOut(char value)
{
putc(value);
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515965 |
|
|
proggy Guest
|
Re: Pointer to string problem |
Posted: Mon Jul 14, 2003 1:46 pm |
|
|
Instead of copying the string into buffer, couldn't you use the function itself?
For example:
LCDPrint("testing display");
:=-----------------------------------------------
:=
:=I don't have an LCD on my test board, currently, so I
:=just directed the output to putc() instead, but this
:=test program worked OK with PCM vs. 3.168.
:=
:=Because you're subtracting 0x20 from each char, I had
:=to use lower case chars and the @ symbol, in order to
:=get some readable output on my terminal window.
:=
:=It displays: "HELLO WORLD"
:=
:=#include "c:\Program Files\Picc\Devices\16F877.H"
:=#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
:=#use delay(clock = 8000000)
:=#use rs232(baud = 9600, xmit=PIN_C6, rcv = PIN_C7, ERRORS)
:=
:=void LCDPrint(char *pch);
:=
:=void AutoOut(char value);
:=
:=
:=//=============================================================
:=void main()
:={
:=char buffer[20];
:=
:=strcpy(buffer, "hello@world");
:=LCDPrint(buffer);
:=
:=
:=while(1);
:=}
:=
:=//=============================================================
:=
:=void LCDPrint(char *pch)
:={
:= while(*pch)
:= {
:=
:= AutoOut(*pch - 0x20); //output offset character
:= pch++; //point to next character
:= }
:=}
:=
:=
:=void AutoOut(char value)
:={
:=putc(value);
:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515968 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: Pointer to string problem |
Posted: Mon Jul 14, 2003 2:11 pm |
|
|
:=Instead of copying the string into buffer, couldn't you use the function itself?
:=
:=For example:
:=LCDPrint("testing display");
--------------------------------------------------------
No, because CCS doesn't support pointers to constant strings.
However, you can re-write your code to do it this way:
<PRE>
#include "c:\Program Files\Picc\Devices\16F877.H"
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 8000000)
#use rs232(baud = 9600, xmit=PIN_C6, rcv = PIN_C7, ERRORS)
<BR>
void LCDPrint(char c);
void AutoOut(char value);
<BR>
char const message1[] = {"hello@world"};
<BR>
//=============================================================
void main()
{
<BR>
LCDPrint(message1);
<BR>
while(1);
}
<BR>
//=============================================================
<BR>
void LCDPrint(char c)
{
AutoOut(c - 0x20); //output offset character
}
<BR>
<BR>
void AutoOut(char value)
{
putc(value);
}
</PRE>
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515971 |
|
|
|
|
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
|