??? 07/22/05 10:20 Read: times |
#97800 - 0 and 1 Responding to: ???'s previous message |
You should start by stopping to think of 1 as on and 0 as off. This is only beginners instinct, and in the practice of digital electronics it is usually the other way around (not restricted to the 8052 universe). Switch to think of 1 as inactive, and 0 as active. The important thing is that the 8052's I/O pin circuitry is designed singularly for this philosohy, and the 1 on, 0 off notion will get you in deep problems. So an input switch to 0V connected to a port pin is GOOD, a switch from a port pin to Vcc is BAD. Setting a pin to 1 in software is like deactivating that port pin (THAT'S WHY PORTS ARE INITIALIZED TO FF AFTER RESET!, your setting them to 00 is like switching them all ON), clearing it is like activating it. External electronics should be built so that they take HIGH as off, and LOW as on. So in the case of a LED, connect it from the port pin to Vcc. If you stick to this philosophy, there is no contradiction anywhere.
Switching to simplistic explanation here: A (standard) 8052 port pin is constructed internally as a pullup resistor to Vcc and a transistor to ground . You can open or close the transistor by software (the output function). So if you don't activate the transistor (write a 1 to the output), the port pin is weakly pulled to Vcc through the resistor. You will measure +5V on the pin on the outside, but because it is through a resistor, you can not connect any load to it, if you do the voltage will collapse. If you activate the transistor, the pin is strongly short circuited to ground. On the outside you will measure 0V, and because it is through the low ohmic transistor, you can actually let a lot of current flow from Vcc through the port pin to ground. Also, internally you can read the pin to see the logic level on it (the input function). If you have deactivated the transistor, you will see a 1, unless some external circuit, for instance a button, is pulling it to 0V, in which case you will read a 0. If you activate the output transistor (write a 0 to it) however, you will always read a 0. Now do what Erik suggested, and read the &^$%@# 8052 Bible! (see links on this site). If you do a site search you will see that variations of this story are told to beginners over and over and over again, because it is one of the first pits beginners fall into. You can not work with microcontrollers unless you are at least part electronics engineer. If you are not and want to work with controllers anyway, become one fast. Being a software guy only does not get you there alone. |