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.

How to convert unsinged binary 8bit to decimal to use in MSP430 microcontrollers

Status
Not open for further replies.

patan.gova

Full Member level 3
Full Member level 3
Joined
Dec 19, 2011
Messages
172
Helped
4
Reputation
8
Reaction score
0
Trophy points
1,296
Visit site
Activity points
2,776
How to convert unsinged binary 8bit to decimal in MSP430 microcontrollers

Hello,
I am working with MSP430 microcontroller to read a analog input using a ADC12 channel and the result obtained will a 8/10/12 bit unsigned binary according to the chosen resolution.
But how to convert the 8 or 10 or 12 bit binary into decimal value.

Can someone help me this conversion and the datasheet is attached below where in page580 it is described about the ADC12 conversion result(i.e, of 8/10/16 bit).
Thanks in Advance.View attachment CC430 User's Guide.pdf
 

ADC12MEMx register contains the ADC conversion results. In 12-bit mode bit 0 to bit 11 contains the ADC result and bit 12 to bit 15 are 0. Just assign the register value to a unsigned int variable or float variable.
 

Perhaps you are looking for something like that :

Code:
int Char3Dig[3] ; 
void ConvertNum3dec( int num )
{
   int dig;
   dig = num / 100 + '0';
   if ( dig == 0 ) Char3Dig[0] = ' ' ;
     else Char3Dig[0] = dig ;
   dig = (num % 100) / 10 + '0';
   Char3Dig[1] = dig ;
   dig = (num % 10) + '0';
   Char3Dig[2] = dig ;
}

+++
 
  • Like
Reactions: PA3040

    PA3040

    Points: 2
    Helpful Answer Positive Rating
@jayanth.devarayanadurga: You mean assigning like this unsigned int result=ADC12MEMx;

But what is the difference between the two solutions.
 

andre_teprom showed you to convert the value to characters for displaying on LCD or UART. ADC12MEMx contains the ADC conversion result and if 12 bit is choosen then result is 12 bit. So, you have to assign it to a 16 bit variable like unsigned int. If you assign it to say a variable adcres then you can pass this adcres to andre_teprom's function to extract each digit of the adcres and convert them into characters for displaying.

Remember in ADC12MEMEx, x is variable. x can have different values. Read datasheet. Maybe it has different registers for different ADC channels.
 

Hoped this help to understand the core operation
Code:
bin_to_dec clrf    hundred
                clrf    ten
                clrf    one
hundred_loop    movlw    .100
                subwf    voltage,w
                btfss    status,0
                goto    ten_loop
                incf    hundred
                movwf    voltage
                goto     hundred_loop

ten_loop    movlw    .10
                subwf    voltage,w
                btfss    status,0
                goto    one_loop
                incf    ten
                movwf    voltage
                goto    ten_loop
                   

one_loop  movlw    .1
                subwf    voltage,w
                btfss    status,0
                return
                incf    one
                movwf    voltage
                goto    one_loop
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top