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

output of an 8bit integer as ascii on rs232

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







output of an 8bit integer as ascii on rs232
PostPosted: Thu Jan 19, 2006 2:54 am     Reply with quote

hello!

iīd like to print out the status of the whole port_b using input_b(). this returns a 8bit integer. now i will send this value over rs232 in ascii format.
i searched in the posts for integer to char conversion but i canīt find the correct answer.
can anybody help me?

thanks a lot in advance
kypec



Joined: 20 Sep 2003
Posts: 54

View user's profile Send private message

PostPosted: Thu Jan 19, 2006 4:01 am     Reply with quote

Look at the built-in printf() function and its arguments.
christoph
Guest







PostPosted: Thu Jan 19, 2006 5:06 am     Reply with quote

okay...thank you! as you can see iīm beginner in programming.
i have read the help about printf but i īstill canīt get it working...

would you post me an example?
kypec



Joined: 20 Sep 2003
Posts: 54

View user's profile Send private message

PostPosted: Thu Jan 19, 2006 5:16 am     Reply with quote

Code:
printf("%u",input_b()); //outputs 8-bit value of PORTB as ASCII string consisting of 1 to 3 characters
printf("%03u",input_b()); //outputs 8-bit value of PORTB as ASCII string with fixed length = 3 characters with leading zeros
christoph
Guest







PostPosted: Thu Jan 19, 2006 6:18 am     Reply with quote

thank you!!

i tried you code but with this i donīt get for example "10011100" representing the the port status return - i get the decimal value in ascii-text.

i want to havefor RS232 in ascii: for exampe "Input-Status PortB is 10011100"
so i need a conversion from the 8bit integer to a char-array with 8 records.

you know what i mean? iīm right?
christoph
Guest







PostPosted: Thu Jan 19, 2006 6:19 am     Reply with quote

decimal value between 0 and 255 to be correct.
kypec



Joined: 20 Sep 2003
Posts: 54

View user's profile Send private message

PostPosted: Thu Jan 19, 2006 6:45 am     Reply with quote

Code:
int8 bit_position,port_value;

port_value=input_b();
printf("Input-Status PortB is ");
for (bit_position=8;bit_position>0;bit_position--) {
   if (port_value & 0b10000000) putc('1');
   else putc('0');
   port_value<<=1;
}
putc(13); //carriage return character alias END OF LINE
christoph
Guest







PostPosted: Thu Jan 19, 2006 8:47 am     Reply with quote

thank you... this is the way i tried!
with your code it is "more careful"
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