+ Post New Thread
Results 1 to 19 of 19

14th March 2016, 04:34 #1
 Join Date
 Jan 2010
 Posts
 210
 Helped
 2 / 2
 Points
 2,239
 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 03:02. Reason: added microcontroller tag

14th March 2016, 16:54 #2
 Join Date
 May 2015
 Location
 127.0.0.1
 Posts
 212
 Helped
 82 / 82
 Points
 1,866
 Level
 10
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, 16:54

14th March 2016, 17:38 #3
 Join Date
 Oct 2011
 Location
 Tallinn, Estonia
 Posts
 1,476
 Helped
 332 / 332
 Points
 8,220
 Level
 21
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:53 #4
 Join Date
 May 2015
 Location
 127.0.0.1
 Posts
 212
 Helped
 82 / 82
 Points
 1,866
 Level
 10
Re: help splitting Hex Result to 3 seperated Values
1 members found this post helpful.

14th March 2016, 21:21 #5
 Join Date
 Jan 2010
 Posts
 210
 Helped
 2 / 2
 Points
 2,239
 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, 21:21

14th March 2016, 21:46 #6
Awards:
 Join Date
 Jul 2009
 Location
 Aberdyfi, West Wales, UK
 Posts
 11,413
 Helped
 3779 / 3779
 Points
 69,847
 Level
 64
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, 00:34 #7
Awards:
 Join Date
 Apr 2014
 Posts
 11,399
 Helped
 2653 / 2653
 Points
 56,092
 Level
 57
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, 04:59 #8
 Join Date
 Jan 2010
 Posts
 210
 Helped
 2 / 2
 Points
 2,239
 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 8bit binary ;Input: w ;Output: w ;RAM:2 ;Cycles: 1224 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 8bit 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 8bit 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 04:47.

15th March 2016, 04:59

15th March 2016, 10:05 #9
Awards:
 Join Date
 Jul 2009
 Location
 Aberdyfi, West Wales, UK
 Posts
 11,413
 Helped
 3779 / 3779
 Points
 69,847
 Level
 64
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 16bit 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, 10:09 #10
 Join Date
 Oct 2011
 Location
 Tallinn, Estonia
 Posts
 1,476
 Helped
 332 / 332
 Points
 8,220
 Level
 21
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, 10:48 #11
 Join Date
 Jan 2010
 Posts
 210
 Helped
 2 / 2
 Points
 2,239
 Level
 10

15th March 2016, 16:40 #12
 Join Date
 Jan 2010
 Posts
 210
 Helped
 2 / 2
 Points
 2,239
 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 8bit binary ;Input: w ;Output: w ;RAM:2 ;Cycles: 1224 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 8bit 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 8bit 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, 17:08 #13
 Join Date
 Nov 2012
 Posts
 2,505
 Helped
 586 / 586
 Points
 13,460
 Level
 27
Re: binary to BCD convert routine fix help
An 8bit unsigned integer has a range of 0255. This can be represented in three BCD digits.
I did not understand your code.
Let x is the number to be converted.
xx/10 will give you the remainder; this is the least significant BCD digit.
Let x > x/10;
xx/10 will give the middle BCD digit.
Let x > x/10;
xx/10 will be the most significant BCD digit.

15th March 2016, 17:17 #14
 Join Date
 Dec 2015
 Location
 Madrid, Spain
 Posts
 1,046
 Helped
 252 / 252
 Points
 5,832
 Level
 18

15th March 2016, 17:27 #15
 Join Date
 Nov 2012
 Posts
 2,505
 Helped
 586 / 586
 Points
 13,460
 Level
 27

15th March 2016, 18:10 #16
 Join Date
 Jan 2010
 Posts
 210
 Helped
 2 / 2
 Points
 2,239
 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, 18:50 #17
 Join Date
 Nov 2006
 Location
 Brazil
 Posts
 7,763
 Helped
 959 / 959
 Points
 25,760
 Level
 39
 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, 20:03 #18
Awards:
 Join Date
 Jul 2009
 Location
 Aberdyfi, West Wales, UK
 Posts
 11,413
 Helped
 3779 / 3779
 Points
 69,847
 Level
 64
re: Splitting Hex Result to 3 seperated Values [PIC]
... and work out what you really want as a result.
In 8bit 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 10bit 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.

15th March 2016, 20:03

16th March 2016, 01:15 #19
 Join Date
 Jan 2010
 Posts
 210
 Helped
 2 / 2
 Points
 2,239
 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: ; 11397 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