How to Declare GPIO vs Alternate function using 8051 Micro-C

Dec 07, 2005 3 Replies

How do you tell the micro-c compiler that you want to use the pin as a general purpose i/o versus use the alternative function (like pwm)..



For example, the PWM uses pins CEX0-CEX4, and according to the 8051 datasheet, the port pin must be set to to '1' inorder for the pwm to drive it. HOWEVER, If I set the bit this way, "setbit(1.3)", this is how you configure the port pin to be an input gpio (opposite of what I want).



Is there another way to initialize a port for alternative function and gpio+direction?



You don't, because the compiler couldn't care less what that the bits in that SFR are used for.

If such a configuration setting exists for whatever 8051 variant you're thinking about (and you forgot to tell), that's between you and the data sheet to figure out.

Hans-Bernhard Broeker (broeker@physik.rwth-aachen.de) Even if all the snow were burnt, ashes would remain.

The PWM function will be a timer-counter, err, function. You'll need to setup the specific timer-counter for the mode you need, and enable it.

The port pin being set to 1 requirement probably just means that there is then no conflict between two possible ways of driving the pin as an output (the GPIO and the timer-counter).

HTH,

Steve

formatting link

The 8051 STANDARD pins are quas-bidirectional. The is not make it and input or out put. If a pin is set to 1 (by bit or byte) other things like in puts or the PWM can pull it down.

the 8051 core has been added to by many manufactures. Additional feature pins may not work this way.

Goto

formatting link
look for the Links to the "bible" which are the original complete data books online.

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required