a very noob question -_-

Discussion in 'Programmer's Corner' started by Macabra, Sep 21, 2008.

  1. Macabra

    Thread Starter Active Member

    May 31, 2008
    49
    0
    Hello! :)

    It's been ages since I've done programming and I can't remember how to do conversions of data types. I'm using UART to transmit data through the serial RS232 but the function to do so only takes int...

    void putsUART1(unsigned int *buffer) __attribute__ ((section (".libperi")));

    void WriteUART1(unsigned int data) __attribute__ ((section (".libperi")));

    so I can send integers that's fine but how do I do it if I want to print character strings?? :confused: something like "hello world"?

    Oh right and this is in C by the way!
    much thanks
     
    Last edited: Sep 21, 2008
  2. Papabravo

    Expert

    Feb 24, 2006
    10,145
    1,791
    There are at least two ways to do it, yielding slightly different results.

    1. You can print the least significant byte (LSB) of each integer
    OR
    2. You can print the the least significant byte (LSB), followed by the next most significant byte until the entire integer has been rendered as characters.

    Which alternative did you have in mind?
     
  3. Macabra

    Thread Starter Active Member

    May 31, 2008
    49
    0
    guess I go for number 1, how would I go into doing that? :confused:
     
  4. Papabravo

    Expert

    Feb 24, 2006
    10,145
    1,791
    Ok, you fetch a character from a string and apply an explicit cast.

    Code ( (Unknown Language)):
    1.  
    2. unsigned char TestString[] = "Test String" ;
    3.  
    4. void foo(void)
    5. {
    6. ....
    7.     p = &TestString[0] ;
    8.     while(*p != '\0')
    9.     {
    10.         WriteUART1( (unsigned int) *p++) ;
    11.     }
    12. ....
    13. }
    14.  
     
Loading...