This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

controllable delay function

Hi! Guys! I want to design a delay function
that can have any desire delay value input in.ex.delay(20)-- 20ms of delay ,
delay(1000)- 1s of delay.

I got problem when I wanted to convert the value of the integer to hexadecimal value.
In addition, the hexadecimal value intialize into TH0 and TL0.
Give me your advice.
Thank You!

Parents
  • "I don't know how to convert from integer to hexadecimal using C."

    You don't need to!

    As far as 'C' is concerned, it's just a 16-bit number! It's up to you whether you want to write it in decimal as "1000" or in hex as "0x03E8" or in octal as "01750" - the internal storage within the processor is unaffected.

    I think your real question is, how to separate the two bytes of a 16-bit number?

    This can be done with shifts & masks, with pointers, or with a union.
    Think about it, and try a 'Search' - there's plenty of examples here already!

Reply
  • "I don't know how to convert from integer to hexadecimal using C."

    You don't need to!

    As far as 'C' is concerned, it's just a 16-bit number! It's up to you whether you want to write it in decimal as "1000" or in hex as "0x03E8" or in octal as "01750" - the internal storage within the processor is unaffected.

    I think your real question is, how to separate the two bytes of a 16-bit number?

    This can be done with shifts & masks, with pointers, or with a union.
    Think about it, and try a 'Search' - there's plenty of examples here already!

Children