View previous topic :: View next topic |
Author |
Message |
Andrew83
Joined: 16 Sep 2008 Posts: 51
|
Serial translation question ! |
Posted: Tue Jan 27, 2009 3:25 am |
|
|
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
|
|
Posted: Tue Jan 27, 2009 4:58 am |
|
|
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
|
|
Posted: Tue Jan 27, 2009 5:47 am |
|
|
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
|
|
Posted: Tue Jan 27, 2009 6:19 am |
|
|
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 |
|
|
Andrew83
Joined: 16 Sep 2008 Posts: 51
|
|
Posted: Tue Jan 27, 2009 12:41 pm |
|
|
Thank you 4 your quick answer ! ;) |
|
|
|