Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 04, 2016, 03:12:43 15:12


Login with username, password and session length


Pages: [1]
Print
Author Topic: need help to converting BCD data  (Read 826 times)
0 Members and 1 Guest are viewing this topic.
sohel
Senior Member
****
Offline Offline

Posts: 437

Thank You
-Given: 140
-Receive: 124



WWW
« on: March 10, 2014, 09:50:59 21:50 »

Dear all,

I am working on countdown timer with RTC ds12887 and at89s51. RTC give me sec value in BCD format.

MOV A,#00H        ;READ SECONDS
LCALL READ_RTC
MOV 40H,A                    ;Store sec Value

how can i convert in reverse like that


00 to 00
01 to 59
02 to 58
03 to 57
04 to 56
..... continue to 00 to 00

Regard's
 Cry



« Last Edit: March 10, 2014, 09:54:24 21:54 by sohel » Logged

A Thousand Miles Journey Start With a Single Step<br />http://www.youtube.com/user/masud58
FriskyFerretReloaded2
Junior Member
**
Offline Offline

Posts: 86

Thank You
-Given: 230
-Receive: 214



« Reply #1 on: March 10, 2014, 11:41:23 23:41 »

Did you want help with the algorithm or did you want someone to write the 8051 assembler code for you?
Logged
TucoRamirez
Senior Member
****
Offline Offline

Posts: 277

Thank You
-Given: 197
-Receive: 95


Tuco ... dead or Alive


« Reply #2 on: March 10, 2014, 11:43:22 23:43 »

implement if readvalue= 0  then readvalue=60 and do ( 60 - var) ... otherwise lazy fuctard solution could be     "create a lut organized backwards :p "
« Last Edit: March 11, 2014, 06:38:39 06:38 by TucoRamirez » Logged

Whoever double crosses me and leaves me alive... he understands nothing about Tuco.
solutions
Hero Member
*****
Offline Offline

Posts: 1446

Thank You
-Given: 590
-Receive: 851



« Reply #3 on: March 11, 2014, 01:59:36 01:59 »

Why do you need to count down?

What are you doing with the result?

Is it always the same period?

Not enough info on the application - you may be trying to do something you don't  have to, or there may be a shortcut using BCD ADDITION and a RTC compare

@tucoramirez - that wasn't a very nice thing to say

"lazy fuctard solution"

 Grin
Logged
hate
Hero Member
*****
Offline Offline

Posts: 556

Thank You
-Given: 156
-Receive: 354


« Reply #4 on: March 11, 2014, 05:22:11 05:22 »

Code:
MOV A,#00H   ;READ SECONDS
LCALL READ_RTC
MOV 40H,A                    ;Store sec Value

RR A        ; Rotate A to the right 4 times
RR A
RR A
RR A
ANL A, #0Fh        ; Get low nibble
MOV B, #0Ah       ; Load decimal 10 into B
MUL AB               ; Multiply A and B
MOV R0, A           ; Save A to R0
MOV A, 40h         ; Load BCD again
ANL A, #0Fh        ; Get low nibble
ADD A, R0           ; Add (high nibble *10) to low nibble namely A=high*10+low
Accumulator 'A' will have your BCD converted to binary. You can then do whatever you want with it. I'm rusty with 8051 assembler so the code might not work but I think you got the idea.
Logged

Regards...
sohel
Senior Member
****
Offline Offline

Posts: 437

Thank You
-Given: 140
-Receive: 124



WWW
« Reply #5 on: March 11, 2014, 05:33:01 05:33 »

Thanks to all,

i want to implement this calculation, result should be BCD.

60 - 01 = 59

99 - 01 = 98
98 + 60 = 158
158 - 99 = 59
Logged

A Thousand Miles Journey Start With a Single Step<br />http://www.youtube.com/user/masud58
hate
Hero Member
*****
Offline Offline

Posts: 556

Thank You
-Given: 156
-Receive: 354


« Reply #6 on: March 11, 2014, 06:04:36 06:04 »

I thought you wanted to convert BCD output to binary as you wrote:
RTC give me sec value in BCD format.

I still don't get what you're trying to achieve!
Thanks to all,

i want to implement this calculation, result should be BCD.

60 - 01 = 59

99 - 01 = 98
98 + 60 = 158
158 - 99 = 59
Which of these numbers come in BCD? All? None? Some, which ones? Do you only need to convert the results to BCD? If the latter, check the thread below that has an example code which converts binary to BCD. Or be more clear pls.
Logged

Regards...
bigtoy
Active Member
***
Offline Offline

Posts: 152

Thank You
-Given: 127
-Receive: 197


« Reply #7 on: March 22, 2014, 08:52:39 20:52 »

If you have the room, use a look-up table. For an 8-bit number the table would be 256 bytes long.
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC