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 CCS Technical Support

Serial translation question !

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



Joined: 16 Sep 2008
Posts: 51

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

Serial translation question !
PostPosted: Tue Jan 27, 2009 3:25 am     Reply with quote

Hello !

Here is what i'm trying to do :

Let's say i have a character transmitted from serial like 0xAA (binary : 10101010).

I want to translate this command into : 0x3AA (binary : 1110101010).

How can this be done ?

Should i use a cast it to int, like this :

Code:

   char c;
   int d;
   
   d=(int)c*


Thank you all !
Andrew83



Joined: 16 Sep 2008
Posts: 51

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

PostPosted: Tue Jan 27, 2009 4:58 am     Reply with quote

Here is a small test code that isn't working:
Code:

#include <18f452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=10000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)


//=============================================================================
void main()
{
 char c;
 int d;
 while(1)
 {
 c=getc();
 d=(int)c*;
 printf("%ld",d);
 }

}


In the CCS c manual :
Quote:

getc( ) .... Returns: An 8 bit character


HELP !!!!!!!!
Guest








PostPosted: Tue Jan 27, 2009 5:47 am     Reply with quote

int is a 8-bit bit value in the CCS compiler.
why do you cast the value (btw cast with * cant work in your example)? what about
c=getc();
printf("%u",c);
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Tue Jan 27, 2009 6:19 am     Reply with quote

not sure what you are trying to do with c*

int is 8 bits on a pic.

try int16

Code:

char c;
int16 d;
while(1)
{
  c = getc();
  d = (int16)c + 0x300;
  printf("%ld",d);
}



LOL, distracted while typing my post so didn't see Guest post Smile
Andrew83



Joined: 16 Sep 2008
Posts: 51

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

PostPosted: Tue Jan 27, 2009 12:41 pm     Reply with quote

Thank you 4 your quick answer ! ;)
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