+ Post New Thread

Results 1 to 19 of 19

- 14th March 2016, 05:34 #1

- Join Date
- Jan 2010
- Posts
- 208
- Helped
- 2 / 2
- Points
- 2,201
- Level
- 10

## Splitting Hex Result to 3 seperated Values [PIC]

hello Guys

i Need to split An HEX value which i've got it from ADC as a result To seperated values to drive 3 7segment's in Assembly Language

For Example(got 0x65 which means 101 So i want to get 1 and 0 and 1 in seperated Variables)

i've searched alot of confusing tutorials about assembly Dividing ways But i've got more confused

and BTW what is the ADRESL and ADRESH of ADC converter ?

thx for helpLast edited by andre_teprom; 15th March 2016 at 04:02. Reason: added microcontroller tag

- 14th March 2016, 17:54 #2

- Join Date
- May 2015
- Location
- 127.0.0.1
- Posts
- 192
- Helped
- 74 / 74
- Points
- 1,531
- Level
- 8

## Re: help splitting Hex Result to 3 seperated Values

ADRESL is the low byte (8 least significant bits) or the ADC value

The high byte is the ADRESH.

You can use division and modulo or

use loop with subtraction (with 100 till <=99 to find hundreds digit, with 10 till <=9 to find decs digit and the rest will be the last digit) or

you can search for conversion from int to bcd and send values to 7segs.

- 14th March 2016, 18:38 #3

- Join Date
- Oct 2011
- Location
- Tallinn, Estonia
- Posts
- 1,219
- Helped
- 285 / 285
- Points
- 6,833
- Level
- 19

## Re: help splitting Hex Result to 3 seperated Values

Basicaly, he needs an value to string converter

But have not enought words to say thatLove me or hate me. All infractions will be ignored.

1 members found this post helpful.

- 14th March 2016, 18:38

- 14th March 2016, 19:53 #4

- Join Date
- May 2015
- Location
- 127.0.0.1
- Posts
- 192
- Helped
- 74 / 74
- Points
- 1,531
- Level
- 8

## Re: help splitting Hex Result to 3 seperated Values

1 members found this post helpful.

- 14th March 2016, 22:21 #5

- Join Date
- Jan 2010
- Posts
- 208
- Helped
- 2 / 2
- Points
- 2,201
- Level
- 10

## Re: help splitting Hex Result to 3 seperated Values

yes right that's wht im looking for but how to do tht in assembly ?

thx Guys

- - - Updated - - -

i've found alot of methods to do it but it didnt work

- 14th March 2016, 22:46 #6

Awards:

- Join Date
- Jul 2009
- Location
- Aberdyfi, West Wales, UK
- Posts
- 10,041
- Helped
- 3214 / 3214
- Points
- 60,444
- Level
- 60

## Re: help splitting Hex Result to 3 seperated Values

Assuming from the ADC register names you are using a PIC, I think this will help:

http://www.piclist.com/techref/micro...adix/index.htm

Brian.PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.

It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.

- 15th March 2016, 01:34 #7

- Join Date
- Apr 2014
- Posts
- 7,354
- Helped
- 1791 / 1791
- Points
- 36,092
- Level
- 46

## Re: help splitting Hex Result to 3 seperated Values

Hi,

For hundreds: subtract 100 as long as the value is larger than 100. Loopcounter = hundreds

The rest: subtract 10 as long as the value us karger than 10. Loopcounter = tens

Rest: = units.

Klaus

- 15th March 2016, 05:59 #8

- Join Date
- Jan 2010
- Posts
- 208
- Helped
- 2 / 2
- Points
- 2,201
- Level
- 10

## Re: help splitting Hex Result to 3 seperated Values

can u plz send me an example plz?

- - - Updated - - -

im reading the microchip app note about math routines right now

- - - Updated - - -

i've fonnd a routine which is wht i need but its not working as it must do

would you plz help me to fix it ?

im not tht good with math

