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

different port manipulation in one function

Hi :

Take a look at this function

  sbit a=P0^1;
  void manipulate_port()
  {
    a=1;
    Delay();
    a=0;
    Delay();
    a=1;
    Delay();
    a=0;
  }

In above code, the hardware(P0.1) is manipulated in the function manipulate_port(); Now I want to manipulate one of the pins of PORT0 according to different parameter. I can program eight different process with eight different pin manipulation and then select which process to be executed by a parameter. But I donot think it is a properly method. Should I only use one process to complete such goal.
Because the manipulation is fixed(no matter which pin is use) So shall I program the process in such way.

  sbit a0=P0^1;
  sbit a1=P0^2;
  ........
  sbit a7=P0^7;
  void manipulate_port(uchar x)
  {
    // according different x, the a will be point to   different pin,then execute the following
    a=1;
    Delay();
    a=0;
    Delay();
    a=1;
    Delay();
    a=0;
  }


Is this resonable(or is this idea will be supported by keil)? If so ,how can I do it.

Thanks for your replying.

Jason Liu

Parents
  • "But in actual situation, the pin be used is not only in one port..."

    Hiding requirement details until later is a no-no. We normally charge a penalty fee when you do that. We'll let it slide this time.

    Ports have a position in the address space, just like bits have a position within a byte.

Reply
  • "But in actual situation, the pin be used is not only in one port..."

    Hiding requirement details until later is a no-no. We normally charge a penalty fee when you do that. We'll let it slide this time.

    Ports have a position in the address space, just like bits have a position within a byte.

Children
No data