How to convert the decimal value to hexadecimal value which needed to be stored in the timer? for example: Timer Low and Timer High only need 2 values such as the 0xFB. How can we extract it if we able to get the hexa from decimal? Have any ideas abt this ? thanx
Think more carefully - there is no conversion required here. A 16-bit number is the same number whether you choose to display it in binary, decimal, hexadecimal, or any other radix (number base)! You could even display it using Roman numerals, if you want! So the question is just how to separate the individual bytes - this is a standard 'C' problem, and nothing specifically to do with Keil. To be completely portable & compiler independent, use the standard 'C' shift and mask (bitwise-AND) operators; To be possibly quicker and use less code, use a union or pointers. It's all been discussed many times before - try a search...
well, i think i can provide what actually i want here. i'm actually writing a servo motor code. for -1 it would be FFFF in hex. So, i'm thinking of to write a function that when i'm key in -1 it will return a hexadecimal FFFF to me. the i can extract this FFF into FF and FF so that FF can be stored in TH0 and FF can be stored in TL0. That's my problems. Thank u for replying me Neil..i'm appreciate ur help!
Take a look at the input functions in the standard C library. strtoul(), strtol(), scanf(), atoi(). The bit pattern for -1 in a 16-bit twos-complement integer is 1111111111111111 The bit pattern for 0xFFFF is 1111111111111111 The value is a matter of interpretation by the programmer; the processor does not care. Human-readable (and -writable) format is a matter for the I/O routines.