Page 1 of 1

RS232 and values of 255

Posted: Sun Jun 24, 2007 11:44 pm
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

Posted: Mon Jun 25, 2007 9:50 am
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 )

Posted: Mon Jun 25, 2007 12:10 pm
by Ron
Hi,

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

Thanks

Ron