EmbeddedRelated.com
Forums

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

Started by Unknown December 7, 2005
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?

benn686@hotmail.com wrote:
> 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)..
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.
<benn686@hotmail.com> wrote in message 
news:1133983898.860586.150380@g14g2000cwa.googlegroups.com...
> 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?
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 http://www.fivetrees.com

benn686@hotmail.com wrote:

> 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?
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 www.8052.com look for the Links to the "bible" which are the original complete data books online.