Thread: converting a string into binary for data transfer

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    399
    This can easily be generalized to an entire string:
    Code:
    uint8_t text[] = "Hello";
    uint8_t i;
    uint8_t *p = &text[0];
    
    /* Transmit the first character. */
    for (i = 0; i < 8; ++i)
    {
        /* Wait for next edge */
        if ((uint8_t)(1 << i) & *p)
        {
            OUT_PORT |= 1 << PIN_NUMBER;
        }
        else
        {
            OUT_PORT &= ~(1 << PIN_NUMBER);
        }
    }
    You can replace the for loop with a static counter if you need to do the sending inside an ISR.
    Last edited by Memloop; 10-15-2010 at 02:06 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Converting a binary string to hex
    By maxhavoc in forum C++ Programming
    Replies: 6
    Last Post: 07-25-2006, 12:46 PM
  2. RicBot
    By John_ in forum C++ Programming
    Replies: 8
    Last Post: 06-13-2006, 06:52 PM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. Converting a string to binary
    By laasunde in forum C++ Programming
    Replies: 11
    Last Post: 07-01-2003, 11:16 AM
  5. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 11:06 PM