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

very dumb question... Solved

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



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

very dumb question... Solved
PostPosted: Sat Oct 22, 2011 9:22 am     Reply with quote

hi,

I have a serial device that ouputs via RS232 numbers 0-9, *, #
(serial keypad).
Code:

IF(var=='#'){blah;}

# is a special character... how do I make the above comparison?

What is the special character I should place before # so that its take as a value and not as if were trying to do a #define....
Code:

IF(var=='\#'){blah;}

like above? I had a similar problem trying to print (") .... where I had to use \"

Sorry for the dumb question...

thanks.
_________________
CCS PCM 5.078 & CCS PCH 5.093


Last edited by Gabriel on Mon Oct 24, 2011 7:09 am; edited 1 time in total
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sat Oct 22, 2011 9:52 am     Reply with quote

'#' doesn't need to be escaped, neither in printf format strings nor other character and string literals.
temtronic



Joined: 01 Jul 2010
Posts: 9228
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Oct 22, 2011 10:09 am     Reply with quote

Nothing 'special' about the # key.
Since your device outputs the keypresses as serial, just use a 'terminal program'(I use Realterm) to show you what the serial keyboard is sending, vis RS232, for the keypresses.Be sure to get the baud,parity,stops bits correct !
If it's a straight ASCII lookup table then your device should send a decimal 35 ( hex 23) for the # key.
There are NO 'carved in stone' formats for serial keyboards so you should decode each keypress as I've stated above.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Sun Oct 23, 2011 5:31 pm     Reply with quote

short summary:

If you know the ASCII code for the 8 bit char you want to compare
it is just that 8 bit unsigned number compared to the var.

I suggest the VAR be either byte or unsigned int8
otherwise you need to cast the value.

Code:

if ( var==ascii_code ) { action(); etc();  }
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Mon Oct 24, 2011 6:55 am     Reply with quote

hey all, thanks for your replies...

yeah.. i agree, the ascii code should work fine.... Duh!

however, the # character when used as:

Code:
IF(var=='#'){blah;}


does give me an error, and shows up in Green like when used in a #device statement.... maybe im missing somthing...

thanks for your help....i cant believe i didnt think about using the hex value of #.....
sad thing is i posted last week a comment to some other guy related to the interpretation of characters in terminals.... i should sleep,

thank you all...

G
_________________
CCS PCM 5.078 & CCS PCH 5.093
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Mon Oct 24, 2011 9:41 am     Reply with quote

is best to assume
that #, _
and possibly other reserved characters used as compiler directive prefix
symbols could share the same fate

HEX or decimal constants are always safe tho ;-))
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Tue Oct 25, 2011 2:26 am     Reply with quote

Gabriel wrote:
hey all, thanks for your replies...

yeah.. i agree, the ascii code should work fine.... Duh!

however, the # character when used as:

Code:
IF(var=='#'){blah;}


does give me an error, and shows up in Green like when used in a #device statement.... maybe im missing somthing...

thanks for your help....i cant believe i didnt think about using the hex value of #.....
sad thing is i posted last week a comment to some other guy related to the interpretation of characters in terminals.... i should sleep,

thank you all...

G


Just took the experiment, of trying this, with a crude test program.
Tested with 3.249, 4.099, 4.118. None complained.

Code:

//With header and RS232 setup:
void main(void) {
   int8 kval;
   do {
       if (kbhit()) {
         kval=getc();
         if (kval=='#')
            putc('M');
         else
            putc('n');
   } while(TRUE);
}

One 'reason', would be if there was something a line or two earlier, that is looking for the '#'. You _may_ be hitting the old CCS problem of not seeing an earlier syntax error, that then makes a latter line complain, and it just happens to be the #, that is triggering this. Another possibility is that 'IF' in upper case, is the preprocessor form, and the compiler will complain about this if #case is selected.
So though using a hex value has solved the problem, you might want to look at your syntax round the area with a fine tooth comb.

Best Wishes
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Tue Oct 25, 2011 6:43 am     Reply with quote

Hi!... thanks for diggin deeper...

ill check it out tonight when i get home, and post the code tomorrow morning as well...or my findings... which ever comes first...



Thanks!
G
_________________
CCS PCM 5.078 & CCS PCH 5.093
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