Thread: Sending Hex

  1. #1
    Registered User
    Join Date
    Dec 2015
    Posts
    5

    Sending Hex

    I'm new to C programming, and I want to send a hex code(38h 00111000) to 8 pins (on a parallax propeller micro-controller) so that the first pin gets a 0 , and the next pin gets a 0 and the next pin gets a 1 , etc. This would be easier then
    sending a binary code to each pin. The propeller uses low for a '0' and high for a '1'.
    I hope that’s clear, sorry for my poorly worded post.
    By the way this is for C code. The code I'm using so far, that works by using binary is:



    Code:
    //int port[] = {27,26,25,24,23,22,21,20};    
        int i = 8;
     
        while(i >0)
        {       //while start
        --i;  
        low(27);
        low(26);
        high(25);
        high(24);
        high(23);
        low(22);
        low(21);
        low(20);
        }
    What I want to do is send a single hex code (38) to pins 20 to 27.
    Thank you

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    I am unfamiliar with this device, and some quick research indicates that it does not follow the more standard conventions of microcontrollers.

    Ordinarily, you would be able to assign a single value to a port, and each of the pins of that port would update according to their bit position.

    For instance, on an 8-bit device:

    Code:
    PORTA = 0x3A;
    
    // Port A, pin 7 = 0
    // Port A, pin 6 = 0
    // Port A, pin 5 = 1
    // Port A, pin 4 = 1
    // Port A, pin 3 = 1
    // Port A, pin 2 = 0
    // Port A, pin 1 = 1
    // Port A, pin 0 = 0
    You didn't tell us what specific device you're using, but a manual for one of the devices shows that all 32 I/O pins are grouped into a single port ("Port A"). So with the above approach, a single assignment to Port A would update all 32 I/O pins.

    If you only wanted to update 8 pins at once, then the solution would be to write a simple function that receives a value and updates the pins of interest based on the value it receives. Then you can update that group of 8 pins with a single function call.

    The same manual I referenced tells you where to find their discussion forums. If you're working with this device a lot, you might want to ask questions related to the specific device there, since the people there will be more familiar with this specific hardware and architecture.

  3. #3
    Registered User
    Join Date
    Dec 2015
    Posts
    5
    Thank you for your reply.
    There is only 1 propeller at this time although the prop 2 should be out within a year.
    I did find the answer myself, see below
    Code:
    set_outputs	(23, 16, 0XF0);
    All you said was correct and thank you again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with TCP sending
    By CoximusPrime in forum C Programming
    Replies: 12
    Last Post: 07-03-2012, 03:03 PM
  2. sending on tcp
    By jamesford in forum Networking/Device Communication
    Replies: 15
    Last Post: 03-31-2010, 08:10 AM
  3. sending commands
    By DeepFyre in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-13-2006, 01:19 PM
  4. Sending key...
    By Nephiroth in forum Windows Programming
    Replies: 1
    Last Post: 02-14-2006, 05:44 PM
  5. Sending and getting ID
    By publikum in forum Windows Programming
    Replies: 1
    Last Post: 02-02-2005, 04:23 PM

Tags for this Thread