- avr16_V120.zip
- avr16
- build.dep
- adc.P
- applic.P
- dbgext.P
- debugger.P
- delay.P
- eeprom.P
- fpga_cfg.P
- fpgassi.P
- kernel.P
- Motor.P
- robolayer.P
- serapp.P
- Timer0.P
- typeconv.P
- Uart.P
- xcs_cfg.P
- build.err
- build.lst
- adc.lst
- applic.lst
- dbgext.lst
- debugger.lst
- delay.lst
- eeprom.lst
- fpga_cfg.lst
- fpgassi.lst
- kernel.lst
- kernel.map
- Motor.lst
- robolayer.lst
- serapp.lst
- Timer0.lst
- typeconv.lst
- Uart.lst
- xcs_cfg.lst
- build.obj
- adc.o
- applic.o
- dbgext.o
- debugger.o
- delay.o
- eeprom.o
- fpga_cfg.o
- fpgassi.o
- kernel.elf
- kernel.o
- kernel.obj
- Motor.o
- robolayer.o
- serapp.o
- Timer0.o
- typeconv.o
- Uart.o
- xcs_cfg.o
- build.rom
- kernel.eep
- kernel.rom
- cfg
- compile.in
- compileflags.in
- env.in
- hw.in
- srcobj.in
- swdef.in
- kernel_elf.aps
- kernel_elf.aws
- license.txt
- makefile
- src
- applic
- debug
- includes
- periphext
- periphint
- Utils
|
/***************************************************************************
Project: AVRILOS
Title: Type conversion functions
Author: Ilias Alexopoulos
Version: 2.00
Last updated: 28-Oct-2010
Target: NA
File: typeconv.c
* Support E-mail:
* avrilos@ilialex.gr
*
* license: See license.txt on root directory (CDDL)
*
* DESCRIPTION
* Type conversion used to avoid stdio functions for lower footprint
*
***************************************************************************/
#include "../includes/types.h"
#include "../includes/settings.h"
static INT8 lut_Hex[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
/*********************************************************************
* Function: void f_BinHex(INT8U bin_in, INT8 *str_out)
* Convert binary number to ASCII Hex
* Input:
* bin_in: input byte to convert to string ASCII
* Output:
* str_out: pointer to output string. Outputs two chars.
**********************************************************************/
void f_BinHex(INT8U bin_in, INT8 *str_out)
{
*(str_out+0) = lut_Hex[(bin_in >> 4) & 0x0f];
*(str_out+1) = lut_Hex[bin_in & 0x0f];
}
/*********************************************************************
* Function: void f_BinHex(INT8U bin_in, INT8 *str_out)
* Convert binary number to ASCII Hex
* Input:
* bin_in: input byte to convert to string ASCII
* Output:
* str_out: pointer to output string. Outputs two chars.
**********************************************************************/
void f_BinHexWord(INT16U bin_in, INT8 *str_out)
{
// static INT8 lut_Hex[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
*(str_out+0) = lut_Hex[(bin_in >> 12)& 0x0f];
*(str_out+1) = lut_Hex[(bin_in >> 8) & 0x0f];
*(str_out+2) = lut_Hex[(bin_in >> 4) & 0x0f];
*(str_out+3) = lut_Hex[(bin_in >> 0) & 0x0f];
}
/*********************************************************************
* Function: INT16U f_HexBin(INT8 *hex_in)
* Convert ASCII Hex to binary number
* Input:
* hex_in: Input hex string to convert to word
* Output:
* return value of 16-bits (short int)
**********************************************************************/
INT16U f_HexBin(INT8 *hex_in)
{
INT16U data = 0;
INT8U i;
INT8 cbyte;
for(i=0; i<4; i++)
{
cbyte = *(hex_in+i);
if ( cbyte >= 'A') cbyte = (cbyte - 'A') + 10;
else cbyte-= '0';
data |= (cbyte << (4*(3-i)));
}
return data;
}
/*********************************************************************
* Function: INT8U f_HexBinByte(INT8 *hex_in)
* Convert ASCII Hex to binary number
* Input:
* hex_in: Input hex string to convert to byte
* Output:
* return value of 8-bits (byte)
**********************************************************************/
INT8U f_HexBinByte(INT8 *hex_in)
{
INT8U data = 0;
INT8U i;
INT8 cbyte;
for(i=0; i<2; i++)
{
cbyte = *(hex_in+i);
if ( cbyte >= 'A') cbyte = (cbyte - 'A') + 10;
else cbyte-= '0';
data |= (cbyte << (4*(1-i)));
}
return data;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
More than 15 year of Embedded Systems development designing both hardware & software.
Experience with Product Development,lab prototypes and Automated Testers, Sensors, motors and System Engineering. Have used numerous micro-controllers/processors, DSP & FPGAs.
Please check
AI ZeroCaliber if you need any help.
You may find also my personal site:
Ilialex and my blog site:
Ilialex Blog