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.
hi Erik,
Thanks for your reply.
i like your solution and i will use it.
Just a thought instead of passing the mask value I will calculate the mask in the function itself.
something like
#define LED_PIN 2,3 //similar to P2_3
void setpin(int port, int pin) { switch( port ) { case 2 : P2 |= (0x01 << pin) ; break ; } }
void main() { setpin(LED_PIN) ; }
i havent compiled and tested this code yet but i think it will work.
thanks!
But fixing the port & pin like that at compile time rather defeats the object of having a function - doesn't it?
You might just as well have
#define LED_PORT P2 #define LED_PIN 3 #define SET_LED LED_PORT |= ( 1 << LED_PIN )
@Erik
yes! i can code it as a macro then...no need for a function...
thanks!!!