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 a port/pin to a function

hi,

i have a question regarding passing a port/pin to a function.

i have written a piece of code as below

#define LED_PIN P1_0 // bit LED_PIN = P1_0 also does not work

void blink(bit pin, int delayTime, int blinkCount)
{ while( --blinkCount ) { pin = !pin ; delay(delayTime) ; // function to generate delay...this works fine }
}

void main()
{ blink( LED_PIN, 1000, 10 ) ;
}

this also does not work if i code the blink function as a macro.

is there any way i can pass the address/pin name to the function? i am using keil compiler for 89C51 MCU.

Parents Reply Children
  • you slipping into textspeak there, Erik
    yes, when showing the principle with "textspeak" rather than "usable code" insignificant misses are a non-issue. Once posting code I forgot a ';' and the rest of the thread was about that. Anyhow IMHO showing the principle is more important than reply format. Now we can, of course, expect a post discussing that you forgot () around port_num
    at the switch :)

  • And Andy didn't specify the data types for the parameters...

    Anyway - I haven't really seen an issue with posting "real" code. I don't think any thread where I have posted code have ended up debating any spelling errors - and spelling errors are likely since I normally code suggestions on-the-fly in the text box in a "best-effort" way.

    The only time I think it's important to be exact, is when people posts code and asks why the compiler protests, or why the program does the wrong thing. Then it's important that the code we read is 100% the same as the code the compiler got to work on, since a minor typo might be the whole reason for the incorrect outcome. And not all spelling errors gets caught by the compiler - lots of C expressions are valid even if meaningless.

  • The only time I think it's important to be exact ...

    I'm sure we're all immensely glad that you have given your diktat on the matter.