Main Page | Data Structures | File List | Data Fields | Globals

ATAVRBFLY_FILES/BCD.c

Go to the documentation of this file.
00001 // This file has been prepared for Doxygen automatic documentation generation. 00023 /***************************************************************************** 00024 * 00025 * Function name : CHAR2BCD2 00026 * 00027 * Returns : Binary coded decimal value of the input (2 digits) 00028 * 00029 * Parameters : Value between (0-99) to be encoded into BCD 00030 * 00031 * Purpose : Convert a character into a BCD encoded character. 00032 * The input must be in the range 0 to 99. 00033 * The result is byte where the high and low nibbles 00034 * contain the tens and ones of the input. 00035 * 00036 *****************************************************************************/ 00037 char CHAR2BCD2(char input) 00038 { 00039 char high = 0; 00040 00041 00042 while (input >= 10) // Count tens 00043 { 00044 high++; 00045 input -= 10; 00046 } 00047 00048 return (high << 4) | input; // Add ones and return answer 00049 } 00050 00051 /***************************************************************************** 00052 * 00053 * Function name : CHAR2BCD3 00054 * 00055 * Returns : Binary coded decimal value of the input (3 digits) 00056 * 00057 * Parameters : Value between (0-255) to be encoded into BCD 00058 * 00059 * Purpose : Convert a character into a BCD encoded character. 00060 * The input must be in the range 0 to 255. 00061 * The result is an integer where the three lowest nibbles 00062 * contain the ones, tens and hundreds of the input. 00063 * 00064 *****************************************************************************/ 00065 unsigned int CHAR2BCD3(char input) 00066 { 00067 int high = 0; 00068 00069 while (input >= 100) // Count hundreds 00070 { 00071 high++; 00072 input -= 100; 00073 } 00074 00075 high <<= 4; 00076 00077 while (input >= 10) // Count tens 00078 { 00079 high++; 00080 input -= 10; 00081 } 00082 00083 return (high << 4) | input; // Add ones and return answer 00084 }

Generated on Tue Nov 1 16:21:39 2005 for AVR323 Interfacing GSM modems by doxygen 1.3.7