Code:;This routine will return the number of decimal ;hundreds from an 8-bit binary ;Input: w ;Output: w ;RAM:2 ;Cycles: 12-24 movlw 0xFB GETHNDS movwf t1 clrf w2 gethnds_loop movlw .100 incf w2,f subwf t1,f btfsc STATUS,C goto gethnds_loop decf w2,w movwf Hunds goto GETTENS ;--- ;This routine will return the number of decimal ;tens from an 8-bit binary ;Loop based, so it might take some time... ;It needs getones too GETTENS movwf t1 clrf w2 gettens_loop movlw .10 incf w2,f subwf t1,f btfsc STATUS,C goto gettens_loop decf w2,w movwf Tens goto GETONES ;--- ;This routine will return the number of decimal ;ones from an 8-bit binary GETONES movwf w2 movlw .10 deltens_loop subwf w2,f btfsc STATUS,C goto deltens_loop addwf w2,w movwf Ones return

im woring on it now hope to understand wht the problem is

- - - Updated - - -

The GETHnds routine loop run twice & get the right values then it is do it for third time & the w is 3 then decreased by one but the t1 is 0xCF now

what is the risponsible of effecting STATUS ?

plz HelpLast edited by janosandi; 15th March 2016 at 05:47.

- 15th March 2016, 05:59

- 15th March 2016, 11:05 #9

Awards:

- Join Date
- Jul 2009
- Location
- Aberdyfi, West Wales, UK
- Posts
- 10,041
- Helped
- 3214 / 3214
- Points
- 60,444
- Level
- 60

## re: Splitting Hex Result to 3 seperated Values [PIC]

If you are using ADRESH and ADRESL it would appear you are not using the correct methods. The result will be 10 bits wide (2 in ADRESH and 8 in ADRESL) so you should be using routines for the next highest multiple of bits, in this case 16. You need a 16-bit binary to 4 digit BCD converter. That should convert all values between zero (000 BCD) to 0x3FF (1023 BCD).

Brian.PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.

It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.

- 15th March 2016, 11:05

- 15th March 2016, 11:09 #10

- Join Date
- Oct 2011
- Location
- Tallinn, Estonia
- Posts
- 1,219
- Helped
- 285 / 285
- Points
- 6,833
- Level
- 19

## re: Splitting Hex Result to 3 seperated Values [PIC]

You can use 'left alligment' and get result from ADRESH only. It will be 8 bit, but no noise suppression will be needed. It is a fast way to work with ADC if 8 bit is enought.

Love me or hate me. All infractions will be ignored.

- 15th March 2016, 11:48 #11

- Join Date
- Jan 2010
- Posts
- 208
- Helped
- 2 / 2
- Points
- 2,201
- Level
- 10

- 15th March 2016, 17:40 #12

- Join Date
- Jan 2010
- Posts
- 208
- Helped
- 2 / 2
- Points
- 2,201
- Level
- 10

## binary to BCD convert routine fix help

i was looking for a solution to seperate HEX value into 3 digits to use it in my program

& i dont know about numbers & finally i've got it i need binary to bcd converter routine in my code & have found a simple one & the method is easy but its not working

i've tried to fix it but i couldnt

any help will b appriciated

Code:;This routine will return the number of decimal ;hundreds from an 8-bit binary ;Input: w ;Output: w ;RAM:2 ;Cycles: 12-24 movlw 0xFB clrf Hunds clrf Tens clrf Ones clrf t1 GETHNDS movwf t1 clrf w2 gethnds_loop movlw .100 incf w2,f subwf t1,f btfsc STATUS,C goto gethnds_loop decf w2,w movwf Hunds goto GETTENS ;--- ;This routine will return the number of decimal ;tens from an 8-bit binary ;Loop based, so it might take some time... ;It needs getones too GETTENS movwf t1 clrf w2 gettens_loop movlw .10 incf w2,f subwf t1,f btfsc STATUS,C goto gettens_loop decf w2,w movwf Tens goto GETONES ;--- ;This routine will return the number of decimal ;ones from an 8-bit binary GETONES movwf w2 movlw .10 deltens_loop subwf w2,f btfsc STATUS,C goto deltens_loop addwf w2,w movwf Ones return

- 15th March 2016, 18:08 #13

- Join Date
- Nov 2012
- Posts
- 1,748
- Helped
- 374 / 374
- Points
- 9,262
- Level
- 23

## Re: binary to BCD convert routine fix help

An 8-bit unsigned integer has a range of 0-255. This can be represented in three BCD digits.

I did not understand your code.

Let x is the number to be converted.

