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.

hex to dec conversion(16 bit) on microcontroller interfaced with adc

Status
Not open for further replies.

pamulapati alekya

Newbie level 3
Joined
Jan 18, 2012
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,305
hi,

can anybody help in giving me the working link of hex to decimal coversion on a micro controller...

and can you say what is the difference between this program when it is used for 16 bit and 8 bit seperatly.?

regards.
 

Here is the Conversion Logic:-

Code:
temp = MYDATA * 2;    //MYDATA is the data coming from the PORT of the Controller to which your ADC of 8bit is connected
        //Conversion Process Starts Here       
            ones = temp%10;
            temp = temp/10;
            tens = temp%10;
            hundreds = temp/10;
And to display it on LCD just add 0x30H to each it will make it ASCII value..
If u don't understand then inform us..
We will try to help u properly...


You can see the Example at the following link... Voltmeter using AT89C51

ADC Interfacing - MATLAB ACADEMY

If u are using a controller of 10-Bit inbuilt ADC as in PIC

u can use the following logic...
Code:
//Here ADRESL stores lower bytes and ADRESH stores Higher Bytes
                adc_data = ADRESH & 0x00FF;
		adc_data = adc_data<<8;
		adc_data = adc_data | ADRESL;
Hope this assist u..
 
Here is the Conversion Logic:-

Code:
temp = MYDATA * 2;    //MYDATA is the data coming from the PORT of the Controller to which your ADC of 8bit is connected
        //Conversion Process Starts Here       
            ones = temp%10;
            temp = temp/10;
            tens = temp%10;
            hundreds = temp/10;

I think there is a mistake here. The code should be:
Code:
temp = MYDATA;    //MYDATA is the data coming from the PORT of the Controller to which your ADC of 8bit is connected
        //Conversion Process Starts Here       
            ones = temp%10;
            temp = temp/10;
            tens = temp%10;
            hundreds = temp/10;

Let's say that MYDATA holds the value 249. In the code you provided, temp = 249 * 2 = 498 (provided temp is a 16-bit register, or atleast ≧ 9 bits). Then, ones = 8, tens = 9, hundreds = 4.
But, in my code, temp = MYDATA = 249. Ones = 9, tens = 4, hundreds = 2.

Hope this helps.
Tahmid.
 
Last edited:
Yes Tahmid u are absolutely right..

Actually that was a copy paste code from the site MATLAB ACADEMY...

and in that code they are making a voltmeter using ADC... that's why they require to multiply the data by 2 (exactly 1.953)..

But yes u right..
It is my mistake to put that code at that post..
Sorry..Dear
 

What language do you want, C or Assembly?
Do you want full 16-bit to BCD or will 12-bit do for you?

I have a fairly thick folder of such routines in Assembly copied from others. The one I am currently using is 12-bit by Peter Hemsley (PicList) and that works well for most A/D converters. There are many other options. If you want to see some of the options, go to PicList and search on Radix in conversions (PIC Microcontoller Radix Math Methods ).

John
 

could you please explain me the logic behind 0*30h..
as we however need to display on lcd by ascii values...
 

To display 1 in integer on LCD, you have to send 0x31 its ascii code..
That's why
0 ----- > 0x30
1 ----- > 0x31
2 ----- > 0x32
3 ----- > 0x33
4 ----- > 0x34
5 ----- > 0x35
6 ----- > 0x36
7 ----- > 0x37
8 ----- > 0x38
9 ----- > 0x39

or u just OR (|) your result with 0x30...


This is all done to display data on LCD..
 

we are doing it in assembly level language. on 8 bit adc of 16 channel but using only two channels for giving input other all channels are left opened.

---------- Post added at 07:29 ---------- Previous post was at 07:27 ----------

we are doing it in assembly level language in serial mode. on 8 bit adc of 16 channel but using only two channels for giving input other all channels are left opened. did this code works for this one.. :!: because it seems like c language.
 

we are doing it in assembly level language. on 8 bit adc of 16 channel but using only two channels for giving input other all channels are left opened.

---------- Post added at 07:29 ---------- Previous post was at 07:27 ----------

we are doing it in assembly level language in serial mode. on 8 bit adc of 16 channel but using only two channels for giving input other all channels are left opened. did this code works for this one.. :!: because it seems like c language.

It won't work for you because it's in C. Do as jpanhalt has said and you can find the assembly routines.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top