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.

Help me write a program to decode 8 bit number to 3 BCD one

Status
Not open for further replies.

semiconductor

Full Member level 4
Joined
Apr 4, 2003
Messages
236
Helped
4
Reputation
8
Reaction score
0
Trophy points
1,296
Activity points
2,735
I need your help!

I'm writing a program to decode a 8 bit number (from 0 to 255) to 3 BCD-number for AT89C51 (3 BCD-numbers is put out at P1 and 4 high bits of P2.

For example: 122 (xxxxxxxx - 8-bit number) <--> 0001 0010 0010

But I haven't finished it yet. Can someone help me? The algorithm or some recommends to help me!

Thank you beforehand!
 

Re: I need your help!

are you working in c or assembly?
 

Re: I need your help!

semiconductor said:
For example: 122 (xxxxxxxx - 8-bit number) <--> 0001 0010 0010

An ideea,

You have a number, say x=122 (decimal)...
You need some scratchpad bytes...
hi, mid, lo

while(x>=100)
{
x-= 100;
hi++;
}
while(x>=10)
{
x-=10;
mid++;
}
lo=x;
After that, put hi, mid and lo where you want :)
That's C, you can use the ideea in asm, too :)

Cheers !
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top