How to use Vcc as input on a microcontroller?

Is there any way to use Vcc as input on a general I/O pin on a microcontroller (AT89C2051 is what I am actually trying to use). If I set the bit on the pin and connect to ground it recognizes the bit as not set, but if the bit is not set, and I connect to Vcc I was thinking that is should recognize the bit as set, but this does not seem to be the case. Anyone got any suggestions? Thank you Colin

Reply to
ColinT
Loading thread data ...

Take a good look at the port/pin structure on the data sheet. How do you specift which pins are inputs and which are outputs? Some chips have a "port direction register" and others use an open drain structure and "wire nor" the output with the input. In the latter case you have to write logic 1's to any pins that you want to use as inputs. Otherwise the Input port "reads it's own output" and you get 0 all the time.

A classic error is to initialise all the registers to zero and then wonder why none of the input pins appear to work.

Say you have an 8 bit port and you want to configure it to be 7 Outputs (A0-A6) and 1 Input (A7). You have to set A7 High whenever you write a byte to the output A0-A6 bits. Otherwise when you read bit A7 you will get 0 all the time. To do this every time you want to write to the port you have to OR the data with 10000000 first.

Reply to
CWatters

"CWatters" wrote in news:DTJJe.164624$ snipped-for-privacy@phobos.telenet-ops.be:

The datasheet says "To be used as an input, the port bit latch must con- tain a 1, which turns off the output driver FET. Then, for Ports 1, 2, and

3, the pin is pulled high by the internal pullup but can be pulled low by an external source." So is there any way to externally pull it high?

Thank you Colin

Reply to
Colin

Colin> The datasheet says "To be used as an input, the port bit Colin> latch must con- tain a 1, which turns off the output driver Colin> FET. Then, for Ports 1, 2, and 3, the pin is pulled high by Colin> the internal pullup but can be pulled low by an external Colin> source." So is there any way to externally pull it high?

For ports 1, 2 and 3, you should read "1" if the port is in input mode, and the pin is unconnected. (The internal pullup will make it so.) You can (externally) connect the pin to Vcc, but it shouldn't matter -- with or without the external "pull up," the bit should read as "1".

For bits without internal pull-ups, a resistor to Vcc should make them read "1" as well.

d.

Reply to
dave madden

dave madden wrote in news: snipped-for-privacy@voxan.mersenne.com:

Thank you both, I think I understand now

Reply to
Colin

Yup that's exactly what I mean.

Once a pin is configured as an input it can be driven high three ways:

1) Leave it open circuit (and it will be pulled high by the on chip resistor). 2) Fit an external pull-up resistor (typically lower value than the on chip one to speed up the rise time) 3) Drive it high using a logic gate (but check what happens on Reset and/or before you program the port direction - You wouldn't want the micro driving the pin low while the external gate is trying to drive it high).
Reply to
CWatters

On Mon, 08 Aug 2005 10:36:24 -0700, dave madden blurted:

What, exactly, does "internal pull-up" mean.

Thanks Spamming this account signifies your unqualified consent to a free security audit

Reply to
spammersarevermin

An on chip resistor between the pin and VCC. It "pulls" the pin voltage up to VCC when nothing is pulling it down to 0V.

Many single chip micros have an open drain output with pull-up resistor.

Reply to
CWatters

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.