How to print byte as binary string to gLCD?

For E-blocks user to discuss using E-blocks and programming for them.

Moderators: Benj, Mods

Frequnator
Posts: 2
Joined: Fri Jan 29, 2010 6:19 am
Contact:

How to print byte as binary string to gLCD?

Postby Frequnator » Mon Feb 01, 2010 10:56 am

Hi!

I have studied how to program with flowcode couple months now. I have 2 questions and I cannot find answers...

I have tried to find answer how to print i.e. number "2" (byte variable) as binary string like "00000010". I can change numbers to hex and print those to LCD just fine but I don't know how to print binary strings.

Case is this: I try to send 8-bit information via zigbee from end-node to coordinator and I would like to see that information on coordinators gLCD (like "1001011") but when I print that information to gLCD flowcode converts automatically that binary information to a number. I collect that "binary information" with 8-button switch board and send that information with zigbee send_char -macro. On coordinator I receive that information with zigbee receive_char and print that out to gLCD. How can I convert that character to binary string and print that 8-bit sting out?

Other problem is how to convert temperature infomation (byte 0-255 or int 0-1024) to normal understandable celcius float number. I have not yet tried to calibrate my temperature sensor, if I measure readings with boiling water (+100C) and result is i.e 223 (byte 0-255), how can I transfer that byte to understandable 100.0 like with normal digital thermometers?

I'm using Flowcode V4.2, E-Blocks with PIC16F877A and compatible e-blocks hardware. I read temperature information with e-blocks sensor board analog input.

Thank you all for answers!

User avatar
Benj
Matrix Staff
Posts: 13989
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4253 times
Been thanked: 4008 times
Contact:

Re: How to print byte as binary string to gLCD?

Postby Benj » Mon Feb 01, 2010 1:15 pm

Hello

To print a byte out as a binary number you will have to create a little loop to do the following.


while loop with a count of 8 in the properties.

calculation x = byte & 0x01

if x

yes: print a '1'

no: print a '0'

calculation byte = byte >> 1

end while

Regarding reading the thermistor or temperature sensor there are example of how to do this already available from the forum.

Frequnator
Posts: 2
Joined: Fri Jan 29, 2010 6:19 am
Contact:

Re: How to print byte as binary string to gLCD?

Postby Frequnator » Tue Feb 02, 2010 7:53 am

Thank you very much! I got it to work!

I will search answers from this forum about that temperature probe. :)

darkmagic35
Posts: 5
Joined: Sun Sep 26, 2010 11:12 am
Has thanked: 2 times
Contact:

Re: How to print byte as binary string to gLCD?

Postby darkmagic35 » Sun Dec 05, 2010 12:42 pm

Hello Benj,

I have 8 sources which can be TRUE (1) or FALSE (0), I save this 8 values to a string (test[8]) and I need to get a byte variable.

Can you give me examle how to convert this string (8 chars) to a byte? (1010 0001 -> 0xA1)

Thank you for your answers.

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: How to print byte as binary string to gLCD?

Postby Spanish_dude » Sun Dec 05, 2010 8:20 pm

Hey darkmagic35,

There are two ways to do this.

The first one is setting "test[0]" as MSB (Most Significant Bit) and "test[7]" as LSB :

Code: Select all

char i;
char byte = 0;

for (i = 0; i < 8; i++)
    byte = ((byte << 1) | (test[i] != 0))


The second method is setting "test[0]" as LSB and "test[7]" as MSB :

Code: Select all

char i;
char byte = 0;

for (i = 7; i >= 0; i--)
    byte = ((byte << 1) | (test[i] != 0))

darkmagic35
Posts: 5
Joined: Sun Sep 26, 2010 11:12 am
Has thanked: 2 times
Contact:

Re: How to print byte as binary string to gLCD?

Postby darkmagic35 » Mon Dec 06, 2010 9:06 am

Thank you for your answear.

