Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsElectronicsBasicsRepairDesignCADComponentsEquipmentElectrical Engineering
ElectronicsKB.com
Contact UsLink To UsSearch & Site Map

Electronics Forum / Basics / November 2006



Tip: Looking for answers? Try searching our database.

8051 Programming

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
luisdanielsilva@gmail.com - 12 Nov 2006 19:40 GMT
I need to convert a 32 bit binary number to gray code. i know how to do
it bit by bit, but i need to do a function to do it, so that i don't
need to repeat code 32 times. Can anybody help me?

Thanks

LDS
Arlet - 12 Nov 2006 19:44 GMT
luisdanielsi...@gmail.com wrote:

> I need to convert a 32 bit binary number to gray code. i know how to do
> it bit by bit, but i need to do a function to do it, so that i don't
> need to repeat code 32 times. Can anybody help me?

>From binary to gray code is easy.

in C: gray = binary ^ (binary >> 1)

The reverse operation takes more effort.
luisdanielsilva@gmail.com - 12 Nov 2006 19:57 GMT
Thanks but i'm doing this in assembler, and i want to do it bit by bit,
not all the bits at once.

> luisdanielsi...@gmail.com wrote:
>
[quoted text clipped - 7 lines]
>
> The reverse operation takes more effort.
Brendan Gillatt - 12 Nov 2006 20:15 GMT
> Thanks but i'm doing this in assembler, and i want to do it bit by bit,
> not all the bits at once.
[quoted text clipped - 9 lines]
>>
>> The reverse operation takes more effort.

Have a look here:
http://forum.microchip.com/tm.aspx?m=96826&mpage=1&key=&#97243

It's for a PIC but I'm sure it will be easy to convert.

| Brendan Gillatt                        |
|  brendan {at} brendan \removethis// gillatt {dot} co {dot} uk |
|      http://www.brendangillatt.co.uk                |
| PGP Key: pgp.mit.edu:11371/pks/lookup?op=get&search=0x6E265E61|
petrus bitbyter - 13 Nov 2006 00:34 GMT
>I need to convert a 32 bit binary number to gray code. i know how to do
> it bit by bit, but i need to do a function to do it, so that i don't
[quoted text clipped - 3 lines]
>
> LDS

Mmm... It's quite some time I wrote 8051 assembler, but if memory serves
it's done like this:

num1 equ 64
num2 equ 65
num3 equ 66
num4 equ 67

clr c
mov a,num1
rlc a
xrl a,num1
mov a,num2
rlc a
xrl a,num2
mov a,num3
rlc a
xrl a,num3
mov a,num4
rlc a
xrl a,num4
end

petrus bitbyter
petrus bitbyter - 14 Nov 2006 21:12 GMT
>>I need to convert a 32 bit binary number to gray code. i know how to do
>> it bit by bit, but i need to do a function to do it, so that i don't
[quoted text clipped - 28 lines]
>
> petrus bitbyter

Oops,

Memory fails. The next code should be correct:
num1 equ 64
num2 equ 65
num3 equ 66
num4 equ 67

clr c
mov a,num1
rlc a
xrl num1,a
mov a,num2
rlc a
xrl num2,a
mov a,num3
rlc a
xrl num3,a
mov a,num4
rlc a
xrl num4,a
end

petrus bitbyter
Ken Smith - 29 Nov 2006 15:41 GMT
>I need to convert a 32 bit binary number to gray code. i know how to do
>it bit by bit, but i need to do a function to do it, so that i don't
>need to repeat code 32 times. Can anybody help me?

If you are doing this in assembly, the these ideas will help you.

32 bits fits into 4 bytes.  You want 2 nested loops to do the process.

R0 or R1 can be used to work your way down the bytes as you process.

There is no XRL C,XXX instruction.  If you want a little speed, you want
two copies of the inner workings.  One for when you are complimenting bits
and one for when you aren't.  If your input values happen to be near zero,
you can also include special code for skipping the unused part of the
field.

Signature

--
kensmith@rahul.net   forging knowledge

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.