Page 1 of 1

How to print byte as binary string to gLCD?

Posted: Mon Feb 01, 2010 10:56 am
by Frequnator
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!

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

Posted: Mon Feb 01, 2010 1:15 pm
by Benj
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.

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

Posted: Tue Feb 02, 2010 7:53 am
by Frequnator
Thank you very much! I got it to work!

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

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

Posted: Sun Dec 05, 2010 12:42 pm
by darkmagic35
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.

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

Posted: Sun Dec 05, 2010 8:20 pm
by Spanish_dude
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))

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

Posted: Mon Dec 06, 2010 9:06 am
by darkmagic35
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?

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

Posted: Mon Dec 06, 2010 10:12 am
by Spanish_dude
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.

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

Posted: Wed Dec 27, 2017 4:42 pm
by Jacob1
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

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

Posted: Wed Dec 27, 2017 7:53 pm
by medelec35
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

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

Posted: Fri Dec 29, 2017 3:21 pm
by Jacob1
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

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

Posted: Fri Dec 29, 2017 6:05 pm
by kersing
Is this homework/assignment for a computer course?

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

Posted: Fri Dec 29, 2017 6:38 pm
by Jacob1
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