How to print byte as binary string to gLCD?
-
- Posts: 2
- Joined: Fri Jan 29, 2010 6:19 am
How to print byte as binary string to gLCD?
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!
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!
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: How to print byte as binary string to gLCD?
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 2
- Joined: Fri Jan 29, 2010 6:19 am
Re: How to print byte as binary string to gLCD?
Thank you very much! I got it to work!
I will search answers from this forum about that temperature probe.
I will search answers from this forum about that temperature probe.

-
- Posts: 5
- Joined: Sun Sep 26, 2010 11:12 am
- Has thanked: 2 times
Re: How to print byte as binary string to gLCD?
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.
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.
-
- Posts: 594
- Joined: Thu Sep 17, 2009 7:52 am
- Location: Belgium
- Has thanked: 63 times
- Been thanked: 102 times
Re: How to print byte as binary string to gLCD?
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 :
The second method is setting "test[0]" as LSB and "test[7]" as MSB :
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))
Code: Select all
char i;
char byte = 0;
for (i = 7; i >= 0; i--)
byte = ((byte << 1) | (test[i] != 0))
-
- Posts: 5
- Joined: Sun Sep 26, 2010 11:12 am
- Has thanked: 2 times
Re: How to print byte as binary string to gLCD?
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?
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?
-
- Posts: 594
- Joined: Thu Sep 17, 2009 7:52 am
- Location: Belgium
- Has thanked: 63 times
- Been thanked: 102 times
Re: How to print byte as binary string to gLCD?
Sure, here you go.darkmagic35 wrote:Can you give me please an example of one method directly in Flowcode?
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 651 times
Re: How to print byte as binary string to gLCD?
Hi,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.
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
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: How to print byte as binary string to gLCD?
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
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 352 times
Martin
Re: How to print byte as binary string to gLCD?
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
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 (26.44 KiB) Viewed 8782 times
-
- Valued Contributor
- Posts: 2045
- Joined: Wed Aug 27, 2008 10:31 pm
- Location: Netherlands
- Has thanked: 553 times
- Been thanked: 1081 times
Re: How to print byte as binary string to gLCD?
Is this homework/assignment for a computer course?
“Integrity is doing the right thing, even when no one is watching.”
― C.S. Lewis
― C.S. Lewis
Re: How to print byte as binary string to gLCD?
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
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