Prepare a custom byte

Hi everybody! Last week i contact an e-farm that produce a software for touch-screen controller
that farm give me a link for use your software with arduino but i have a problem trasmitting byte
the information byte have to follow this directive http://www.touch-base.com/documentation/controller%20support.htm
someone can help me with the serial.write?

UP!!

What's the problem?

sorry for my bad english but in italian section anyone help me, the problem is that i have to prepare a custom byte how i have to do for exemple i have to divide 10 bit on 2 byte but in a specific order how i have to do, and how i have to send it to pc?

I have had a look at the data sheet link but it is not clear exactly what custom byte you want to prepare.

In general you always send bytes back to the PC by using the serial.print() command either one byte at a time or as a string. The string is what you see as a number on the screen. In your case I suspect you want to just sent the byte as a character.

If you want to build up a byte from something else you have to use "bit manipulation", this involves using OR operations to set bits in the byte you want and AND operations to clear (set to zero) bits you don't want. For example suppose you want a byte called fred to contain just the 3 least significant bits of a byte called val you would mask off the bits you want with a mask of 1's in the places you wanted the bits to stay the same and zeros in the bits you wanted to be zero. Do it like this:-
fred = val & 0x07;
The mask is 0x07 and fred just contains what ever bits val had in the bits where the mask had a one.

The other trick is to use the shift operation << for shift left and >> for shift right.
Suppose you had an int (two bytes) called join and two bytes called big and small. You want to make the int join have big in the 8 most significant bits and small in the 8 least significant bits. You shift one byte up by 8 places and or the two values together like:-
join = (big << 8) | small;

But as I say it is not clear what byte or bytes you want to make and what you want to make them from.

thanks a lot but i'm not skilled in bit manipulation however i have to prepare a status byte as u can see from data sheet that i have posted
and make the first bit of data packet egual to 0 can anyone help me? i have the right program that return int value now whit this value we have to prepare custom packet like datasheet required and then we have a crazy arduino touch controller!!

The problem is that the data sheet is complex and I do not know what you are wanting in your custom byte and where this information is coming from. Assuming that it is this table you want to use:-

For new controllers under development we have the following comments regarding packet structure:
Generally speaking we are able to configure any given packet structure within our driver as we are able to define the packet structure at individual bit level so normally we expect to be informed of the packet structure implemented in the controller and we then define it as appropriate. However, for readers wanting advice as to a suitable packet structure, here is a example 12 bit packet structure that offers a status byte and 2 bytes per x and Y co-ordinate:

Bit 1 2 3 4 5 6 7 8
Byte 0 1 0 T 0 0 0 0 0
Byte 1 0 X6 X5 X4 X3 X2 X1 X0
Byte 2 0 0 0 X11 X10 X9 X8 X7
Byte 3 0 Y6 Y5 Y4 Y3 Y2 Y1 Y0
Byte 4 0 0 0 Y11 Y10 Y9 Y8 Y7

Where T =1 when touching and 0 when untouch is detected.

Bits should be labelled 0 to 7 not 1 to 8 and they are the wrong way round but assuming it is just this labelling that is wrong and you have your X & Y & T values in variables called X, Y and T then:-
B0 = 0x80 | (( T & 0x1)<< 5);
B1 = X & 0x7F;
B2 = (X >> 6) & 0x1F;
B3 = Y & 0x7F;
B4 = (Y >> 6) & 0x1F;

thanks a lot i'm sure that your solution it is good but i don't understand anything can u give me a good book or a good link were i can learn more about manipulation?

Well I did explain it in the last post but look at:-
http://www.arduino.cc/playground/Code/BitMath

thanks a lot fro your patience i have read the link but i don't still understand the expression:

0x80 or 0x7F

what means?

If you write out 0x80 and 0x7f as binary, it will make it easier to visualise:

0x80 = 1000 0000
0x7F = 0111 1111

The truth table for the OR operation is:

0 0 | 0
0 1 | 1
1 0 | 1
1 1 | 1

so
1000 0000
OR 0111 1111

1111 1111

= 0xFF

In "C" the prefix 0x specifies that a number is expressed in hexidecimal, or base 16.
Hexidecimal values are the digits 0-9 followed by A-F as follows:

Decimal             Hexidecimal   Binary
===========   =======   ======
0             0x00      0000
1             0x01      0001
2             0x02      0010
3             0x03      0011
4             0x04      0100
5             0x05      0101
6             0x06      0110
7             0x07      0111
8             0x08      1000
9             0x09      1001
10            0x0A      1010
11            0x0B      1011
12            0x0C      1100
13            0x0D      1101
14            0x0E      1110
15            0x0F      1111

thanks a lot now i understand