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

convert ascii value to character

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



Joined: 18 Nov 2008
Posts: 278
Location: Athens, Greece.

View user's profile Send private message

convert ascii value to character
PostPosted: Sun Mar 22, 2009 6:21 pm     Reply with quote

Hi all!

Is there a way to convert ascii value to character?

For example I have the int8 number 65, I want to get back the character "A" in char format. something like the "toascii" which is not included in CCS.


Regards
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Sun Mar 22, 2009 6:33 pm     Reply with quote

Just cast the int8 to type char. At the machine level nothing actually happens as both representations are the same in binary.

If you putc(65) you will get an "A" out the serial port. Putc() just looks at the binary and doesn't know what data type it is.
_________________
The search for better is endless. Instead simply find very good and get the job done.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Mar 22, 2009 6:38 pm     Reply with quote

Quote:
something like the "toascii" which is not included in CCS

It's normally in ctype.h, and it's a just a simple macro:
Code:
#define toascii(c) ((c) & 0x7f)
georpo



Joined: 18 Nov 2008
Posts: 278
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Wed Mar 25, 2009 9:25 am     Reply with quote

hello again.

Let me explain,
I have a ps-2 keyboard connected to the pic. I convert scan code to ascii etc and I end up with the pressed key in int8 ascii number.

I want to add each character received to a string using the strcat command and finally have a string with the characters received.

That is why I want to convert number to string.

does "toascii" return char or int type? and please give me an example of how to use the macro.

Thanks.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Mar 25, 2009 9:42 am     Reply with quote

Basically you don't need a conversion cause int8 and char are alias types. They may be either signed or unsigned, but this doesn't matter in this regard.

The intended method of concatenating characters to a string is actually the more interesting thing. You may e.g. use an index:

Code:
char c[11]; // need room for terminating 0
int8  scancode;
for (i=0;i<10;i++)
{
   scancode = get_it_somewhere();
   c[i]=scancode;
}
c[10]=0;
printf("This is my collected string: %s\r\n",c);
georpo



Joined: 18 Nov 2008
Posts: 278
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Wed Mar 25, 2009 10:17 am     Reply with quote

Thank you FvM.

really simple indeed. It works!

Now I need to parse the string for expected names,
For example you write"print hello" to the keybord.

I want to search the string that we created, seperate and recognize the "print", the " " and the user input "hello".

As you can see I am trying to make a simple PC.

I already have a dspic running a VGA monitor at 640X480, creating fonts etc.
Now I have to analyze user input.

Regards.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Mar 25, 2009 2:19 pm     Reply with quote

Basically, CCS C is supporting standard C string library functions. They can achieve the intended action, e.g. strncmp() or strstr(). However, you have to pay attention to the fact, that constant strings (residing in flash memory) can't be used in all places where a string argument is required. Thus strstr(stri,"hello") doesn't work in default const mode.
georpo



Joined: 18 Nov 2008
Posts: 278
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Wed Mar 25, 2009 2:42 pm     Reply with quote

can you give me an example of the syntax for these commands?

thanks.
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