Sending 16 bit values, 8 bits at a time

Thread Starter

Guinness1759

Joined Dec 10, 2010
64
So I have four 16 bit temperature values, and I need to send them 8 bits at a time to ustart.

Rich (BB code):
volatile unsigned char temp1[2], temp2[2], temp3[2], temp4[2];

I've tried,

putch(temp1);
putch(temp1+1);

and

putch(&temp1);
putch(&temp1+1);
The putch function puts the serial data out. The putch function works when I manually put the values in, so no problem there.
 

t06afre

Joined May 11, 2009
5,934
Use a Union. And define union(s) as 16 integer and a 2 byte array. That should do the trick.
here is an example. It is from one my threads in this forum. I am going to bed now. but I hope you understand
Rich (BB code):
{ 
typedef union 
unsigned short counter;
signed char hilo_bytes[2]; 
} clock_register;
clock_register clock;
// play with variable clock 
void main()
{clock.counter = 0xffff;
TMR1L = clock.hilo_bytes[0]; 
TMR1H = clock.hilo_bytes[1];
//some time alter
clock.hilo_bytes[0]=TMR1L; 
clock.hilo_bytes[1]=TMR1H;
//Now the variable clock.counter will contain the TMR1 value read above 
}
 
Top