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

Every character is seen as acsII .......why??

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







Every character is seen as acsII .......why??
PostPosted: Fri Feb 17, 2006 12:11 pm     Reply with quote

Hi all,
Is it me or is this just annoying and very silly.

I am trying to output hex values out the serial pins. sounds simple.

so i am using printf or fprintf to do so:

one would thing if you typed :

for(i=0x0;i<0x7F;i++){
printf("%x",i);
delay_ms(300);
}

i was thinking, this will give me the hex value of the numbers 0-128 on the serial TX line. instead it is giving me hex values of 30-7F, becuase it treats variable i as an ascii character......is that normal to anyone?? or i am alittle oblivious about something.

I will appreciate any help
Ttelmah
Guest







PostPosted: Fri Feb 17, 2006 12:40 pm     Reply with quote

You are I think misunderstanding something.
Hex, _is_ an ASCII format. The number '7F',is the two ASCII characters '37', and '46'. It sounds as if you are running a program at the other end, which is taking raw binary, and turning this into it's hex representation. hence your value gets converted twice!.
Try outputing the character using putc, as:
Code:

for(i=0x0;i<0x7F;i++){
    putc(,i);
    delay_ms(300);
}

This sends the raw value, and your program at the other end, will then do the required conversion.
In fact you are only dealing with raw numbers, and hex need not come into it at all. So:
Code:

for(i=0x0;i<127;i++){
    putc(,i);
    delay_ms(300);
}

Will give exactly the same result...

Best Wishes
kauty
Guest







PostPosted: Fri Feb 17, 2006 12:53 pm     Reply with quote

You would trhink after those year i would have it striaght!

You are absolutely correct and thanks for your quick help
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