Chapter Three
Chapter Three
Input pin A logic one (1) is applied to a bit of the P register. The output FE transistor is turned off and
the appropriate pin remains connected to the power supply voltage over a pull-up resistor of high
resistance.
Logic state (voltage) of any pin can be changed or read at any moment. A logic zero (0) and logic
one (1) are not equal. A logic one (0) represents a short circuit to ground. Such a pin acts as an
output.
A logic one (1) is “loosely “connected to the power supply voltage over a resistor of high resistance.
Since this voltage can be easily “reduced” by an external signal, such a pin acts as an input.
Port 0
The P0 port is characterized by two functions. If external memory is used then the lower
address byte (addresses A0-A7) is applied on it. Otherwise, all bits of this port are
configured as inputs/outputs
The other function is expressed when it is configured as an output. Unlike other ports consisting of
pins with built-in pull-up resistor connected by its end to 5 V power supply, pins of this port have this
resistor left out. This apparently small difference has its consequences
If any pin of this port is configured as an input then it acts as if it “floats”. Such an input has unlimited
input resistance and in determined potential.
When the pin is configured as an output, it acts as an “open drain”. By applying logic 0 to a port bit,
the appropriate pin will be connected to ground (0V). By applying logic 1, the external output will
keep on “floating”. In order to apply logic 1 (5V) on this output pin, it is necessary to built in an
external pull-up resistor.
Port 1 P1 is a true I/O port, because it doesn't have any alternative functions as is the case with P0,
but can be cofigured as general I/O only. It has a pull-up resistor built-in and is completely
compatible with TTL circuits.
Port 2 P2 acts similarly to P0 when external memory is used. Pins of this port occupy addresses
intended for external memory chip. This time it is about the higher address byte with addresses A8-
A15. When no memory added, this port can used as a general input/output port showing features
similar to P1.
Port 3
All port pins can be used as general I/O, but they also have an alternative function. In order to use
these alternative functions, a logic one (1) must be applied to appropriate bit of the P3 register. In
terms of hardware, this port is similar to P0, with the difference that its pins have a pull-up resistor
built-in.
8051 IC
Hardware Structure of I/O Pin
Each pin of I/O ports Internal CPU bus:communicate with CPU D latch store the value
of this pin
D latch is controlled by “Write to latch” Write to latch=1:write data into the D latch 2
Tri-state buffer:
TB1: controlled by “Read pin” Read pin=1:really read the data present at the pin
TB2: controlled by “Read latch” Read latch=1:read value from internal latch A
transistor M1 gate
Gate=0: open
Gate=1: close
Tristate Buffer
Writing “0” to Output Pin P1.X
Reading “High” at Input Pin
Port – 0
Port0
Port – 2
Port 2
Port – 3
Port-3
The register used to access the stack is called SP (stack pointer) register.
The stack pointer in the 8051 is only 8 bits wide, which means that it can take value 00 to FFH.
When 8051 powered up, the SP register contains value 07.
Example:
MOV R6,#25H
MOV R1,#12H
MOV R4,#0F3H
PUSH 6
PUSH 1
PUSH 4
Difference between Microprocessor and Microcontroller
1. Key difference in both of them is presence of external peripheral, where microcontrollers have
RAM, ROM, EEPROM embedded in it while have to use external circuits in case of microprocessors.
2. As all the peripheral of microcontroller are on single chip it is compact while microprocessor or is
bulky.
3. Microcontrollers are mad by using complementary metal oxide semiconductor technology so they
are far cheaper than microprocessors. In addition, the applications made with microcontrollers are
cheaper because they need lesser external components, while the overall cost of systems made with
microprocessors are high because of the high number of external components required for such
systems.
4. Processing speed of microcontrollers is about 8 MHz to 50 MHz, but in contrary processing speed
of general microprocessors is above 1 GHz so it works much faster than microcontrollers do.
5. Generally microcontrollers have power saving system, like idle mode or power saving mode so
overall it uses less power and since external components are low overall consumption of power is
less. While in microprocessors generally, there is no power saving system and many external
components are use with it, so its power consumption is high in comparison with microcontrollers.
6. Microcontrollers are compact so it makes them favorable and efficient system for small products
and applications while microprocessors are bulky so they are preferred for larger applications.
7. Tasks performed by microcontrollers are limited and generally less complex. While task performed
by microprocessors are software development, Game development, website, documents making etc.
which are generally more complex so require more memory and speed so that is why external ROM,
RAM are used with it.
8. Microcontrollers are base on Harvard architecture where program memory and data memory are
separate while microprocessors are base on von Neumann model where program and data are
stored in same memory module.
Interfacing the input/output
The interfacing of a 20-character 2-line LCD module with the 8051 shown. The data lines are
connect to the port 1 of 8051 and control lines RS, R/W and E driven by 3.2, 3.3 and 3.4 lines of port
3, respectively .The voltage at V EE pin adjusted by a potentiometer to adjust the contrast of LCD.
Main Routine
DAC and ADC for interfacing purpose
Most physical variables are analog in nature and can take on any value within a
continuous range of values. Examples include temperature, pressure, light intensity,
audio signals, position, rotational speed, and flow rate. Digital systems perform all of
their internal operations using digital circuitry and digital operations. Any information
that has to be inputted to a digital system must first be put into digital form. Similarly,
the outputs from a digital system are always in digital form
Example:-Transducer
The physical variable is normally a nonelectrical quantity. A transducer is a device
that converts the physical variable to an electrical variable. Some common
transducers include thermistors, photocells, photodiodes, flow meters, pressure
transducers, and tachometers. The electrical output of the transducer is an analog
current or voltage that is proportional to the physical variable it is monitoring. For
example, the physical variable could be the temperature of water. Let’s say that the
water temperature varies from 80 to 1500 F and that a thermistor and its associated
circuitry convert this water temperature to a voltage ranging from 800 to 1500mV.
Note that the transducer’s output is directly proportional to temperature; such that
each 10 F produces a 10mV output. Analog-to digital converter (ADC) and digital-to-
converter (DAC) used to interface a computer to the analog world so that the
computer can monitor and control a physical variable.
Analog-to-Digital Converter (ADC)
The transducer’s electrical analog output serves as the analog input to the ADC. The
ADC converts this analog input to a digital output. This digital output consists of a
number of bits that represent the value of the analog input. For example, the ADC
might convert the transducer’s 800to 1500-mV analog values to binary values ranging
from 01010000 (80) to 10010110 (150). Note that the binary output from the ADC is
proportional to the analog input voltages so that each unit of the digital output
represents 10mV.
The digital representation of the analog vales is transmitted from the ADC to the
digital computer, which stores the digital value and processes it according to a
program of instructions that it is executing.
Digital-to-Analog Converter (DAC)
This digital output from the computer is connected to a DAC, which converts it to a
proportional analog voltage or current. For example, the computer might produce a
digital output ranging from 0000000 to 11111111, which the DAC converts to a
voltage ranging from 0 to 10V.
An analog-to-digital converter takes an analog input voltage and after a certain
amount of time produces a digital output code which represents the analog input. The
A/D conversion process is generally more complex and time-consuming than the D/A
process. The techniques that are used provide and insight into what factors
determine an ADCs performance
Several important types of ADC utilize a DAC as part of their circuitry.
The basic operation of ADCs of this type consists of the following steps:
1.The START COMMAND pulse initiates the operation.
2. At a rate determined by the clock, the control unit continually modifies the binary
number that is stored in the register.
3. The binary number in the register is convert to an analog voltage, VAX, by the
DAC.