📄 bcd.c
字号:
// This file has been prepared for Doxygen automatic documentation generation.
/*! \file ********************************************************************
*
* Atmel Corporation
*
* - File : BCD.c
* - Compiler : IAR EWAAVR 4.11a
*
* - Support mail : avr@atmel.com
*
* - Supported devices : All devices with a UART/USART can be used.
* The example is written for ATmega169
*
* - AppNote : AVR323 - Interfacing GSM modems
*
* - Description : Example of how to use AT-Commands to control a GSM modem
*
* $Revision: 1.1 $
* $Date: Tuesday, November 08, 2005 12:25:32 UTC $
*****************************************************************************/
/*****************************************************************************
*
* Function name : CHAR2BCD2
*
* Returns : Binary coded decimal value of the input (2 digits)
*
* Parameters : Value between (0-99) to be encoded into BCD
*
* Purpose : Convert a character into a BCD encoded character.
* The input must be in the range 0 to 99.
* The result is byte where the high and low nibbles
* contain the tens and ones of the input.
*
*****************************************************************************/
char CHAR2BCD2(char input)
{
char high = 0;
while (input >= 10) // Count tens
{
high++;
input -= 10;
}
return (high << 4) | input; // Add ones and return answer
}
/*****************************************************************************
*
* Function name : CHAR2BCD3
*
* Returns : Binary coded decimal value of the input (3 digits)
*
* Parameters : Value between (0-255) to be encoded into BCD
*
* Purpose : Convert a character into a BCD encoded character.
* The input must be in the range 0 to 255.
* The result is an integer where the three lowest nibbles
* contain the ones, tens and hundreds of the input.
*
*****************************************************************************/
unsigned int CHAR2BCD3(char input)
{
int high = 0;
while (input >= 100) // Count hundreds
{
high++;
input -= 100;
}
high <<= 4;
while (input >= 10) // Count tens
{
high++;
input -= 10;
}
return (high << 4) | input; // Add ones and return answer
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -