Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
09/21/06 23:00
Read: times


 
Msg Score: +1
 +1 Good Answer/Helpful
#124838 - How have you measured this?
Responding to: ???'s previous message


I can't see how these routines would take an inordinate amount of time. However, if your value Dig_Cnt was a large number, then it might take some time.

If you have an oscilloscope, a quick and simple way of timing your routines is to set an output pin at the begining of a routine and clear it at the end.

Your routine names lie! Hex_2_ascii does not convert a hex value to ascii! The variable you supply is an integer not a hex value! Hex is base16 - I see no conversion from base 16! There are usually functions in the libraries supplied with your 'c' compiler that do exactly what you want to do - so why are you re-inventing the wheel? Have a look at scanf and printf for a start - this routines are large so be aware.

Whilst I understand you're a beginner, you are starting with some bad habits - we have some globals: Buff_kb,Dig_cnt,Ready. Also, in Ascii_2_Hex, if the converted value is 0, what do you return? If the converted value is not 0, you set Ready and return the value. Would it not be easier to just return the value and let the calling routine figure out what to do with it?
I would suggest you do some reading on the 'c' language regarding pointers, with pointers you will be able to rid your self of the 'extern' declarations. Also, it will mean your functions can work with any buffer you want to pass them - not just Buff_kb!

In Hex_2_Ascii, you make a copy of the passed variable - this is unecessary as 'c' passed this variable by value - it gave you a copy already. Pointers on the other hand pass by reference - if you modify a variable pointed to by the pointer, the variable itself is modified.

Simply:
pass by value: I give you a copy of the value.
pass by reference: I tell you where to find the value.




So for Hex_2_Ascii I would write:

void Hex_2_Ascii(unsigned int val,char *buf,char dig_cnt)
{
}
to call this I would write:

Hex_2_Ascii(value,Buf_Kb,5);


List of 4 messages in thread
TopicAuthorDate
Data conversion            01/01/70 00:00      
   How have you measured this?            01/01/70 00:00      
      How have you measured this?            01/01/70 00:00      
         Try This            01/01/70 00:00      

Back to Subject List