Sending 16 bit values, 8 bits at a time

Discussion in 'Embedded Systems and Microcontrollers' started by Guinness1759, Jun 10, 2011.

  1. Guinness1759

    Thread Starter Member

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

    Code ( (Unknown Language)):
    1.  
    2.  
    3. volatile unsigned char temp1[2], temp2[2], temp3[2], temp4[2];
    4.  
    5. I've tried,
    6.  
    7. putch(temp1);
    8. putch(temp1+1);
    9.  
    10. and
    11.  
    12. putch(&temp1);
    13. putch(&temp1+1);
    14.  
    15.  
    The putch function puts the serial data out. The putch function works when I manually put the values in, so no problem there.
     
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    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
    Code ( (Unknown Language)):
    1. {
    2. typedef union
    3. unsigned short counter;
    4. signed char hilo_bytes[2];
    5. } clock_register;
    6. clock_register clock;
    7. // play with variable clock
    8. void main()
    9. {clock.counter = 0xffff;
    10. TMR1L = clock.hilo_bytes[0];
    11. TMR1H = clock.hilo_bytes[1];
    12. //some time alter
    13. clock.hilo_bytes[0]=TMR1L;
    14. clock.hilo_bytes[1]=TMR1H;
    15. //Now the variable clock.counter will contain the TMR1 value read above
    16. }
     
    Guinness1759 likes this.
  3. nigelwright7557

    Senior Member

    May 10, 2008
    487
    71
    putch(temp1);
    putch(temp1+1);

    Try:
    putch(temp1[0]);
    putch(temp1[1]);
     
    Guinness1759 likes this.
  4. Guinness1759

    Thread Starter Member

    Dec 10, 2010
    64
    0

    Thanks, that worked, I can't believe I didn't notice it before. :eek:
     
Loading...