x-x/10 will give you the remainder; this is the least significant BCD digit.

Let x -> x/10;

x-x/10 will give the middle BCD digit.

Let x -> x/10;

x-x/10 will be the most significant BCD digit.

- 15th March 2016, 18:17 #14

- Join Date
- Dec 2015
- Location
- Madrid, Spain
- Posts
- 460
- Helped
- 93 / 93
- Points
- 2,455
- Level
- 11

- 15th March 2016, 18:27 #15

- Join Date
- Nov 2012
- Posts
- 1,748
- Helped
- 374 / 374
- Points
- 9,262
- Level
- 23

- 15th March 2016, 19:10 #16

- Join Date
- Jan 2010
- Posts
- 208
- Helped
- 2 / 2
- Points
- 2,201
- Level
- 10

## Re: binary to BCD convert routine fix help

& i need a solution in assembly i know the method but how to do it in assemly ?

- 15th March 2016, 19:10

- 15th March 2016, 19:50 #17

- Join Date
- Nov 2006
- Location
- Rio de Janeiro, Brazil
- Posts
- 6,654
- Helped
- 809 / 809
- Points
- 21,723
- Level
- 35
- Blog Entries
- 5

## Re: binary to BCD convert routine fix help

--------------------------------------------------------------------------------------------------

Part of the world that you live in, You are the part that you're giving ( Renaissance )

1 members found this post helpful.

- 15th March 2016, 21:03 #18

Awards:

- Join Date
- Jul 2009
- Location
- Aberdyfi, West Wales, UK
- Posts
- 10,041
- Helped
- 3214 / 3214
- Points
- 60,444
- Level
- 60

## re: Splitting Hex Result to 3 seperated Values [PIC]

... and work out what you really want as a result.

In 8-bit mode the result can be 00000000 to 11111111 which is 0x00 to 0xFF in hexdecimal (two digits) or 0 to 255 in decimal which is three digits.

In 10-bit mode the result can be 0000000000 to 1111111111 which is 0x000 to 0x3FF in hexadecimal (three digits) or 0 to 1023 in decimal which is four digits.

The same principle applies, count how many times you can remove the decimal weight for the digit and when your result is zero or less, start counting how many time you can remove the next lower decimal weight*FROM THE REMAINING VALUE.*

Brian.PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.

It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.

1 members found this post helpful.

- 16th March 2016, 02:15 #19

- Join Date
- Jan 2010
- Posts
- 208
- Helped
- 2 / 2
- Points
- 2,201
- Level
- 10

## Re: Splitting Hex Result to 3 seperated Values [PIC]

i've found another routine at microchip's application Notes but again its not working

any one can help with this ?

as i guess it must work

Code:; ;******************************************************************** ; Binary To BCD Conversion Routine ; ; This routine converts the 8 bit binary number in the W Register ; to a 2 digit BCD number. ; The least significant digit is returned in location LSD and ; the most significant digit is returned in location MSD. ; ; Performance : ; Program Memory : 10 ; Clock Cycles : 81 (worst case when W = 63 Hex ) ; ( i.e max Decimal number 99 ) ; ; Program: BIN8BCD.ASM ; Revision Date: ; 1-13-97 Compatibility with MPASMWIN 1.40 ; ;******************************************************************* ; LSD equ 10 MSD equ 11 ; call main ; BinBCD clrf MSD movwf LSD gtenth movlw .10 subwf LSD,W BTFSS STATUS,C goto over movwf LSD incf MSD, F goto gtenth over retlw 0 ;******************************************************************* ; main movlw 63 ; W reg = 63 Hex call BinBCD ; after conversion, MSD = 9 & LSD = 9 self goto self ; ( 63 Hex = 99 Decimal ) ; org 1FF goto main ; END

im working on the code again with the instruction set trying to understand how it works line by line

thx Guys

- - - Updated - - -

i've found the problem with this code of microchip which its my fault

it was for 16c54 & im using 16f877 & i've changed LSD & MSD files to 20 & 21 & now its doing what its supposed to do

thx Guys All

John

- - - Updated - - -

what i was looking for was wrong so i need binary to Decimal converter not bcd

the binary to BCD 2 digits its ok now & im working on the second one now

thx

John

+ Post New Thread

Please login