Binary word serial output

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
graemec
Posts: 11
Joined: Thu Dec 24, 2009 10:26 pm
Contact:

Binary word serial output

Post by graemec »

Hi,

I'd be grateful for any advice.

I need to output a 40 bit word serially from a single port.
I have figured out a way to do it that works but it seems very wasteful and inefficient.
What I've done is represent the 40 bit word as a string array (which uses up 40 bytes instead of 5 bytes) and then output each byte of the array in turn.
There must be a more direct way of outputting a binary number sequentially (LSB first) just can't find it / figure it out.

If you can help!

Thanks

G

User avatar
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: Binary word serial output

Post by Benj »

Hello G,

Could you do it like this.

Create a byte variable in the variable manager called output[5].

Then assign your binary value by passing in byte constants or variables.

output[0] = 0x5A
output[1] = byte1

Or you can simply clear the variable and then set the bits which need to be logic 1.

output[0] = 0
output[0] = 1 << 4
output[0] = 1 << 7

Once you have the data inside the 5 bytes you should be able to create a loop to stream out the values starting with the LSb from byte 0 and ending with the MSb from byte 4.

Code: Select all

while (byteindex < 5)
{
	innerindex = 0
	while (innerindex < 8)
	{
		if (output[byteindex] & (0x01 << innerindex))
			Yes: Output 1 to Port Pin
			No: Output 0 to Port Pin
		delay_ms(1)
		innerindex = innerindex + 1
	}
	byteindex = byteindex + 1
}

graemec
Posts: 11
Joined: Thu Dec 24, 2009 10:26 pm
Contact:

Re: Binary word serial output

Post by graemec »

Thanks Ben, I'll give that a try.
Regards
Graeme

Post Reply