Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] conversion of hexadecimal to decimal code in 8051 embedded c

Status
Not open for further replies.

vattipalli

Junior Member level 1
Joined
Oct 13, 2010
Messages
18
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,404
hi,
my work is to read data from temperature sensor which is interfaced to 8051, i can read it but to display it , i need to convert hexadecimal to decimal, plz any one give some info how i can convert it and display it.
 

Dear friend,

If you are using mikroc ,then

Bcd2Dec16(unsigned bcdnum);
 

I have posted a thread about converting hex value to BCD(decimal value). Just check that thread. The code is included in it....
Regards,
Jerin. ;-)
 

// to initialize adc.
#include <compiler_defs.h>
#include <c8051f930_defs.h>
#include <math.h>

void Timer_Init()
{
TCON = 0x40;
TMOD = 0x20;
TH1 = 0x96;
}

void UART_Init()
{
SCON0 = 0x10;
}

void OSC_INIT(void)
{
FLSCL = 0x40;
OSCICN = 0x8f;
CLKSEL = 0x00;
}
void PORT_INIT(void)
{
//port initialization.
P0MDOUT = 0x10;
P1MDOUT = 0x15;
P2MDOUT = 0x04;
XBR0 = 0x01;
XBR1 = 0x42;
XBR2 = 0x40;
}

void Send_Char0( unsigned char Data)
{

SBUF0 = Data;
while(!(SCON0 & 0x02));
SCON0 &= 0xFD;
}

void ADC_INIT(void)
{
//adc initialization.
ADC0MX = 0x1b;
ADC0CF = 0xc1;
ADC0CN = 0x80;
REF0CN = 0x14;
}
void sys_init(void)
{
Timer_Init();
UART_Init(); //sys intialization.
OSC_INIT();
PORT_INIT();
ADC_INIT();
}



void main(void)
{
unsigned int d1 = 0, d2 = 0, d3 = 0, d4 = 0,read_h = 0x00;
unsigned int x = 0,y = 0;
unsigned char Data = 0x00;

PCA0MD &= ~0x40;
sys_init();


AD0BUSY = 1;
while(1)
{
if(AD0BUSY == 1)
//TO START ADC CONVERSION.

read_h = ADC0H; // adc data in hexadecimal
x = read_h;
// decimal conversion
d1 = x / 100;
x = x % 100;
d2 = x / 10;
x = x % 10;
d3 = x;


P0 = d1;
P1 = d2;

Data = (unsigned char)(P0);
Send_Char0(Data);

}
}
plz check my code once. i am getting junk(symbols).
 

Which compiler have you used? I have done my code in MikroC.......
Regards,
Jerin.
 

c8051f920 silicon labs microcontroller. keil compiler
 

Haven't used that....... :(
You want the conversion of adc hex value to decimal rite?
Store the 10 bit value to a variable of integer type & do the divide operation as explained in the code.
Regards,
Jerin.

---------- Post added at 08:22 ---------- Previous post was at 08:17 ----------

https://www.edaboard.com/threads/191227/
Check out this link.
Regards,
Jerin.
 

thanks jerin....its working...
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top