Page 1 of 1

DEC to BIN

Posted: Mon Oct 29, 2012 11:18 pm
by badir79
Hi Everyone!!! I guess this topic already exist, but I just can´t find it in my quick search...

Well, I need some help. How i can convert decimal numbers into binary numbers and show them on a display? In other words, how i can decompose a single byte into their bits and manipulate them?

Thanks a lot for helping me!!! :D

Re: DEC to BIN

Posted: Tue Oct 30, 2012 12:17 am
by Enamul
Hi,
You can try the following code...

Re: DEC to BIN

Posted: Tue Oct 30, 2012 12:41 am
by badir79
Enamul, thank you very much for your help... But I can´t open it because this file was made in Flowcode V5 I guess, and I only have Flowcode V4; please, can you give it to me in V4, or post an image of the flowchart to see what can I do... Thanks!!!

Re: DEC to BIN

Posted: Tue Oct 30, 2012 12:46 am
by Enamul
Here it is...

Re: DEC to BIN

Posted: Tue Oct 30, 2012 1:06 am
by badir79
Enamul, this is just what I was looking for... Thank you very much!!!

Re: DEC to BIN

Posted: Fri Nov 02, 2012 3:56 pm
by badir79
Hi,
Now I need to convert single bits from one port pin into a byte... How can I do that? how can I do this inverse process?

Re: DEC to BIN

Posted: Fri Nov 02, 2012 4:45 pm
by Enamul
This one is not so simple like earlier one..what will be the bit rate in that port..Will you allowed to interrupt to detect 1. Is that a continuous transmission or single byte transmission? I have made a program for you but need to tune depending on these Q/A.

Re: DEC to BIN

Posted: Fri Nov 02, 2012 5:13 pm
by badir79
Thank you Enamul, let me see... this is for a serial comunication at a baud rate of 10400 bps, so, the time bit is about 96 micro-seconds. I was thinking in an interrupt, but I need to evaluate that, because in this proyect there will be just one bidireccional comm line, so I will have one pin for TX and one for RX, but due to the interface design, every time I send a bit by the TX port, it reflects in the RX port, so, I'm not sure at this moment an interrupt would work properly for this case. Another thing to consider is that it will need to detect start bit and stop bit. Start bit= '0',/ Byte bits,/ Stop bit ='1'.
Thanks alot for your help Enamul, if you need another detail please ask me... Thanks!!!

Re: DEC to BIN

Posted: Fri Nov 02, 2012 5:18 pm
by Enamul
Ok..In that case you can simply use RS232 and that's most easy to deal with. If you don't have hardware RS232 in PIC still you can use software RS232.

Re: DEC to BIN

Posted: Fri Nov 02, 2012 5:40 pm
by badir79
Thank you very much Enamul, I will try it with RS232 component...

Re: DEC to BIN

Posted: Sat Nov 10, 2012 12:21 am
by badir79
Hello! This is another issue that I have at this moment... I have an hexadecimal value in a string, this is an address for a external EEPROM, from this value, I need to get the memory's high and low addresses , then I need to send these string values as individual bytes via i2c, but, I can't send it as string, so I use the function BYTE = StringToInt (STRING)

Example1:

String 0x47E
String_H = 04
BYTE1 = StringToInt (String_H)
BYTE1= 4

String_L = 7E
BYTE2 = StringToInt (String_L)
BYTE2 = 7

Bytes sent via i2c: 0107, but I need to send 017E

Example2:

String 0x190
String_H = 01
BYTE1 = StringToInt (String_H)
BYTE1= 1

String_L = 90
BYTE2 = StringToInt (String_L)
BYTE2 = 90

Bytes sent via i2c: 015A, but I need to send 0190

So, the addresses sent are not equals to the addresses that I need to send. How can I convert these bytes to hex numbers, or, how can I keep the same value of these strings?

Thanks a lot for helping me!!!

Re: DEC to BIN

Posted: Sat Nov 10, 2012 9:56 am
by Enamul
Hi,
First of all you can declare an INT variable for the address. In calculation box, just put your hex value in that variable and then simply you have to split that into low and high byte.
Address=0x47E
BYTE_L =Address AND 0x00FF
BYTE_H =Address >> 8
Hope this helps.

Re: DEC to BIN

Posted: Sat Nov 10, 2012 9:14 pm
by badir79
Enamul, I tried that and it works great!!!

Thank you very much!!!

Re: DEC to BIN

Posted: Sat Nov 10, 2012 10:45 pm
by Enamul
Glad to know that it worked.