Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
April 19, 2024, 01:36:27 01:36


Login with username, password and session length


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

Posts: 442

Thank You
-Given: 167
-Receive: 149



« 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
FriskyFerretReloaded2
Junior Member
**
Offline Offline

Posts: 82

Thank You
-Given: 232
-Receive: 208



« 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: 307

Thank You
-Given: 257
-Receive: 115


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: 1823

Thank You
-Given: 655
-Receive: 900



« 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
*****
 Warned
Offline Offline

Posts: 555

Thank You
-Given: 156
-Receive: 355


« 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: 442

Thank You
-Given: 167
-Receive: 149



« 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
hate
Hero Member
*****
 Warned
Offline Offline

Posts: 555

Thank You
-Given: 156
-Receive: 355


« 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: 238

Thank You
-Given: 322
-Receive: 297


« 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