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

passing ports to a function

I have a program in which I have to manipulate 4 LEDs. I have a function that is designed to find out exactlywhat I need to do to each LED ie flash, fade, dim, etc but in order to save on code space I would like to send the program the LED by reference. For instance on of my functions looks like the following:

void switchon(&sbit LED, bit turnon)
{
  if(turnon)
  {
    LED=ON;
  }
  if(!turnon)
  {
    LED=OFF;
  }
}
where LED is the LED I am currently wanted to manipulate. I keep getting errors with this code. I have even tried just passing the LED by value and as a bit. Nothing seems to work. Is this valid?

Thanks
Justin Moses

Parents
  • "I have even tried just passing the LED by value and as a bit. Nothing seems to work. Is this valid?"

    No. To understand why, refer to the C51 User's Manual. You also need to understand the limitations of the 8051's memory/SFR architecture and instruction set.

    Once you understand these limitations, you can devise a function that does what you want using switch, shifts, and bit masking. This will be a much less "direct" solution than what you were probably hoping for.

Reply
  • "I have even tried just passing the LED by value and as a bit. Nothing seems to work. Is this valid?"

    No. To understand why, refer to the C51 User's Manual. You also need to understand the limitations of the 8051's memory/SFR architecture and instruction set.

    Once you understand these limitations, you can devise a function that does what you want using switch, shifts, and bit masking. This will be a much less "direct" solution than what you were probably hoping for.

Children