I tried to rewrite this code to flowcode but I wasn't successful. (I copy your C code to flowcode and modife variables and than I try to do this with flowcode's graphics components).

Can you give me please an example of one method directly in Flowcode?

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: How to print byte as binary string to gLCD?

Postby Spanish_dude » Mon Dec 06, 2010 10:12 am

darkmagic35 wrote:Can you give me please an example of one method directly in Flowcode?


Sure, here you go.

ConvertStringToByte sets test[0] as MSB and ConvertStringToByte2 sets test[7] as MSB.

Rgds,

Nicolas L. F.

EDIT:
- Forgot to add what's written in bold.
Attachments
Flowcode1.fcf
(6.5 KiB) Downloaded 369 times
These users thanked the author Spanish_dude for the post:
darkmagic35 (Mon Dec 06, 2010 10:22 am)
Rating: 5.88%
 

Jacob1
Posts: 35
Joined: Wed Dec 27, 2017 4:18 pm
Has thanked: 7 times
Been thanked: 6 times
Contact:

Re: How to print byte as binary string to gLCD?

Postby Jacob1 » Wed Dec 27, 2017 4:42 pm

Benj wrote:Hello

To print a byte out as a binary number you will have to create a little loop to do the following.


while loop with a count of 8 in the properties.

calculation x = byte & 0x01

if x

yes: print a '1'

no: print a '0'

calculation byte = byte >> 1

end while

Regarding reading the thermistor or temperature sensor there are example of how to do this already available from the forum.


Hi,

I was wondering if you could explain what byte represents from this info? Do I need to create a variable?
As I am trying to create the loop and unsure of what icons to use. Do I need any outputs? If you have this loop on file that would be really useful,

I am trying to create a program which when a switch is pressed it shows the binary number on the LCD and lights up the corresponding LED. If you know how to do this or can give me a example that would be great,

Thanks

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8236
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2359 times
Been thanked: 3347 times
Contact:

Re: How to print byte as binary string to gLCD?

Postby medelec35 » Wed Dec 27, 2017 7:53 pm

Hi Jacob1,
Can you see if attached flowchart works for you?
If it does help, I can take you though how it works if you get stuck

Martin
Attachments
Switch in Binary.fcfx
(14.23 KiB) Downloaded 52 times
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

Jacob1
Posts: 35
Joined: Wed Dec 27, 2017 4:18 pm
Has thanked: 7 times
Been thanked: 6 times
Contact:

Re: How to print byte as binary string to gLCD?

Postby Jacob1 » Fri Dec 29, 2017 3:21 pm

Hi Medlec,

Thanks for taking the time to complete a example!

However, I think that program is a bit different to the example you have given me. I am following a micro controller booklet, which gives a broad brief about what to do for each program. I think the program wants the binary number as in the 8 bit, such as 0000 0001. So as each switch is pressed, the 1 will move across. The program also asks for this "binary number" to be multiplied by 100, and for the LCD to show this on the next line

I have attached the program instructions below, and I would appreciate it if you could have a look at this.

Thanks for your help
Jacob
Attachments
Program.JPG
Program.JPG (26.44 KiB) Viewed 2018 times

kersing
Valued Contributor
Valued Contributor
Posts: 1873
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 530 times
Been thanked: 1040 times
Contact:

Re: How to print byte as binary string to gLCD?

Postby kersing » Fri Dec 29, 2017 6:05 pm

Is this homework/assignment for a computer course?
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

Jacob1
Posts: 35
Joined: Wed Dec 27, 2017 4:18 pm
Has thanked: 7 times
Been thanked: 6 times
Contact:

Re: How to print byte as binary string to gLCD?

Postby Jacob1 » Fri Dec 29, 2017 6:38 pm

Hi,

This is a booklet which we follow for my college course, it is not homework or an assignment. As the course is a new spec, this is what we follow for lessons as we have nothing else! The programs can be completed at home in our free time. Our teacher works from this as well but is also very new to this.

Hope that makes sense