View previous topic :: View next topic |
Author |
Message |
joseph
Joined: 14 Jun 2010 Posts: 16
|
How a can putc ( hexa value )..... |
Posted: Mon Jun 14, 2010 7:15 am |
|
|
Hello, I have a big question.... I need to put on a display a hex value with putc/puts and not printf. But i don't know how to. Can you explain me the solution.Thanks before.
int8 temp;
temp=0xA8;
fct_XXXXXXX(temp); // With utilisation 'putc' or 'puts'
------------------------------------------
result on display : 'A8' |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Jun 14, 2010 8:03 am |
|
|
A typical school assignment.
Students understanding the matter will write the function in two minutes. The other students are found on this forum... |
|
|
joseph
Joined: 14 Jun 2010 Posts: 16
|
|
Posted: Mon Jun 14, 2010 8:16 am |
|
|
Thank for you aid...... If i have wrote this message, it's because i haven't find the answer on forum. so if you have a link or a precision, don't keep the information !
thanks |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Jun 14, 2010 8:37 am |
|
|
Come on, be creative!
There are at least four possible solutions that I can think of, one of these is short and very fast but the others do the job too.
How would you handle this question if you had to print the decimal value 23?
You would:
1) print 2
2) print 3
Now, in step 1, how do you get the 2 from the 23 value?
And then the 3? |
|
|
joseph
Joined: 14 Jun 2010 Posts: 16
|
|
Posted: Mon Jun 14, 2010 8:59 am |
|
|
i think you have not correctly understand my question, so i try to explain better.
1.My pic read position (hexa value) in a motor stepper controller.
2.I will send this value on RS232 with a protocol.
> The protocol specifie to "print" the value like a ASCII caracter.
If the position is 0xA8; i would send A8 in ASCII whithout printf funtion but put or puts. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Jun 14, 2010 9:15 am |
|
|
The explanation does not really help, but if I understand correctly you can not use printf("%x). Right?
You mean you have to write your own implementation of the %x conversion?
If yes, then you are back at my simple '23' printing question. |
|
|
joseph
Joined: 14 Jun 2010 Posts: 16
|
|
Posted: Mon Jun 14, 2010 9:25 am |
|
|
Exactly, i don't want use printf (it's embeded software), and i try to write my own function !
For the question of decimal value, the protocol say not decimal... only in hex
-> the value is 0xA8, the value must be send like :
putc('A');
putc('8'); |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Jun 14, 2010 9:32 am |
|
|
joseph wrote: | Exactly, i don't want use printf (it's embeded software), and i try to write my own function ! | The CCS compiler is optimized for embedded software and very efficient. Only try to do optimization when your project has problems with memory usage or speed.
I know you need an answer for hexadecimal, but decimal is easier to understand. The step from decimal to hex is small. |
|
|
|