RS232 and values of 255

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
Ron
Posts: 225
Joined: Wed Apr 11, 2007 6:15 pm
Has thanked: 2 times

RS232 and values of 255

Post by Ron »

Hi,

I am working on some RS232 code and I have found that I need to be able to send/receive values that exceed a BYTE value of 255.

For example, I will send the computer 1900.

1) How do you "break" apart 1900 into into 2 BYTES to send it to the PC.

The computer will send 1900 to PIC.

2) How do I assemble the 2 BYTEs received from the computer so it becomes 1900.

3) I also need to be able to store the received 2 BYTEs as BYTES in EEPROM of the PIC then read out the 2 BYTES and assemble then back to INT. My guess this is the same #2 but want to be sure.

It has been my experience that there is often many ways to do anything when it comes to programming. I am looking for a way using the standard Flowcode blocks, if possible.

Thanks,


Ron

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:

Post by Benj »

Hello

An integer variable is essentially a 16bit variable. Eg 2 bytes.

To send a value like 1900 then you can do the following.

Create a INT variable and assign a value to it.

create to byte variables.

byte1 = int & 0xFF
byte2 = ( int >> 8 ) & 0xFF

then you can transmit the byte1 and byte2. Remember that byte 1 is the least significant byte.

To receive a INT variable via two bytes you can do the following.

int = byte1
int = int + ( byte2 << 8 )

Ron
Posts: 225
Joined: Wed Apr 11, 2007 6:15 pm
Has thanked: 2 times

Post by Ron »

Hi,

This is great.........

Thanks

Ron

Post Reply