This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

LPc2294+TCP

Hallo,

I have a question to the topic ethernet.
I have look at the exmaple LEDswitch Client and I don't understand why I need the following code:
..
U8 p2val, cnt, lshf;
..
p2val = 1; cnt = 0; lshf = 1;
...
send_data(p2val);
p2val = lshf ? (p2val << 1) : (p2val >> 1);
if (p2val == 0x80) lshf = 0;
if (p2val == 0x01) lshf = 1;

I don't find anything in the help from keil for what p2val stand and why I to hand this on my funktion send_data? Can something explain it.

Parents
  • Without looking at the specific example:

    p2val - Port 2 value, i.e. intended value for the port.

    It gets shifted left step by step until the bit has moved to the most significant bit. Then lshf gets toggled and p2val gets shifted right until it is back at the first (least significant bit again), where the shift direction gets switched again.

    So send_data() sends a value that is constantly moving to the left or the right - if the receiving end uses this value to drive 8 LED, then a single LED would constantly run up/down.

    This is demo code - demo code don't need reasons for the arbitrary choice of effects used.

Reply
  • Without looking at the specific example:

    p2val - Port 2 value, i.e. intended value for the port.

    It gets shifted left step by step until the bit has moved to the most significant bit. Then lshf gets toggled and p2val gets shifted right until it is back at the first (least significant bit again), where the shift direction gets switched again.

    So send_data() sends a value that is constantly moving to the left or the right - if the receiving end uses this value to drive 8 LED, then a single LED would constantly run up/down.

    This is demo code - demo code don't need reasons for the arbitrary choice of effects used.

Children